SSL をサポートする Java CAPS の構成

LDAP アダプタと HTTPS アダプタへの OpenSSL ユーティリティーの使用

OpenSSL ユーティリティーは、暗号化アルゴリズム (3DES など)、ハッシュアルゴリズム (SHA1 など)、および公開鍵アルゴリズム (RSA など) の無償の実装です。このユーティリティーには、keytool で提供されない、証明書の署名などの多数のオプションがあります。OpenSSL は、次の Web サイトからダウンロードできます。

http://www.openssl.org

OpenSSL の構築およびインストールの手順に従ってください。

サンプル CA 証明書の作成

この節では、OpenSSL ユーティリティーを使用して CA を作成する方法について、例を使って説明します。ここで生成する CA は、keytoolOpenSSL のどちらで作成したものも、あとで CSR の署名に使用されます。「独自の CA による証明書の署名」を参照してください。

Procedureサンプル CA 証明書を作成する

テスト用にサンプルの CA を生成できます。CA 業者にテスト証明書の署名を依頼する追加の費用を節約するために、サンプルを生成してテスト証明書の署名に使用します。

  1. コマンド行から次の操作を実行します。


    openssl  req  -config c:\openssl\bin\openssl.cnf 
     -new  -x509  -keyout  ca-key.pem.txt -out  ca-certificate.pem.txt  -days  365
    
    Using properties from c:\openssl\bin\openssl.cnf
    Loading ’screen’ into random state: done
    Generating a 1024 bit RSA private key
    .................++++++
    .....................++++++
    writing new private key to ’ca-key.pem.txt’
    Enter PEM pass phrase:
    Verifying password: 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) []:US
    State or Province Name (full name) []:California
    Locality Name (eg, city) []:Monrovia
    Organization Name (eg, company) []:Sun
    Organizational Unit Name (eg, section) []:Development
    Common Name (eg, your websites domain name) []
        :development.sun.com
    Email Address []:development@sun.com  

    パスワード情報の入力を求められます。

  2. パスワードを入力し、CA の非公開鍵で証明書に署名するためこのパスワードを覚えておきます。

    このコマンドにより、CA の非公開鍵と対応する証明書が作成されます。この証明書は、作成された日付および時刻から数えて 365 日間有効です。

    req コマンドには、プロパティーファイル C:\openssl\bin\openssl.cnf が必要です。デフォルトの config.cnf ファイルは、apps サブディレクトリの下の OpenSSL パッケージにあります。


    注 –

    Windows でこのファイルを使用する場合は、二重バックスラッシュを使うようにパスを変更します。Windows 環境での動作を確認済みの完全な Config.cnf ファイルの例については、「Windows の OpenSSL.cnf ファイルの例」を参照してください。


独自の CA による証明書の署名

この節の例では、keytool を使用して証明書署名要求を作成し、前の節で作成した CA で証明書署名要求に対応する署名付き証明書を生成する方法を示します。この節で示される キーストアおよび証明書署名要求を生成する手順については、「JKS 形式のキーストアの作成」ですでに説明しています。


注 –

keytool のコマンドの詳細については、ここでは説明しません。「JKS 形式のキーストアの作成」を参照してください。


Procedurekeytool を使用して CSR を作成および証明書署名要求に対する署名付き証明書を生成する

  1. コマンド行から次の操作を実行します。


    keytool –keystore clientkeystore –genkey –alias client
    
    Enter keystore password:  javacaps
    What is your first and last name?
    [Unknown]:  development.sun.com
    What is the name of your organizational unit?
    [Unknown]:  Development
    What is the name of your organization?
    [Unknown]:  Sun
    What is the name of your City or Locality?
    [Unknown]:  Monrovia
    What is the name of your State or Province?
    [Unknown]:  California
    What is the two-letter country code for this unit?
    [Unknown]:  US
    Is <CN=development.sun.com, OU=Development, O=Sun, L=Monrovia, ST=California, 
    C=US> correct?
    [no]:  yes
    
    Enter key password for <client>
    (RETURN if same as keystore password):
  2. 証明書署名要求を生成します。


    keytool –keystore clientkeystore –certreq –alias client –keyalg rsa 
    –file client.csr
  3. 署名付き証明書を、関連する証明書署名要求に対して生成します。


    openssl  x509  -req  -CA 
        ca-certificate.pem.txt -CAkey ca-key.pem.txt 
        -in client.csr -out client.cer  -days 365  -CAcreateserial
  4. keytool を使用して、CA 証明書をクライアントキーストアにインポートします。


    keytool -import -keystore clientkeystore -file ca-certificate.pem.txt  
    -alias theCARoot 
    
    Enter keystore password:  javacaps
    Owner: EmailAddress=development@sun.com, CN=development.sun.com, OU=Development,
     O=Sun, L=Monrovia, ST=California, C=US
    Issuer: EmailAddress=development@sun.com, CN=development.sun.com, 
    OU=Development, O=Sun, L=Monrovia, ST=California, C=US
    Serial number: 0
    Valid from: Tue May 08 15:09:07 PDT 2007 until: Wed May 08 
        15:09:07 PDT 2008
    Certificate fingerprints:
    MD5:  60:73:83:A0:7C:33:28:C3:D3:A4:35:A2:1E:34:87:F0
    SHA1: C6:D0:C7:93:8E:A4:08:F8:38:BB:D4:11:03:C9:E6:CB:9C:D0:72:D0
    Trust this certificate? [no]:  yes
    Certificate was added to keystore
  5. keytool を使用して、関連するクライアントエイリアスの署名付き証明書をキーストアにインポートします。


    keytool –import –keystore clientkeystore –file client.cer –alias client
    
    Enter keystore password: javacaps
    Certificate reply was installed in keystore

    注意 – 注意 –

    クライアント証明書に証明書チェーンがない場合、次のエラーが生成されます。


    keytool -import -keystore clientkeystore -file client.cer -alias client
    
    Enter keystore password: javacaps
    keytool error: java.lang.Exception: Failed to establish chain from reply

    このエラーは、CA の証明書が最初にキーストアにインポートされなかったことが原因です。まず CA の証明書をインポートし (手順 4)、それから client.cer ファイル自体をインポートして証明書チェーンを形成します (手順 5)。


    これで、非公開鍵と関連する証明書チェーンをキーストア clientkeystore に備えることができました。これを、クライアント (アダプタ) 認証用のキーストアとして使用できます。ただし、CA 証明書は、接続する予定の Web サーバーの信頼できる証明書ストアにインポートするように注意してください。さらに、Web サーバーをクライアント認証用に構成してください (たとえば、Apache の場合は httpd.conf)。

Windows の OpenSSL.cnf ファイルの例

この節では、Windows で使用できる openssl.cnf ファイルの内容について説明します。ディレクトリは適切に変更する必要があります。


#
# SSLeay example properties file.
# This is mostly being used for generation of certificate requests.
#

RANDFILE        = .rnd

####################################################################
[ ca ]
default_ca    = CA_default        # The default ca section

####################################################################
[ CA_default ]

dir        = G:\\openssl\\\bin\\demoCA    # Where everything is kept
certs        = $dir\\certs                # Where the issued certs are kept
crl_dir    = $dir\\crl                # Where the issued crl are kept
database    = $dir\\index.txt            # database index file.
new_certs_dir    = $dir\\newcerts            # default place for new certs.

certificate    = $dir\\cacert.pem                # The CA certificate
serial        = $dir\\serial                # The current serial number
crl        = $dir\\crl.pem                # The current CRL
private_key    = $dir\\private\\cakey.pem       # The private key
RANDFILE    = $dir\\private\\private.rnd     # private random number file

x509_extensions    = x509v3_extensions    # The extentions to add to the cert
default_days        = 365            # how long to certify for
default_crl_days    = 30            # how long before next CRL
default_md        = md5            # which md to use.
preserve        = no            # keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy        = policy_match

# For the CA policy
[ policy_match ]
countryName            = match
stateOrProvinceName        = match
organizationName        = match
organizationalUnitName    = optional
commonName            = supplied
emailAddress            = optional

# For the ’anything’ policy
# At this point in time, you must list all acceptable ’object’
# types.
[ policy_anything ]
countryName        = optional
stateOrProvinceName    = optional
localityName        = optional
organizationName    = optional
organizationalUnitName    = optional
commonName            = supplied
emailAddress            = optional

####################################################################
[ req ]
default_bits        = 1024
default_keyfile     = privkey.pem
distinguished_name    = req_distinguished_name
attributes        = req_attributes

[ req_distinguished_name ]
countryName            = Country Name (2 letter code)
countryName_min        = 2
countryName_max        = 2

stateOrProvinceName        = State or Province Name (full name)

localityName            = Locality Name (eg, city)

0.organizationName        = Organization Name (eg, company)

organizationalUnitName    = Organizational Unit Name (eg, section)

commonName            = Common Name (eg, your website’s domain name)
commonName_max        = 64

emailAddress            = Email Address
emailAddress_max        = 40

[ req_attributes ]
challengePassword        = A challenge password
challengePassword_min    = 4
challengePassword_max    = 20

[ x509v3_extensions ]

注 –

次の著作権表示が適用されます: Copyright © 2004-2008 The OpenSSL Project. All rights reserved.Copyright © 2005-2008 World Wide Web Consortium, (Massachusetts Institute of Technology, Institut National de Recherche en Informatique et en Automatique, Keio University). All Rights Reserved. http://www.w3.org/Consortium/Legal/