5.7. Digest Authentication
A halfway house between complete encryption and none at all is digest authentication. The idea is that a one-way hash, or digest, is calculated from a password and various other bits of information. Rather than sending the password, as is done in basic authentication, the digest is sent. At the other end, the same function is calculated: if the numbers are not identical, something is wrong -- and in this case, since all other factors should be the same, the "something" must be the password.
Digest authentication is applied in Apache to improve the security of passwords. MD5 is a cryptographic hash function written by Ronald Rivest and distributed free by RSA Data Security; with its help, the client and server use the hash of the password and other stuff. The point of this is that although many passwords lead to the same hash value, there is a very small chance that a wrong password will give the right hash value, if the hash function is intelligently chosen; it is also very difficult to construct a password leading to the same hash value (which is why these are sometimes referred to as one-way hashes ). The advantage of using the hash value is that the password itself is not sent to the server, so it isn't visible to the Bad Guys. Just to make things more tiresome for them, MD5 adds a few other things into the mix: the URI, the method, and a nonce. A nonce is simply a number chosen by the server and told to the client, usually different each time. It ensures that the digest is different each time and protects against replay attacks. The digest function looks like this:
This plugs a nasty hole in the Internet's security. Almost unbelievably, the authentication procedures discussed up to now send the user's password in clear text across the Web. A Bad Guy who intercepts the Internet traffic then knows the user's password. This is a Bad Thing. So, digest authentication works this way:
A different nonce is sent the next time, so that the Bad Guy can't use the captured digest to gain access.
MD5 digest authentication is implemented in Apache for two reasons. First, it provides one of the two fully compliant reference HTTP/1.1 implementations required for the standard to advance down the standards track; second, it provides a test bed for browser implementations. It should only be used for experimental purposes, particularly since it makes no effort to check that the returned nonce is the same as the one it chose in the first place. This makes it susceptible to a replay attack.
User webuser Group webgroup ServerName www.butterthlies.com ServerAdmin email@example.com DocumentRoot /usr/www/site.digest/htdocs/customers ErrorLog /usr/www/site.digest/logs/customers/error_log TransferLog /usr/www/site.digest/logs/customers/access_log ScriptAlias /cgi-bin /usr/www/cgi-bin <VirtualHost sales.butterthlies.com> ServerAdmin firstname.lastname@example.org DocumentRoot /usr/www/site.digest/htdocs/salesmen ServerName sales.butterthlies.com ErrorLog /usr/www/site.digest/logs/salesmen/error_log TransferLog /usr/www/site.digest/logs/salesmen/access_log ScriptAlias /cgi-bin /usr/www/cgi-bin <Directory /usr/www/site.digest/htdocs/salesmen> AuthType Digest AuthName darkness AuthDigestFile /usr/www/ok_digest/sales require valid-user #require group cleaners </Directory> </VirtualHost>
Go to the Configuration file (see Chapter 1, "Getting Started" ). If the line:
Module digest_module mod_digest.o
is commented out, uncomment it and remake Apache as described previously. Go to the Apache support directory and type:
% make htdigest % cp htdigest /usr/local/bin
% htdigest [-c]passwordfile realm user
Go to /usr/www (or some other appropriate spot) and make the ok_digest directory and contents:
% mkdir ok_digest % cd ok_digest % htdigest -c sales darkness bill Adding password for user bill in realm darkness. New password: password Re-type new password: password % htdigest sales darkness ben ... % htdigest sales darkness sonia ... % htdigest sales darkness daphne ...
appeared in the Config file, the error log contained the following entry:
client used wrong authentication scheme
Copyright © 2001 O'Reilly & Associates. All rights reserved.