SSL を設置するメモ

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

# cd /usr/local/etc/apache22
# /usr/bin/openssl genrsa -rand /var/log/messages -des3 \
-out /usr/local/etc/apache22/server.key 1024 54002 \
semi-random bytes loaded

Generating RSA private key, 1024 bit long modulus
....++++++
.............++++++
e is 65537 (0x10001)
Enter pass phrase for
/usr/local/etc/apache22/ssl.key/www.smb.net.key:*********
Verifying - Enter pass phrase for
/usr/local/etc/apache22/ssl.key/www.smb.net.key:*********

# chmod 600 server.*

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]:CAcert Inc.
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:ここは、ドメインやマシン名がわかる名前の方がよい
Email Address []:

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

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/apache2/にserver.crt として、保存します。 (eeでもviでもいいので、これを新規で作成します)

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

# chmod 600 server.*

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

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

# cd /usr/local/etc/apache22/
# 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 httpd-ssl.conf httpd-ssl.conf-dist

/usr/local/etc/apache22/extra/httpd-ssl.conf に該当ドメインのファイルは

DocumentRoot "(ドキュメントルート)"
ServerName サーバ名:443
ServerAdmin webmaster@smb.net
ErrorLog /var/log/httpsd-error.log
TransferLog /var/log/httpsd-access.log

SSLCertificateFile /usr/local/etc/apache22/ssl.crt/www.smb.net.server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/ssl.key/www.smb.net.key

や、

<VirtualHost IPアドレス:443>
       ServerAdmin     webmaster@smb.net
       DocumentRoot    /home/tfc/public_html/
       ServerName      secure.smb.net:443
       ServerAlias     www.smb.net:443
       ScriptAlias     /cgi-bin/       /home/tfc/public_html/
       UserDir         disabled
       ErrorLog        /home/tfc/log/https-example-jp-error_log
       CustomLog       /home/tfc/log/https-example-jp-access_log combined
       DirectoryIndex  index.html

       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
<Directory "/home/tfc">
       AllowOverride FileInfo AuthConfig Limit
       Options Includes SymLinksIfOwnerMatch execCGI
       Order           allow,deny
       Allow from      all
</Directory>
<Directory "/home/tfc">
       SSLOptions +StdEnvVars
</Directory>

<FilesMatch "\.(cgi|shtml|phtml|php3?)$">
       SSLOptions +StdEnvVars
</FilesMatch>

       SetEnvIf User-Agent ".*MSIE.*" \
       nokeepalive ssl-unclean-shutdown \
       downgrade-1.0 force-response-1.0

       CustomLog       /home/tfc/log/https-example-jp-ssl_request.log \
               "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

ように指定します。

 /etc/rc.confには

apache22_enable="YES"
apache22ssl_enable="YES"

を入れておきましょう。

ページを参照して、確認すると128bitのSSLで接続されていることが確認できたと思います。

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: 2902, today: 1, yesterday: 1

2015-05-22 (金) 08:16:24


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS