2004年11月21日
Apacheを使ったDigest認証の利用メモ
HTTPのDigest認証を使うと、認証時にネットワークを流れるパスワードが暗号化される。IEやFirefoxなどのブラウザもDigest認証に対応しているので手軽に利用できる。ApacheでDigest認証を使う方法をまとめる。
ただし、IE6でfile.cgi?foo=barなどのURI にアクセスすると 400 Bad Request が発生する問題が知られている。よって、現状は管理用などの限られた用途に向いている。
■ apacheの設定
Digest認証用モジュールを有効にするため、/usr/local/etc/apache2/httpd.confを編集して、次の1行を有効にする。編集後、apacheの再起動を行う。
LoadModule auth_digest_module libexec/apache2/mod_auth_digest.so
■ .htaccessファイルの準備
/usr/local/www/data/hotsanic に.htaccessファイルを作成し、Digest認証を設定する例を取り上げる。
まず、.htaccessファイルによって認証の設定できるようになっているか、サーバの設定ファイル/usr/local/etc/apache2/httpd.confを確認する。
# vi /usr/local/etc/apache2/httpd.conf
<Directory "/usr/local/www/data">
のなかの
AllowOverride None
が
AllowOverride AuthConfig
に変更されているか確認する。
次に、.htaccessファイルを準備し、Digest認証を有効にする。
AuthNameの値は、htdigestのrealm(レルム)として使われる。realmに':'が含まれているとうまく動作しない。
# cd /usr/local/www/data/hotsanic
# vi .htaccess
AuthType Digest
AuthName "Administrator Area"
AuthDigestDomain /hotsanic/
AuthDigestFile /usr/local/www/data/hotsanic/.htdigest
Require valid-user
そして、Digest認証用のパスワードファイルを準備する。htdigestコマンドの引数には、パスワードファイル、realmとユーザIDを与える。
# cd /usr/local/www/data/hotsanic
# htdigest -c .htdigest 'Administrator Area' commoore
Adding user commoore in realm Administrator Area
New password:
Re-type new password:
次のようなパスワードファイルが生成される。
# cat .htdigest
commoore:Administrator Area:e8e888e88f22b1abcd41d775d0b2a333