OpenSSLで証明書を承認する
先に作成していたCSRに対して、CAを使用して証明書を発行してみる。
なお、先に作成していたopenssl.confやCSRを利用するものと想定。コマンドは以下のようになる。
openssl ca -conf openssl.conf -in server1_csr.pem
設定ファイルがおかしいと何らかのエラーが出るはず。
自分でもいくつかエラーが出た。
Using configuration from openssl.conf
Error opening CA private key /MyOwnRootCA/private/cakey.pem
334:error:02001002:system library:fopen:No such file or directory:bss_file.c:278:fopen('/MyOwnRootCA/private/cakey.pem','r')
334:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:280:
unable to load CA private keyこれは、CAの秘密鍵にアクセスできないときだったと思う。設定ファイル(openssl.conf)のprivate_keyや、
default_keyfileの場所を見直すか、コマンドラインで「-keyfile private/cakey.pem」というように秘密鍵を指定すれば解決するはず。
Using configuration from openssl.conf Enter pass phrase for /MyOwnRootCA/private/cakey.pem: unable to load CA private key 338:error:06065064:digital envelope routines:EVP_DecryptFinal:bad decrypt:evp_enc.c:509: 338:error:0906A065:PEM routines:PEM_do_header:bad decrypt:pem_lib.c:423:
これは、秘密鍵のパスフレーズが間違えているとき。これは重症。CAの証明書を作り直すしかない。
Using configuration from openssl.conf Enter pass phrase for /MyOwnRootCA/private/cakey.pem: variable lookup failed for MyOwnRootCA::certificate 340:error:0E06D06C:configuration file routines:NCONF_get_string:no value:conf_lib.c:329:group=MyOwnRootCA name=certificate
これは、CAの証明書にアクセスできないとき。設定ファイル(openssl.conf)のcertificateを見直すか、
コマンドラインで「-cert cacert.pem」というように直接証明書を指定すれば解決するはず。
Using configuration from openssl.conf Enter pass phrase for /MyOwnRootCA/private/cakey.pem: Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'JP' stateOrProvinceName :PRINTABLE:'Server1 State Name' localityName :PRINTABLE:'Server1 City' organizationName :PRINTABLE:'Server1 Organization' organizationalUnitName:PRINTABLE:'Server1 Unit' commonName :PRINTABLE:'Server1' emailAddress :IA5STRING:'hogehoge.fugafuga@example.com' organizationUnitName:unknown object type in 'policy' configuration
というのもあった。これは、openssl.confのpolicyで、organizationalUnitName = optional と定義できるのだが、
organizationUnitName = optional と間違えていたときに発生。
なかなか気付けず苦労した・・・TRY & ERROR を繰り返し、問題がすべて解決すれば、
冒頭の openssl ca 〜 コマンドでサーバー証明書は完成するはず。以下のようになる。
Using configuration from openssl.conf
Enter pass phrase for /MyOwnRootCA/private/cakey.pem:
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'JP'
stateOrProvinceName :PRINTABLE:'Server1-State'
localityName :PRINTABLE:'Server1-City'
organizationName :PRINTABLE:'Server1-Organization'
organizationalUnitName:PRINTABLE:'Server1-OrgUnit'
commonName :PRINTABLE:'Server1'
emailAddress :IA5STRING:'hogehoge.fugafuga@example.com'
Certificate is to be certified until Oct 27 17:05:48 2019 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: md5WithRSAEncryption
Issuer: CN=MyOwnRootCA, ST=Tokyo, C=JP/emailAddress=hogehoge.fugafuga@example.com, O=My Own Root Certification Authority
Validity
Not Before: Oct 29 17:05:48 2009 GMT
Not After : Oct 27 17:05:48 2019 GMT
Subject: C=JP, ST=Server1-State, O=Server1-Organization, OU=Server1-OrgUnit, CN=Server1/emailAddress=hogehoge.fugafuga@example.com
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:ea:c0:41:dd:00:60:fc:d6:7e:b2:cc:4d:44:a4:
59:98:6e:dd:23:4b:b6:c6:5e:e7:e8:d2:23:e2:1e:
0e:48:06:67:0c:1e:56:69:9e:62:03:23:f9:3e:cf:
e0:a7:70:b9:de:d5:f7:3f:a3:3f:9e:b5:e1:bf:a4:
3e:6f:7f:26:d2:ec:9c:15:94:58:84:fc:80:07:eb:
d4:cd:c4:2e:d0:7d:1a:a2:ee:01:93:34:cc:ee:68:
51:21:40:64:82:ec:d7:7e:57:74:5c:11:c6:c6:3d:
ab:b9:b7:0e:07:bf:42:8d:b5:95:64:de:06:57:10:
42:34:43:f7:b8:68:f6:d2:5f
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Signature Algorithm: md5WithRSAEncryption
56:53:35:72:ee:4b:fa:ff:0d:e5:47:63:15:45:c1:b5:78:9f:
45:4c:ec:55:35:fb:89:17:c1:18:62:4b:c3:20:87:64:1b:49:
c6:5c:d0:8a:12:5b:dc:dc:f5:7e:ca:f2:b5:68:77:55:cd:7f:
80:e9:6c:4b:17:16:c6:51:b0:55:e3:aa:31:09:ae:d4:38:17:
fc:b1:b6:be:73:23:c1:78:f9:07:c0:8a:19:0a:7a:b4:69:44:
fb:e4:de:f0:4e:08:41:e0:1c:51:b0:90:d7:17:d2:a3:9e:9c:
1f:a8:ed:c3:06:9c:e5:5c:36:8c:dd:aa:ef:14:2c:c0:53:5b:
1a:f5:e3:7b:7d:3a:5d:50:92:4e:e5:ba:d2:46:39:df:76:b3:
cf:88:86:cf:9d:a6:78:fc:71:75:bd:54:81:e6:bd:e5:c0:2e:
d6:60:80:f8:c9:57:25:38:e1:f2:85:44:e8:1c:9b:5c:8b:cd:
36:b5:1b:dd:ff:70:61:bf:1a:a4:4c:4a:e8:74:d8:32:2c:37:
d2:11:2b:73:72:ca:80:34:96:4c:79:38:64:da:c3:65:44:23:
11:93:f7:6b:33:f9:32:8b:6e:63:75:05:a2:a7:af:21:67:3d:
0a:f7:24:1d:b6:07:9a:e8:f5:19:9b:f9:b6:4b:88:20:b9:03:
ec:f8:7b:ee
-----BEGIN CERTIFICATE-----
〜証明書の内容〜
-----END CERTIFICATE-----
Data Base UpdatedBEGIN CERTIFICATE の行から、END CERTIFICATE の行までをテキストエディタでコピーし、
拡張子をpemとかcerとかで保存してやれば、それをサーバー証明書として使うことができる。