« おれおれ証明書(プライベート証明書) サーバ証明書編 | main | 楽しみな映画 バイオハザードⅣアフターライフ »

おれおれ証明書(プライベート証明書) クライアント証明書編

  • author: Tadashi
  • 2010/07/10 20:55

CA構築編、サーバ証明書編、と続いたクライアント証明の実現方法ですが、いよいよ「クライアント証明書」編の始まりです。

ユーザディレクトリに移動します。
# cd /usr/local/ssl

秘密鍵を2048bitで作成します。
# openssl genrsa -out client.private.pem 2048



Generating RSA private key, 2048 bit long modulus
.....................................................................+++
....+++
e is 65537 (0x10001)

秘密鍵を使用して署名リクエスト(公開鍵)を作成します。クライアント(ユーザ)単位に適用する証明書なので、ユーザ名がわかる名前を付けます。
# openssl req -new -key client.private.pem -out admin.free-style.biz.pem



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) [JP]:
→そのままEnterキー
State or Province Name (full name) [Tokyo]:
→そのままEnterキー
Locality Name (eg, city) [Shinagawa-ku]:
→そのままEnterキー
Organization Name (eg, company) [Fs DataCenter CA]:
→そのままEnterキー
Organizational Unit Name (eg, section) []:
→そのままEnterキー
Common Name (eg, your name or your server's hostname) []:
→ユーザ名(admin)を入力します。(各自お好みで)
Email Address []:
→ユーザのメールアドレス(admin@free-style.biz)を入力します。

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
→そのままEnterキー
An optional company name []:
→フレンドリ名(admin)を入力します。(各自お好みで)


「Netscape用」と言われていますが、クライアントで使用するために署名リクエスト(公開鍵)にCAの認証を付加します。
# cd /etc/pki/tls/misc
# openssl ca -out /usr/local/ssl/admin.free-style.biz.crt -infiles /usr/local/ssl/admin.free-style.biz.pem



Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for ../../CA/private/cakey.pem:
→CAの秘密鍵のパスフレーズを入力します。
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 6 (0x6)
Validity
Not Before: Jul 9 06:40:46 2010 GMT
Not After : Jul 8 06:40:46 2020 GMT
Subject:
countryName = JP
stateOrProvinceName = Tokyo
organizationName = Fs DataCenter CA
commonName = admin
emailAddress = admin@free-style.biz
X509v3 extensions:
X509v3 Basic Constraints:
CA:TRUE
Netscape Cert Type:
SSL Client, SSL Server, S/MIME, Object Signing
X509v3 Subject Key Identifier:
D6:4C:45:72:6E:17:9B:94:8F:C4:C1:8A:C0:43:69:59:4B:E5:A6:87
X509v3 Authority Key Identifier:
keyid:AF:3D:E9:BC:17:83:29:D7:C0:4D:3F:E0:32:51:2C:BF:B1:B4:0A:00

Certificate is to be certified until Jul 8 06:40:46 2020 GMT (3652 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


クライアントに組み込むためにp12形式のファイルを作成します。
-export → クライアントの署名リクエストファイル名
-inkey → クライアントの秘密鍵ファイル名
-certfile → CAの公開鍵ファイル名
-name → フレンドリ名
-caname → ルートCA(サーバ証明書のホスト名)
-out → p12形式の出力ファイル名
# openssl pkcs12 -export -in /usr/local/ssl/admin.free-style.biz.crt -inkey /usr/local/ssl/client.private.pem -certfile /etc/pki/CA/cacert.pem -name admin -caname ca1.free-style.biz -out /usr/local/ssl/admin.free-style.biz.p12



Enter Export Password:
→バックアップ用パスワードを入力します。クライアントへのインストール時に必要になります。
Verifying - Enter Export Password:
→もう一度バックアップ用パスワードを入力します。

これでクライアント証明書の完成です。先に作成した「サーバ証明書」と今回の「クライアント証明書」の2つをクライアントにインストールすれば、おれおれS/MIMEが使用できるようになります。


以下、参考にしたサイト。CAを作成しないパターンや古い情報もあるので注意!

S/MIMEでセキュアなメール送信 in PHP

S/MIME(Secure MIME)で電子メールを交換する個人証明書作成を試す

CentOS5.3でオレオレCA局+SSL認証の作り方

SSLおれおれ証明書とクライアント認証


この記事へのトラックバック

この記事のトラックバックURL :

この記事へのコメント

この記事にコメントする

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)