SSLの証明書を作る。
CA局も立てて、自分で自分を証明するようにする。
/etc/ssl/openssl.cnfの設定を書き換える。
dir = /etc/xxx/CA
(CA局に関する証明書等を入れるディレクトリを指定)
default_days = 3652
(証明書のデフォルトを10年に)
basicConstraints=CA:TRUE
(CA局の証明書も作るため、TRUEに)
nsCertType = server, sslCA, emailCA
(Netscape向けの設定。どの証明書を作るか。)
/etc/ssl/miscにあるCA.shの中の設定を書き換える。
DAYS="-days 3652"
(証明書の有効期限を10年に)
CADAYS="-days 3652"
(CA局証明書の有効期限を10年に)
CATOP=/etc/xxx/CA
(証明書等作成のディレクトリを指定)
上記のCA.shを実行
# ./CA.sh -newca
CA certificate filename (or enter to create) (Enterを押して新規作成する。)
Making CA certificate ...
Generating a 1024 bit RSA private key
.++++++
..........++++++
writing new private key to '/etc/xxx/CA/private/./xxxxx.pem'
Enter PEM pass phrase:(設定したいパスフレーズを入力)
Verifying - Enter PEM pass phrase:(上と同じパスフレーズを入力)
-----
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]:(都道府県名を入れる)
Locality Name (eg, city) []:(市町村名を入れる)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:(団体名を入れる)
Organizational Unit Name (eg, section) []:(配下の組織名を入れる)
Common Name (eg, YOUR name) []:(識別に使う名称を入れる)
Email Address []:xxxx@nns-fact.2y.net(メールアドレスを入れる)
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(そのままEnter)
An optional company name []:(そのままEnter)
(省略)
Write out database with 1 new entries
Data Base Updated
pemファイルをブラウザにインポート可能なder形式に変換。
# cd /etc/xxx/CA
openssl x509 -days 3652 -inform pem -in xxxxx.pem -outform der -out cacert.der
cacert.derは公開し、自分を含め、必要な方にブラウザにインポートしてもらいます。
つづいてサーバ側の証明書作成のお話。
秘密鍵を保存するディレクトリに移動し、秘密鍵を生成。
# cd /etc/xxx/private/
# openssl genrsa -des3 1024 -days 3652 > yyyyy.key
Generating RSA private key, 1024 bit long modulus
....................++++++
...................++++++
e is 65537 (0x10001)
Enter pass phrase:(設定したいパスフレーズを入力)
Verifying - Enter pass phrase:(上と同じパスフレーズを入力)
秘密鍵から認証部分を削除(SMTPでのエラーを防ぐ、まぁ念のため)
openssl rsa -in yyyyy.key -out yyyyy.key
Enter pass phrase for private.key:(先ほど設定した秘密鍵のパスフレーズを入力)
writing RSA key
続いてサーバー証明書(署名要求書)を作成する。
# cd /etx/xxx/csr
# openssl req -new -key ../private/yyyyy.key -out zzzzz.csr -days 3652
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]:(都道府県名を入れる)
Locality Name (eg, city) []:(市町村名を入れる)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:(団体名を入れる)
Organizational Unit Name (eg, section) []:(配下の組織名を入れる)
Common Name (eg, YOUR name) []:(識別に使う名称を入れる)
Email Address []:xxxx@nns-fact.2y.net(メールアドレスを入れる)
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:(そのままEnter)
An optional company name []:(そのままEnter)
このcsrに先ほど作ったCA局に署名させる。
openssl ca -config /etc/ssl/openssl.cnf -in private.csr -keyfile /etc/xxx/CA/aaaaa/bbbbb.pem -cert /etc/xxx/CA/cacert.pem -out ssl.pem
Using configuration from /etc/ssl/openssl.cnf
Enter pass phrase for /etc/ssl/CA/private/cakey.pem:
Check that the request matches the signature
Signature ok
できたファイルがpem形式なので、公開鍵形式のcrtに変換する。
# openssl x509 -days 3652 -in ssl.pem -out ssl.crt
このままでも良いが、postfixのssl化(将来用)に、ファイルを一つにまとめる。
# (cat ssl.crt ; cat ssl.pem)> ssl_smtp.pem
これでsslに必要な証明書がそろった。