最終更新日:2013年8月31日
サーバ証明書を受けたいサーバ(例えばWWWサーバ)では、以下の手順で署名要求書(CSR)を作成し、それを認証局(CA)に送付し、CAにてサーバ証明書を作成してもらう必要があります。
(サーバ証明書の入手手順: サーバ証明書が必要なサーバ側での作業になります)
- サーバの秘密鍵(プライベートキー)を作成する。
- プライベートキーを使い署名要求書(CSR)を作成する。
- CSRをCAに送付してサーバ証明書を作成してもらいそれを送り返してもらう。
- サーバ証明書に必要に応じてプライベートキーをマージする。
尚、以下では次のような条件でサーバ証明書を作成します。
設定内容 設定値(Debian系) 設定値(Redhat系) 備考 OpenSSL関連のデータディレクトリ /etc/ssl /etc/pki/tls プライベートキー(サーバの秘密鍵)の作成場所 /etc/ssl/private /etc/pki/tls/private プライベートキー(サーバの秘密鍵)の名前 server.key server.key 目的が判る名前を付けると良い(ex. mail-server.key, www-server.key) プライベートキー(サーバの秘密鍵)の鍵の長さ 2048 2048 サーバ証明書の有効期限 365(1年) 365(1年)
1. OpenSSL設定ファイルを作成する。
最初にOpenSSLの設定ファイルを編集しておきます。
2. サーバの秘密鍵(プライベートキー)を作成する。
次のコマンドを実行して、サーバのプライベートキーを作成します。(サーバ証明書の必要なすべてのサーバで実行します)
Debian・Ubuntu Redhat・CentOS・SL-Linux $ cd /etc/ssl/private
$ sudo openssl genrsa -des3 -out server.key 2048
# cd /etc/pki/tls/private
# openssl genrsa -des3 -out server.key 2048
ここではキー長を2048バイトにしてますが、必要に応じて可変してください。なお2048以下はセキュリティの問題から推奨されません。(ベリサインなどのグローバルCAでは2048以下のキーを受け付けません)
コマンドを入力すると次に様な画面が表示され入力を求められます。
Generating RSA private key, 2048 bit long modulus
........................................................+++
...........................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key: 秘密鍵用のパスフレーズを入力 [Enter]
Verifying - Enter pass phrase for server.key: 再度パスフレーズを入力 [Enter]
これでプライベートキーの作成は完了です。 ただし、このキーファイルは暗号化された状態で、このキーをサーバでそのまま利用するとサーバの起動時にパスフレーズを求めてきてしまいますので、暗号化を解除したキーファイルも作成しておきます。
# openssl rsa -in server.key -out nopass_server.key
3. 署名要求書(CSR)を作成する。
次のコマンドを実行して、サーバの署名要求書(CSR)を作成します。(サーバ証明書の必要なすべてのサーバで実行します)
Debian・Ubuntu Redhat・CentOS・SL-Linux $ cd /etc/ssl
$ sudo openssl req -new -days 365 -key private/server.key -out server-csr.pem
# cd /etc/pki/tls
# openssl req -new -days 365 -key private/server.key -out server-csr.pem
コマンドを入力すると次に様な画面が表示され入力を求められます。
Enter pass phrase for private/server.key: 秘密鍵のパスフレーズ [Enter]
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-to]: [Enter]
Locality Name (eg, city) [Chiyoda-kui]: [Enter]
Organization Name (eg, company) [Example Corp] [Enter]:
Organizational Unit Name (eg, section) []: [Enter]
Common Name (eg, your name or your server's hostname) []: www.example.jp [Enter]
Email Address [webmaster@example.jp]: [Enter]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: [Enter]
An optional company name []: [Enter]
これでCSRの作成は完了です。 作成された "server-csr.pem" ファイルを認証局に送付して、認証局の認証を受けたサーバ証明書を発行して貰います。 この後の作業はCAからサーバ証明書が送り返されてきてから作業になり、証明書の必要な各サービスでの作業となります。なお、作成されたCSRファイルの内容を確認したい場合には$ openssl req -inform pem -in server-csr.pem -textを実行すれば良い。
Copyright© 1998-2013 ROBATA.ORG