Red Hat Linux 7.xやTurbolinux7では,システムインストール時にApacheを候補に含めると,SSL(Secure Socket Layer)暗号化環境が整う。
しかし,下画像のように証明書を表示させてみると,「発行先」「発行元」共に「localhost.localdomain」と記載されているはずだ。正規にベリサインから証明書が発行されていなくても,この記載内容だけは変更することが可能だ。
発行先,発行者共に「localhost.localdomain」と表示されている
ここで紹介するSSL環境は,mod_sslと呼ばれるモジュールを追加することでセキュアなhttpサーバを構築する方法である。ほかにもApache-SSLと呼ばれる,モジュールではなく単一バイナリでパフォーマンスを重視するプログラムもある。mod_sslによるモジュール組み込みは比較的導入が手軽なため,ここでもこの方法について解説しよう。
まず最初に,現在のApacheがセキュアサーバ(https:443ポート)として機能しているかを確認してみよう。「https://〜」指定でアクセスすればよい。「xxxxxxx」には,192.168.0.2やWindows上でhostsファイルを設定しているのであれば,サーバ名でアクセスすればよい(参考Windows Tips「ルータなどへIPアドレスの代わりに名前でアクセスする」)。
https://xxxxxxx/
mod_sslの環境が整っているのであれば,次のような「セキュリティの警告」ウィンドウが表示されるだろう。
基本的に,ベリサインより正式な証明書が発行されていないとこのようなウィンドウが現れる
このウィンドが表示されれば,Apacheの設定ファイル(httpd.conf)内でSSL設定がある程度最適化されていると思ってよい。前述した証明書内容を書き換えるためには,新たに鍵を生成しよう。まずは既存の鍵を削除しなければならない。手順は次の通りだ。
# cd /etc/httpd/conf/ # rm ssl.key/server.key # rm ssl.crt/server.crt |
次のように指定して鍵を生成することができる。黄色文字が入力を必要とする個所だ。
# make genkey umask 77 ; \ /usr/bin/openssl genrsa -des3 1024 > /etc/httpd/conf/ssl.key/server.key Generating RSA private key, 1024 bit long modulus ......++++++ .................................++++++ e is 65537 (0x10001) Enter PEM pass phrase:xxxxxxxxx Verifying password - Enter PEM pass phrase:xxxxxxxxx |
次に,自己署名証明書を生成する。
# make testcert umask 77 ; \ /usr/bin/openssl req -new -key /etc/httpd/conf/ssl.key/server.key -x509 -days 365 -out /etc/httpd/conf/ssl.crt/server.crt Using configuration from /usr/share/ssl/openssl.cnf Enter PEM pass phrase:xxxxxxxxx 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]:[Enter] State or Province Name (full name) [Some-State]:[Enter] Locality Name (eg, city) []:[Enter] Organization Name (eg, company) [Internet Widgits Pty Ltd]:[Enter] Organizational Unit Name (eg, section) []:[Enter] Common Name (eg, your name or your server's hostname) []:xxxxxxx.jp Email Address []:root@xxxxxxx.jp |
ここまでで,新たな鍵を生成したセキュアサーバ環境が整った。httpdを起動させてみよう。
# /etc/rc.d/init.d/httpd start httpdを起動中: Apache/1.3.20 mod_ssl/2.8.5 (Pass Phrase Dialog) Some of your private key files are encrypted for security reasons. In order to read them you have to provide us with the pass phrases. Server galaxies.jp:443 (RSA) Enter pass phrase:xxxxxxxxx Ok: Pass Phrase Dialog successful. [OK] |
上記のように,鍵を生成した際のパスフレーズを要求されたはずだ。しかし,システムインストール直後にはパスフレーズを問い合わされなかったはずだ。同じようにするためには,再度次のように指定してserver.keyファイルを作成し直せばよい。
# /usr/bin/openssl genrsa 1024 > /etc/httpd/conf/ssl.key/ server.key Generating RSA private key, 1024 bit long modulus ..............................................................................++++++ .........++++++ e is 65537 (0x10001) # chmod go-rwx /etc/httpd/conf/ssl.key/server.key # make testcert umask 77 ; \ /usr/bin/openssl req -new -key /etc/httpd/conf/ssl.key/server.key -x509 -days 365 -out /etc/httpd/conf/ssl.crt/server.crt Using configuration from /usr/share/ssl/openssl.cnf 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]:[Enter] State or Province Name (full name) [Some-State]:[Enter] Locality Name (eg, city) []:[Enter] Organization Name (eg, company) [Internet Widgits Pty Ltd]:[Enter] Organizational Unit Name (eg, section) []:[Enter] Common Name (eg, your name or your server's hostname) []:xxxxxxx.jp Email Address []:root@xxxxxxx.jp |
以上の操作で,次のようにパスフレーズが省略できるようになったはずだ。
# /etc/rc.d/init.d/httpd start httpdを起動中: [OK] |
このようにlocalhost.localdomainの記述が変更されていることが分かる
ブラウザ右下には,SSL暗号化のやり取りが確立されている鍵アイコンが表示されているだろう
Copyright © ITmedia, Inc. All Rights Reserved.