自己証明書の作成方法
自己証明書(オレオレ証明書)の作成方法
基本的には
1. 秘密鍵の作成
2. 秘密鍵を使って証明書署名要求の作成
3. 秘密鍵と証明書署名要求を使って証明書の作成
という流れになる
1. 秘密鍵の作成
$ openssl genrsa -aes128 2048 > test.key
2. 証明書署名要求(CSR: Certificate Signing Request)の作成
$ openssl req -new -key test.key -out test.csr Enter pass phrase for test.pem: # 秘密鍵作成時に入力したパスワード入力 . . . ----- Country Name (2 letter code) [AU]:JP # 国名 State or Province Name (full name) [Some-State]:Tokyo #都道府県名 Locality Name (eg, city) []:Setagaya # 市区町村名 Organization Name (eg, company) [Internet Widgits Pty Ltd]:HogeHoge, Inc. # 会社・団体名 Organizational Unit Name (eg, section) []:Development Section1 # 部署名 Common Name (e.g. server FQDN or YOUR name) []:foobar.nouziru.com # FQDN Email Address []: nouziru@mail.com # メールアドレス Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: # 入力不要 An optional company name []: # 入力不要
確認
$ openssl req -text -noout -in test.csr Certificate Request: Data: Version: 0 (0x0) Subject: C=JP, ST=Tokyo, L=Setagaya, O=HogeHoge, Inc., OU=Development Section1, CN=foobar.nouziru.com/emailAddress=nouziru@mail.com Subject Public Key Info: . . .
3. 自己証明書(CRT)の作成
$ openssl x509 -days 3650 -req -signkey test.key < test.csr > test.crt Signature ok subject=/C=JP/ST=Tokyo/L=Setagaya/O=HogeHoge, Inc./OU=Development Section1/CN=foobar.nouziru.ddns.net/emailAddress=nouziru@mail.com Getting Private key
確認
$ openssl x509 -text -noout -in test.crt
以上で自己証明書の作成は完了
$ ls -l total 44 -rw-r--r-- 1 nouziru nouziru 1359 Oct 12 13:11 test.crt -rw-r--r-- 1 nouziru nouziru 1082 Oct 12 12:58 test.csr -rw-r--r-- 1 nouziru nouziru 1766 Oct 12 12:56 test.key
csrファイルは特に必要ないので削除してもかまわない
その他
derファイルへの変換
$ openssl x509 -in test.crt -outform DER -out test.der
SAN情報を付加する場合(Chrome58対策)
crtを作るときに以下のようにextファイルを作成してdomain情報をのせる
## create extension file $ echo subjectAltName=DNS:${YOUR DOMAIN} > v3.ext # generate crt $ openssl x509 -days 3650 -req -signkey ${name}.key < ${name}.csr > ${name}.crt -extfile v3.ext