apacheを利用して、サーバ認証とクライアント認証を実施する。
サーバにルートCAから発行されたサーバ証明書を配置、クライアントに中間CAから発行されたクライアント証明書を配置し、正常に通信が行えるかを確認する。
/ca/websvに作成するものとする。
[ubuntu@pki ~ca]$ mkdir ~/ca/websv [ubuntu@pki ~ca]$ cd ~/ca/websv
[ubuntu@pki ~websv]$ mkdir private
[ubuntu@pki ~websv]$ openssl req -config ../configs/openssl_req.cnf -new -newkey rsa:2048 -keyout private/websvkey.pem -out websvcsr.pem Generating a 2048 bit RSA private key ..+++ ................................................................+++ writing new private key to 'private/websvkey.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) [JP]:JP State or Province Name (full name) []:Tokyo Organization Name (eg, company) []:Prosper2 Organizational Unit Name (eg, section) []:web server Common Name (e.g. server FQDN or YOUR name) []:websv.prosper2.org [ubuntu@pki ~websv]$
[ubuntu@pki ~websv]$ openssl rsa -in private/websvkey.pem -out private/websvkey.pem Enter pass phrase for private/websvkey.pem: writing RSA key [ubuntu@pki ~websv]$
[ubuntu@pki ~websv]$ cp websvcsr.pem ../RootCA
[ubuntu@pki ~websv]$ cd ../RootCA
[ubuntu@pki ~RootCA]$ openssl ca -config ../configs/openssl_sign.cnf -keyfile private/RootCA_key.pem -batch -days 30 -cert RootCA_crt.pem -extensions v3_server -in websvcsr.pem -out websvcrt.pem
Using configuration from ../configs/openssl_sign.cnf
Enter pass phrase for private/RootCA_key.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 3 (0x3)
Validity
Not Before: Jul 12 23:49:27 2013 GMT
Not After : Aug 11 23:49:27 2013 GMT
Subject:
countryName = JP
stateOrProvinceName = Tokyo
organizationName = Prosper2
organizationalUnitName = web server
commonName = websv.prosper2.org
X509v3 extensions:
X509v3 Subject Key Identifier:
5E:25:4E:08:B5:8E:42:EA:6C:4E:64:8E:1A:18:F5:5E:49:D1:5B:FF
X509v3 Authority Key Identifier:
keyid:B1:0F:66:B2:40:FD:F4:3E:12:31:03:E6:C7:2B:BE:C6:3A:1A:CB:03
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
Digital Signature, Non Repudiation, Key Encipherment
Certificate is to be certified until Aug 11 23:49:27 2013 GMT (30 days)
Write out database with 1 new entries
Data Base Updated
[ubuntu@pki ~RootCA]$ cp websvcrt.pem ../websv
[ubuntu@pki ~RootCA]$ cd ../websv[ubuntu@pki ~websv]$ openssl x509 -in websvcrt.pem -out websvcrt.pem [ubuntu@pki ~websv]$ openssl x509 -inform PEM -outform DER -in websvcrt.pem -out websvcrt.der [ubuntu@pki ~websv]$
apache2の設定を実施する。
[ubuntu@pki ~websv]$ sudo vi /etc/apache2/sites-available/default-ssl #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key SSLCertificateFile /home/ubuntu/ssl/websv/websvcrt.pem SSLCertificateKeyFile /home/ubuntu/ssl/websv/private/websvkey.pem
[ubuntu@pki ~websv]$ sudo a2enmod ssl [ubuntu@pki ~websv]$ sudo a2ensite default-ssl [ubuntu@pki ~websv]$ sudo /etc/init.d/apache2 restart
前の手順で作成しておいたルート証明書をクライアント(ブラウザ)にインストールする
実際にブラウザから接続してみて、セキュリティ警告がでないことを確認する。
ちなみに、上記のままのCSRだと、FQDNが正しくないと警告がでてしまうため、ローカルのIPアドレスなどを指定する。
/ca/clientに作成するものとする。
[ubuntu@pki ~ca]$ mkdir ~/ca/client [ubuntu@pki ~ca]$ cd ~/ca/client
[ubuntu@pki ~client]$ mkdir private
[ubuntu@pki ~client]$ openssl req -config ../configs/openssl_req.cnf -new -newkey rsa:2048 -keyout private/clientkey.pem -out clientcsr.pem Generating a 2048 bit RSA private key ................+++ ..........................+++ writing new private key to 'private/clientkey.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) [JP]:JP State or Province Name (full name) []:Tokyo Organization Name (eg, company) []:Prosper2 Organizational Unit Name (eg, section) []:Client Certificate Common Name (e.g. server FQDN or YOUR name) []:Client Certificate ubuntu@SVRootCA01:~/ca/client$ ls
[ubuntu@pki ~client]$ cp clientcsr.pem ../InterCA
[ubuntu@pki ~client]$ cd ../InterCA
[ubuntu@pki ~InterCA]$ openssl ca -config ../configs/openssl_sign.cnf -keyfile private/InterCA_key.pem -batch -days 30 -cert InterCA_crt.pem -extensions v3_client -in clientcsr.pem -out clientcrt.pem
Using configuration from ../configs/openssl_sign.cnf
Enter pass phrase for private/InterCA_key.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Jul 13 03:47:34 2013 GMT
Not After : Aug 12 03:47:34 2013 GMT
Subject:
countryName = JP
stateOrProvinceName = Tokyo
organizationName = Prosper2
organizationalUnitName = Client Certificate
commonName = Client Certificate
X509v3 extensions:
X509v3 Subject Key Identifier:
4C:E7:6B:0E:D0:8A:7D:48:15:FB:3D:9E:EA:97:61:98:03:09:77:0C
X509v3 Authority Key Identifier:
keyid:94:15:EC:04:A1:25:24:82:18:13:DF:07:A3:31:83:43:DA:08:16:BF
X509v3 Basic Constraints:
CA:FALSE
X509v3 Key Usage:
Digital Signature, Non Repudiation, Key Encipherment
X509v3 Extended Key Usage:
TLS Web Client Authentication
Certificate is to be certified until Aug 12 03:47:34 2013 GMT (30 days)
Write out database with 1 new entries
Data Base Updated
[ubuntu@pki ~InterCA]$ cp clientcrt.pem ../client
[ubuntu@pki ~InterCA]$ cd ../client[ubuntu@pki ~client]$ openssl pkcs12 -export -inkey private/clientkey.pem -in clientcrt.pem -out clientcrt.p12 Enter pass phrase for private/clientkey.pem: Enter Export Password: Verifying - Enter Export Password: [ubuntu@pki ~client]$
apache2の設定を実施する。
[ubuntu@pki ~client]$ sudo vi /etc/apache2/sites-available/default-ssl #SSLCACertificatePath /etc/ssl/certs/ #SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt SSLCACertificatePath /home/ubuntu/ssl/RootCA/ SSLCACertificateFile /home/ubuntu/ssl/RootCA/RootCA_crt.pem #SSLVerifyClient require #SSLVerifyDepth 10 SSLVerifyClient require SSLVerifyDepth 2
[ubuntu@pki ~client]$ sudo /etc/init.d/apache2 restart
前の手順で作成しておいた中間証明書をクライアント(ブラウザ)にインストールする
前の手順で作成しておいたクライアント証明書をクライアント(ブラウザ)にインストールする
実際にブラウザから接続してみて、セキュリティ警告がでないことを確認する。