* webサーバを利用したサーバ認証とクライアント認証 [#g8fc7040]
#contents

* 目的 [#bee53ac7]
apacheを利用して、サーバ認証とクライアント認証を実施する。~
サーバにルートCAから発行されたサーバ証明書を配置、クライアントに中間CAから発行されたクライアント証明書を配置し、正常に通信が行えるかを確認する。

** 前提 [#n487eeb6]
[[OpenSSLによるPKI構築]]を利用してルート証明書、中間証明書を作成しておくこと。

** サーバ証明書によるサーバの正当性確認 [#fdba14dd]

*** webサーバ証明書の作成(ルート認証局で発行) [#m2cb0cc2]
~/ca/websvに作成するものとする。
 [ubuntu@pki ~ca]$ mkdir ~/ca/websv
 [ubuntu@pki ~ca]$ cd ~/ca/websv

- 秘密鍵を保管しておくフォルダを作成しておく
 [ubuntu@pki ~websv]$ mkdir private

- 署名要求を作成(同時に秘密鍵も生成)
秘密鍵の作成と同時にCSRを作成する方法だと、秘密鍵単独で作成する方法と違い、暗号化アルゴリズムが選択できない?ような気がする。
 [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]$ 

- 秘密鍵のパスフレーズを除去
秘密鍵にパスフレーズが含まれている場合、webサーバ起動時にパスフレーズを求められるので、
これを除去しておく
 [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]$

- 署名要求をルートCAへ送付
同一ホストの別ディレクトリで構築しているだけなので、単純にファイルコピーでOK。
遠隔ホストであれば、scpやテキストをコピペでもOK
 [ubuntu@pki ~websv]$ cp websvcsr.pem ../RootCA

- ルートCAで署名要求にサイン
 [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

- サーバ証明書のバイナリを作成
証明書に不要な情報(Certificate:~~)があるので、これを除去してからバイナリ作成
 [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]$ 

*** webサーバ設定 [#o50f4e30]
apache2の設定を実施する。
- 設定ファイル
apache2のSSL用設定ファイルを修正する。
 [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

- SSLの有効化
 [ubuntu@pki ~websv]$ sudo a2enmod ssl
 [ubuntu@pki ~websv]$ sudo a2ensite default-ssl
 [ubuntu@pki ~websv]$ sudo /etc/init.d/apache2 restart

*** クライアント設定 [#e9f11f33]
前の手順で作成しておいたルート証明書をクライアント(ブラウザ)にインストールする

*** 接続テスト [#x880cb09]
実際にブラウザから接続してみて、セキュリティ警告がでないことを確認する。~
ちなみに、上記のままのCSRだと、FQDNが正しくないと警告がでてしまうため、ローカルのIPアドレスなどを指定する。


** クライアント証明書による接続クライアントの制限 [#g7c4a7f5]

*** クライアント証明書の作成(中間認証局で発行) [#m2cb0cc2]
~/ca/clientに作成するものとする。
 [ubuntu@pki ~ca]$ mkdir ~/ca/client
 [ubuntu@pki ~ca]$ cd ~/ca/client

- 秘密鍵を保管しておくフォルダを作成しておく
 [ubuntu@pki ~client]$ mkdir private

- 署名要求を作成(同時に秘密鍵も生成)
秘密鍵の作成と同時にCSRを作成する方法だと、秘密鍵単独で作成する方法と違い、暗号化アルゴリズムが選択できない?ような気がする。
 [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


- 署名要求を中間CAへ送付
同一ホストの別ディレクトリで構築しているだけなので、単純にファイルコピーでOK。
遠隔ホストであれば、scpやテキストをコピペでもOK
 [ubuntu@pki ~client]$ cp clientcsr.pem ../InterCA

- 中間CAで署名要求にサイン
 [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]$ 

*** webサーバ設定 [#vfb7d5a2]

apache2の設定を実施する。
- 設定ファイル
apache2のSSL用設定ファイルを修正する。
 [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


*** クライアント設定 [#s6a2325e]
前の手順で作成しておいた中間証明書をクライアント(ブラウザ)にインストールする~
前の手順で作成しておいたクライアント証明書をクライアント(ブラウザ)にインストールする

*** 接続テスト [#x880cb09]
実際にブラウザから接続してみて、セキュリティ警告がでないことを確認する。~
~
~
~
#counter



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS