クライアント証明は、限られた人のみアクセスを限定したいサイトを構築する場合に有効です。
サーバの証明書と同様、自己認証局に署名してもらうクライアント署名要求書を作成します。
作業は /usr/local/openssl/CLIENT で行います。
# mkdir -p /usr/local/ssl/CLIENT |
# chmod 700 /usr/local/ssl/CLIENT |
場所準備が出来たら、クライアント用の秘密鍵を作成します。
# cd /usr/local/ssl/CLIENT | |
# /usr/local/ssl/bin/openssl genrsa -des3 -out client.key 1024 | |
Generating RSA private key, 1024 bit long modulus | |
.........++++++ | |
...........++++++ | |
e is 65537 (0x10001) | |
Enter pass phrase for client.key: | 【クライアント秘密鍵のパスフレーズを入力】 |
Verifying - Enter pass phrase for client.key: | 【クライアント秘密鍵のパスフレーズの確認】 |
次に、クライアント署名要求書を作成します。
# /usr/local/ssl/bin/openssl req -new -days 365 -key client.key -out clcsr.pem -config /usr/local/ssl/openssl.cnf | |
Enter pass phrase for client.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]:Tokyo | |
Locality Name (eg, city) []:Setagaya-ku | |
Organization Name (eg, company) [Internet Widgits Pty Ltd]:UMIYAMA SHOJI Co., Ltd. | |
Organizational Unit Name (eg, section) []:Eigyou | |
Common Name (eg, YOUR name) []:www.umiyama.co.jp | |
Email Address []:fuguta@umiyama.co.jp | |
Please enter the following 'extra' attributes | |
to be sent with your certificate request | |
A challenge password []: | 【何も入力しない】 |
An optional company name []: | 【何も入力しない】 |
ここで作成した署名要求書(clcsr.pem)をCA管理者に提出して署名してもらいます。
この作業はCA管理者が行う作業です(ここでは同一ホストで行っているのでその必要はありません)。
以下のコマンドで署名してクライアント証明書を作成しますが、 OpenSSLの設定ファイルの「nsCertType」を "client, email" に変更する必要があるので注意が必要です。
# /usr/local/ssl/bin/openssl ca -in clcsr.pem -out clcert.pem -config /usr/local/ssl/openssl.cnf | |
Using configuration from /usr/local/ssl/openssl.cnf | |
Enter pass phrase for /usr/.../private/cakey.pem: | 【証明書のパスフレーズを入力】 |
Check that the request matches the signature | |
Signature ok | |
... (略) ... | |
Certificate is to be certified until Nov 17 07:56:00 2009 GMT (365 days) | |
Sign the certificate? [y/n]:y | |
1 out of 1 certificate requests certified, commit? [y/n]y | |
Write out database with 1 new entries | |
Data Base Updated |
クライアントでは PKCS12形式しか利用できないので clcert.pem を変換する。
変換には、CAの証明書(公開鍵)を含めた形で作業する。
# openssl pkcs12 -export -in clcert.pem -inkey client.key -certfile ../CA/cacert.pem -out clcert.p12 | |
Enter pass phrase for client.key: | 【クライアント秘密鍵のパスフレーズを入力】 |
Enter Export Password: | 【証明書を取り込む時のパスフレーズを設定】 |
Verifying - Enter Export Password: | 【上記パスフレーズの確認】 |
Apache の SSLディレクトリに、CAの証明書(cacert.pem)とクライアント証明の秘密鍵(client.key)、クライアント証明書(clcert.pem)を用意する。
SSLCertificateFile "/usr/local/ssl/SERVER/cert.pem" |
SSLCertificateKeyFile "/usr/local/ssl/SERVER/servernopass.key" |
SSLCertificateChainFile "/usr/local/ssl/CA/cacert.pem" |
SSLCACertificatePath "/usr/local/ssl/CA" |
SSLCACertificateFile "/usr/local/ssl/CA/cacert.pem" |
SSLCARevocationPath "/usr/local/ssl/CLIENT" |
SSLCARevocationFile "/usr/local/ssl/CLIENT/clcert.pem" |
SSLVerifyClient require |
SSLVerifyDepth 1 |