CSRの作成

SSL取得の際に必要なCSRの作成メモ


前提1:CSRを作成するには、秘密鍵ファイルが必要
前提2:秘密鍵ファイルは擬似乱数を元に作られる
前提3:全ての作成コマンドには「openssl」コマンドを使用する

上記前提より、以下の順序で進めます
①opensslの確認
擬似乱数ファイル作成(rand.txt)
秘密鍵ファイル作成(private_key.pem)
CSR作成(csr.pem)

①opensslコマンドの確認(なければインストール)


$ which openssl
/usr/bin/openssl

擬似乱数ファイル作成


openssl md5 乱数ファイル


touch rand.dat
openssl md5 rand.dat > rand.dat

秘密鍵ファイル作成 ※キー長は取得する証明書の商品に合わせる


openssl genrsa -rand 乱数ファイル -des3 キー長

→リダイレクトしてファイル(private_key.pem)作成

$ openssl genrsa -rand rand.dat -des3 2048 > private_key.pem
48 semi-random bytes loaded
Generating RSA private key, 2048 bit long modulus
...........................................................................+++
..................+++
e is 65537 (0x10001)
Enter pass phrase:            // ←ここでパスフレーズを入力
Verifying - Enter pass phrase:

パスフレーズはなんでも良い(大抵はあとで削除することになる)

CSR作成


openssl req -new -key 秘密鍵ファイル -out CSRファイル

$ openssl req -new -key private_key.pem -out csr.pem
Enter pass phrase for private_key.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) [GB]:
State or Province Name (full name) [Berkshire]:
Locality Name (eg, city) [Newbury]:
Organization Name (eg, company) [My Company Ltd]:
Organizational Unit Name (eg, section) :
Common Name (eg, your name or your server's hostname)
:
Email Address :

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password :
An optional company name []:

この後、作成したCSRcsr.pem)の中身をコピー&ペーストして認証局へ申請する事になります。
秘密鍵もサーバ設定で必要になるので取っておきます。

証明書を取得した後の設定はコチラ↓↓↓
http://d.hatena.ne.jp/moroto1122/20090115/1232016361