Yesterday:074 | Today:020 | Total:00375
[ 自宅サーバーWebRing |ID=83 前後5表示乱移動サイト一覧 ]

E-HIRO.NET Web Site..

- SSL化のための鍵作成 -

ここでは、Webサーバー( HTTPS )のための証明書Mailサーバー( smtps pop3s imaps )のための証明書を作成していきます。

この辺の内容に関して、まだまだ未熟者ですので詳しくは触れませんが、作成手順を示します。

証明書作成の際に、mod_ssl付属のsign.shスクリプトを使用するので、
最新のmod_sslをこちらからダウンロードしておきます。
私の場合は、mod_ssl-2.8.19-1.3.31.tar.gz でした。

作業ディレクトリに移動します。
# cd /usr/local/src
# tar zxfv mod_ssl-2.8.19-1.3.31.tar.gz  ← 解凍

lsコマンドsign.shがあることを確認してください。
# ls mod_ssl-2.8.19-1.3.31/pkg.contrib

鍵を置いておくディレクトリを作成します(ここで作業します)
# mkdir /usr/local/certs
# cd /usr/local/certs

鍵作成時に使用する乱数データ(rand.dat)を作成します。
# openssl dgst -md5 ../apache2/conf/* > rand.dat


CA用秘密鍵(ca.key)の作成
RSA鍵を生成、DES3の暗号化アルゴリズム使用、鍵長1024ビット指定
# openssl genrsa -des3 -out ca.key -rand rand.dat 1024
686 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
...++++++
...............++++++
e is 65537 (0x10001)
Enter pass phrase for ca.key:xxxxCA用パス入力
Verifying - Enter pass phrase for ca.key:xxxxCA用パス再入力

# openssl req -new -x509 -days 365 -key ca.key -out ca.crt
Enter pass phrase for ca.key:xxxxCA用パス入力
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]:Kanagawa都道府県名の入力
Locality Name (eg, city) [Newbury]:Yokohama市町村名の入力
Organization Name (eg, company) [My Company Ltd]:E-HIRO.NET_CAサイト名の入力(適当です)
Organizational Unit Name (eg, section) []:  ← 空白でいいです
Common Name (eg, your name or your server's hostname) []:e-hiro.netホスト名の入力
Email Address []:webmaster@e-hiro.net管理者メールアドレスの入力


サーバー用秘密鍵(server.key)の作成
RSA鍵を生成、DES3の暗号化アルゴリズム使用、鍵長1024ビット指定
# openssl genrsa -des3 -out server.key -rand rand.dat 1024
686 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
.......................++++++
................................................................................
...............................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:yyyyサーバー用パス入力(CA用とは異なるpass)
Verifying - Enter pass phrase for server.key:yyyyサーバー用パス再入力


サーバー用公開鍵(server.csr)の作成
# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:yyyyサーバー用パス入力
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]:Kanagawa都道府県名の入力
Locality Name (eg, city) [Newbury]:Yokohama市町村名の入力
Organization Name (eg, company) [My Company Ltd]:E-HIRO.NETサイト名の入力
Organizational Unit Name (eg, section) []:  ← 空白でいいです
Common Name (eg, your name or your server's hostname) []:e-hiro.netホスト名の入力
Email Address []:webmaster@e-hiro.net管理者メールアドレスの入力

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


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


サーバー用証明書(server.crt)の作成
mod_ssl付属のsign.shスクリプトでサーバー用デジタル証明書を作成します。
#/usr/local/src/mod_ssl-2.8.19-1.3.31/pkg.contrib/sign.sh server.csr
CA signing: server.csr -> server.crt:
Using configuration from ca.config
Enter pass phrase for ./ca.key:xxxxCA用パス入力
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'JP'
stateOrProvinceName   :PRINTABLE:'Kanagawa'
localityName          :PRINTABLE:'Yokohama'
organizationName      :PRINTABLE:'E-HIRO.NET'
commonName            :PRINTABLE:'e-hiro.net'
emailAddress          :IA5STRING:'webmaster@e-hiro.net'
Certificate is to be certified until Oct 11 05:28:07 2005 GMT (365 days)
Sign the certificate? [y/n]:yyを入力


1 out of 1 certificate requests certified, commit? [y/n]yyを入力
Write out database with 1 new entries
Data Base Updated
CA verifying: server.crt <-> CA cert
server.crt: OK


CA証明書をブラウザにインポートするためのca.derファイル作成
# openssl x509 -inform pem -in ca.crt -outform der -out ca.der


メール用証明書(mail.pem)の作成
# (cat server.crt ; cat server.key) > mail.pem


クライアント用証明書の作成
サーバー証明書をクライアントにインストールしておかないと使用できないわけではないが、
接続のたびにウィンドウが表示されウザイです。
敢えて作成する必要はなく、Apache用に作成したca.derを
クライアントの信頼できる証明機関にインストールすることで解消できます。


各ファイルの所有権の変更
作成後、管理者(root)以外アクセスできないようにモードを変更しておきます。
# chmod -c -R 400 server* ca* rand.dat mail.pem
`server.crt' のモードを 0400 (r--------) に変更しました
`server.csr' のモードを 0400 (r--------) に変更しました
`server.key' のモードを 0400 (r--------) に変更しました
`server.key.bak' のモードを 0400 (r--------) に変更しました
`ca.crt' のモードを 0400 (r--------) に変更しました
`ca.db.certs' のモードを 0400 (r--------) に変更しました
`ca.db.certs/01.pem' のモードを 0400 (r--------) に変更しました
`ca.db.index' のモードを 0400 (r--------) に変更しました
`ca.db.serial' のモードを 0400 (r--------) に変更しました
`ca.der' のモードを 0400 (r--------) に変更しました
`ca.key' のモードを 0400 (r--------) に変更しました
`rand.dat' のモードを 0400 (r--------) に変更しました
`mail.pem' のモードを 0400 (r--------) に変更しました
			
Menu
Copyright © 2004-2005 E-HIRO.NET. All Rights Reserved.