最終更新日 2005/10/18  戻る  485065 人 REMOTE = 38.103.63.59 REFERER =

★SSLによるセキュアなウェブサーバー

SSLはポート443を使いhttps://yaguma.comなどとhttpsでブラウザからアクセスします.
ルータなどを使っている場合はポート443を開けるのを忘れないように.
apache2ではSSLの設定はほとんどssl.confで行います.設定が終わったら,証明書(CA)を作って
# service apache2 start
SSLを使う利点として,例えばメールを外から使う場合,スクリルウェブメーラーなどを使ったとしても他人には情報が漏れません.また,勤め先の会社が25番,80番,110番を止めていたとしてもメールが使えます.他には,httpsを使っていれば会社の履歴には残りません.(かなり怪しげ,自信なし)

1.httpd.confの変更
<IfDefine SSL>
Listen 443
</IfDefine>
Listen 80

2.ssl.confの変更
#Listen  443
#<VirtualHost _default_:443>
# 私の環境では_default_や*では不具合がでます.ちゃんとサーバの動いているプライベートIPを指定.
<VirtualHost 192.168.1.101:443>
# General setup for the virtual host
DocumentRoot "/home/user/html"
ServerName yaguma.com:443
ServerAdmin tanaka@yaguma.com
#証明書の指定
#SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server.crt
SSLCertificateFile /usr/local/certs/server.crt
#秘密鍵の指定
#SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server.key
SSLCertificateKeyFile /usr/local/certs/server.key

3.証明書の作成 http://acorn.zive.net/~oyaji/www/certs.htmよりの抜粋です.
http://www.modssl.org/
からCurrent Version: mod_ssl 2.8.15 for Apache 1.3.28をダウンロード.
# cd /usr/local/src
# tar zxfv mod_ssl-2.8.15-1.3.27.tar.gz

a.まずは,certification用ディレクトリを作り,鍵作成時に使用する乱数データ(rand.dat)を作成.
# cd /usr/local
# mkdir /usr/local/certs
# cd /usr/local/certs
# openssl dgst -md5 ../apache2/conf/* > rand.dat

b.乱数データ(rand.dat)を使用してCA用の鍵を作成.
# openssl genrsa -des3 -out ca.key -rand rand.dat 1024
 718 semi-random bytes loaded
 Generating RSA private key, 1024 bit long modulus
 ・・・
 ・・・
 e is 65537 (0x10001)
 Enter PEM pass phrase:xxxxx            ← CA用パスフレーズ入力
 Verifying password - Enter PEM pass phrase:xxxxx ← CA用パスフレーズ再入力

c.CA用証明書(ca.crt)を作成.
# openssl req -new -x509 -days 365 -key ca.key -out ca.crt
 Using configuration from /usr/share/ssl/openssl.cnf
 Enter PEM pass phrase:xxxxx            ← CA用パスフレーズ入力
 You are about to be asked to enter information that will be incorporated
 into your certificate request.
 What you are about to enter is what is called a Distinguished Name or a DN.
 There are quite a few fields but you can leave some blank
 For some fields there will be a default value,
 If you enter '.', the field will be left blank.
 -----
 Country Name (2 letter code) [GB]:JP (国コード)
 State or Province Name (full name) [Berkshire]:Aichi (都道府県名)
 Locality Name (eg, city) [Newbury]:Nagoya (市町村名)
 Organization Name (eg, company) [My Company Ltd]:yaguma.com (組織名)
 Organizational Unit Name (eg, section) []:Admin (組織内ユニット名)
 Common Name (eg, your name or your server's hostname) []:yaguma.com (サーバ名)
 Email Address []:tanaka@yaguma.com (管理者メールアドレス)

d.サーバ用秘密鍵(server.key)を作成.
RSA鍵を生成し暗号化アルゴリズムはDES3,鍵長1024ビットで指定.
# openssl genrsa -des3 -out server.key -rand rand.dat 1024
 718 semi-random bytes loaded
 Generating RSA private key, 1024 bit long modulus
 ・・・
 ・・・
 e is 65537 (0x10001)
 Enter PEM pass phrase:yyyyy             ← パスフレーズ入力
 Verifying password - Enter PEM pass phrase:yyyyy ← パスフレーズ再入力

e.サーバ用公開鍵(server.csr)を作成.
CAに送るデジタル証明書のリクエストファイル.
# openssl req -new -key server.key -out server.csr
 Using configuration from /usr/share/ssl/openssl.cnf
 Enter PEM pass phrase:yyyyy           ← パスフレーズ入力
 You are about to be asked to enter information that will be incorporated
 into your certificate request.
 What you are about to enter is what is called a Distinguished Name or a DN.
 There are quite a few fields but you can leave some blank
 For some fields there will be a default value,
 If you enter '.', the field will be left blank.
 Country Name (2 letter code) [GB]:JP (国コード)
 State or Province Name (full name) [Berkshire]:Aichi (都道府県名)
 Locality Name (eg, city) [Newbury]:Nagoya (市町村名)
 Organization Name (eg, company) [My Company Ltd]:yaguma.com (組織名)
 Organizational Unit Name (eg, section) []:Admin (組織内ユニット名)
 Common Name (eg, your name or your server's hostname) []:yaguma.com (ホスト名)
 Email Address []:tanaka@yaguma.com (管理者メールアドレス)
 Please enter the following 'extra' attributes
 to be sent with your certificate request
 A challenge password []:           ← Enterのみ入力
 An optional company name []:         ← Enterのみ入力

f.サーバ用秘密鍵(server.key)からパスフレーズの削除.
# cp server.key server.key.bak
# openssl rsa -in server.key.bak -out server.key
 read RSA private key
 Enter PEM pass phrase:yyyyy          ← パスフレーズ入力
 writing RSA private key

g.サーバ用証明書(server.crt)を作成.
mod_ssl付属のsign.shスクリプトでサーバ用デジタル証明書を作成
# /usr/local/src/mod_ssl-2.8.11-1.3.27/pkg.contrib/sign.sh server.csr
 CA signing: server.csr -> server.crt:
 Using configuration from ca.config
 Enter PEM pass phrase:xxxxx          ← CA用パスフレーズ入力
 Check that the request matches the signature
 Signature ok
 The Subjects Distinguished Name is as follows
 countryName :PRINTABLE:'JP'
 stateOrProvinceName :PRINTABLE:'Aichhi'
 localityName :PRINTABLE:'Nagoya'
 organizationName :PRINTABLE:'yaguma.com'
 organizationalUnitName:PRINTABLE:'Admin'
 commonName :PRINTABLE:'yaguma.com'
 emailAddress :IA5STRING:'tanaka@yaguma.com'
 Certificate is to be certified until Oct 10 13:09:20 2003 GMT (365 days)
 Sign the certificate? [y/n]:y
 1 out of 1 certificate requests certified, commit? [y/n]y
 Write out database with 1 new entries
 Data Base Updated
 CA verifying: server.crt <-> CA cert
 server.crt: OK

h.CA証明書をブラウザにインポートするためのca.derファイルを作成.
# openssl x509 -inform pem -in ca.crt -outform der -out ca.der
インポートの方法はhttp://acorn.zive.net/~oyaji/www/ssl_client.htmにあります.

i.各ファイルのパーミッションを変更.
# chmod -c -R 400 server.* ca.* rand.dat mail.pem

4.apache2を自動起動するには
# cd /usr/local/apache2/bin
# cp apachectl /etc/rc.d/init.d/apache2
# cd /etc/rc.d/init.d
# chmod 700 apache2
apache2の先頭の
#!/bin/sh以下に

# chkconfig: - 86 14
# Source function library.
. /etc/rc.d/init.d/functions
を付け加え,
case $ARGV in
start|stop|restart|graceful)
$HTTPD -k $ARGV
ERROR=$?
;;
startssl|sslstart|start-SSL)
$HTTPD -k start -DSSL
ERROR=$?
;;
とあるのを
case $ARGV in
stop|restart|graceful)
$HTTPD -k $ARGV
ERROR=$?
;;
start|startssl|sslstart|start-SSL)
$HTTPD -k start -DSSL
ERROR=$?
;;

とします.これでntsysvで自動起動の設定が可能になります.

このページは
http://www.kkoba.com/ssl/
http://acorn.zive.net/~oyaji/www/apache_linux_ssl.htm
を元にして作りました.ほとんど丸写しに近くて
かつさん,おやじさんごめんなさい.m(_ _)m


Copyright 2002-2003 Kai All Rights Reserved & This site is Link Free 戻る