SSL をvirtualhostに適用するメモ

http://www.linux.ph/apache/apacheSSL.html

IPベースのバーチャルホストは設定済みのホスト上でSSLを適用する

秘密鍵生成[/usr/local/etc/apache22/ssl.key/www.smb.net.key]

# mkdir /usr/local/etc/apache22/thouand-winds_server_keys
# cd /usr/local/etc/apache22/thouand-winds_server_keys
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
#openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
chmod 0400 server.key server.crt

CSR(証明書申請データ)生成[/usr/local/etc/apache22/server.csr]

# /usr/bin/openssl req -new -key \
/usr/local/etc/apache22/server.key \
-out /usr/local/etc/apache22/server.csr

Enter pass phrase for \
/usr/local/etc/apache22/ssl.key/www.smb.net.key:*********
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) [AU]:JP
State or Province Name (full name) [Some-State]:Ehime
Locality Name (eg, city) []:Matsuyama
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:www.thousand-winds.net
Email Address []:webmaster@thousand-winds.net

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

k222# chmod 0400 server.key server.crt

CSRは、認証局(CA)に渡す ものなので、これを cat で表示させて、その内容を範囲コピーしておきます。

CAcert.orgのサーバー証明書に登録

http://www.cacert.org/index.php?id=0&lang=ja_JP

まずはhttp://www.cacert.org/へアクセス。右のメニューのTransrations で日本語を :)

ドメインの指定は、上記のCSRを作成する時に指定した

Common Name (eg, YOUR name)

の部分に相当しますので、自動で登録されることになります。

サーバ証明書の新規作成をクリックします。

下にCSRをペーストしてください。

と書かれている部分に、CSRの内容をそのままコピーします。

私は、CAcertの保証制度には協力していないので、詳細な情報は出ませんが、そもそもそんな情報を欲するようなユーザが利用する用途では用いていないので無視して大丈夫。

送信を選択すると、SSLにするFQDNが表示され、その先に進めると、キーができあがってきました

左のような部分をコピーし、 /usr/local/etc/apache22/thouand-winds_server_keys/にserver.crt として、保存します。 (eeでもviでもいいので、これを新規で作成します)

それが完了したら、同ディレクトリにあるものを

# chmod 600 server.*

してキーの生成は完了です。

これだけですと、Apacheの開始時に毎回パスフレーズを求められるようになってしまいますので、これをあらかじめ解消して使うことにしています。

# cd /usr/local/etc/apache22/thouand-winds_server_keys
# mv  server.key server.key.orig
# openssl rsa -in server.key.orig -out server.key
Enter pass phrase for www.smb.net.key.orig:*********
writing RSA key
# chmod 600 server.*

これで必要な鍵はそろいました。

[ ssl.confの設定 ]

設定ファイルの待避

# cd /usr/local/etc/apache22/extra
# cp httpd-ssl.conf httpd-ssl.conf-dist

/usr/local/etc/apache22/extra/httpd-ssl.conf の最低限?の設定

Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache        "shmcb:/var/run/ssl_scache(512000)"
SSLSessionCacheTimeout  300
SSLMutex  "file:/var/run/ssl_mutex"

## SSL Virtual Host Context
<VirtualHost _default_:443>
#   General setup for the virtual host
DocumentRoot "/usr/local/www/apache22/data"
ServerName www.smb.net:443
ServerAdmin webmaster@smb.net
ErrorLog "/var/log/httpd-error.log"
TransferLog "/var/log/httpd-access.log" 

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/etc/apache22/ssl.crt/www.smb.net.server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/ssl.key/www.smb.net.key

SSLCertificateKeyFile "/usr/local/etc/apache22/ssl.key/www.smb.net.key"

<FilesMatch "\.(cgi|shtml|phtml|php)$">
   SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/local/www/apache22/cgi-bin">
   SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
CustomLog "/var/log/httpd-ssl_request.log" \
         "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>                                  

のように指定します。

/usr/local/etc/apache22/Includes/www.thousand-winds.jp.conf

と言う設定ファイルを以下のように記述

<VirtualHost  219.117.246.222:443>
DocumentRoot "/usr/home/tfc/public_html"
ServerName www.thousand-winds.net:443
ServerAdmin webmaster@thousand-winds.net
ErrorLog /var/log/httpsd-error_thousand-winds.log
TransferLog /var/log/httpsd-access_thousand-winds.log

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/etc/apache22/thouand-winds_server_keys/server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/thouand-winds_server_keys/server.key

<Directory "/usr/home/tfc/public_html">
  SSLRequireSSL
 
      Options FollowSymLinks
      Options +ExecCGI
      AllowOverride None
      Order deny,allow
      Allow from all   
 
 
 
</Directory>
<FilesMatch "\.(cgi|shtml|phtml|php)$">
   SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/local/www/apache22/cgi-bin">
   SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0

CustomLog /var/log/httpd-ssl_request.log \
         "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>                                  

Tips

CSRのCNとアクセス先のFQDNを合わせ

ておかないと、「証明書のエラー アドレスが一致しません」と言われます

ちなみに証明書と鍵の確認方法、証明書の内容を見る方法は

openssl x509 -noout -text -in filename.crt

秘密鍵の内容を見る方法は

openssl rsa -noout -text -in filename.key

http://freebsd.fkimura.com/cacert-a0.html


Counter: 1303, today: 1, yesterday: 0

2010-02-12 (金) 07:08:01


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2010-02-12 (金) 07:08:01