差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン 次のリビジョン両方とも次のリビジョン | ||
linux:openssl_private_ca [2019/02/16 21:10] – 作成 ともやん | linux:openssl_private_ca [2020/03/03 10:45] – [参考文献] ともやん | ||
---|---|---|---|
行 1: | 行 1: | ||
====== OpenSSL によるプライベート CA の構築 ====== | ====== OpenSSL によるプライベート CA の構築 ====== | ||
+ | |||
+ | ===== ディレクトリとファイルの作成 ===== | ||
+ | < | ||
+ | $ sudo mkdir -p / | ||
+ | $ sudo touch / | ||
+ | $ sudo bash -c "echo ' | ||
+ | </ | ||
+ | |||
+ | ==== CA のディレクトリとファイル ==== | ||
+ | < | ||
+ | $ ll / | ||
+ | drwxr-xr-x 1 root root 0 2月 11 11:26 certs | ||
+ | drwxr-xr-x 1 root root 0 2月 11 11:26 client | ||
+ | drwxr-xr-x 1 root root 0 2月 11 11:26 crl | ||
+ | -rw-r--r-- 1 root root 0 2月 11 11:27 index.txt | ||
+ | -rw-r--r-- 1 root root 0 2月 11 11:27 index.txt.attr | ||
+ | drwxr-xr-x 1 root root 0 2月 11 11:26 newcerts | ||
+ | drwxr-xr-x 1 root root 0 2月 11 11:26 private | ||
+ | -rw-r--r-- 1 root root 3 2月 11 11:27 serial | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | .col1 { width: 196px; } | ||
+ | </ | ||
+ | </ | ||
+ | ^ ディレクトリ | ||
+ | | certs | 証明書保管用 | ||
+ | | client | ||
+ | | crl | 失効リスト(Certificate Revocation List)保管用 | ||
+ | | newcerts | ||
+ | | private | ||
+ | |||
+ | |||
+ | ===== デフォルトのユーザー情報を設定 ===== | ||
+ | 証明書作成の際に入力の手間を省くために、デフォルト値を設定しておく。\\ | ||
+ | \\ | ||
+ | 設定ファイルをコピーする。 | ||
+ | < | ||
+ | $ sudo cp / | ||
+ | </ | ||
+ | \\ | ||
+ | 設定ファイルを編集する。 | ||
+ | < | ||
+ | $ sudo vi / | ||
+ | </ | ||
+ | |||
+ | <code diff> | ||
+ | [ CA_default ] | ||
+ | dir = / | ||
+ | default_days | ||
+ | |||
+ | [ req ] | ||
+ | default_bits = 2048 | ||
+ | default_md = sha256 | ||
+ | |||
+ | [ req_distinguished_name ] | ||
+ | countryName_default = JP # 国コード | ||
+ | stateOrProvinceName_default = Hokkaido Pref. # 都道府県 | ||
+ | localityName_default = Sapporo City # 市町村区 | ||
+ | # 会社名 or ドメイン名(行末の# | ||
+ | 0.organizationName_default = Monster' | ||
+ | organizationalUnitName_default = - # 組織部門名 | ||
+ | emailAddress_default = domain-admin@monsters-g.com # 管理者メールアドレス | ||
+ | </ | ||
+ | |||
+ | openssl.cnf をコピーして、認証局(ca)、サーバー(server)、クライアント(client)用の設定ファイルを準備する。 | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo bash -c ' | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== プライベート認証局 CA の秘密鍵と証明書の作成 ===== | ||
+ | ==== 作成ファイル ==== | ||
+ | ^ ファイル | ||
+ | | private/ | ||
+ | | cacert.pem | ||
+ | | mgc_ca_cert.der | ||
+ | |||
+ | ==== CA の秘密鍵と証明書の作成 ==== | ||
+ | openssl-mgc-ca.cnf(認証局用設定ファイル)を編集する。 | ||
+ | < | ||
+ | $ sudo vi / | ||
+ | </ | ||
+ | <code ini> | ||
+ | [ usr_cert ] | ||
+ | basicConstraints=CA: | ||
+ | |||
+ | [ v3_ca ] | ||
+ | # nsCertType = sslCA, emailCA | ||
+ | nsCertType = sslCA, emailCA # SSL認証局、電子メール認証局 | ||
+ | </ | ||
+ | |||
+ | CA の秘密鍵と証明書を作成する。 | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl req -new -config / | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | Generating a RSA private key | ||
+ | .................................................+++++ | ||
+ | ..................................................................................+++++ | ||
+ | writing new private key to '/ | ||
+ | Enter PEM pass phrase: # プライベート認証局のパスフレーズを入力 | ||
+ | Verifying - 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 ' | ||
+ | ----- | ||
+ | Country Name (2 letter code) [JP]: # Enter を入力 | ||
+ | State or Province Name (full name) [Hokkaido Pref.]: # Enter を入力 | ||
+ | Locality Name (eg, city) [Sapporo City]: # Enter を入力 | ||
+ | Organization Name (eg, company) [Monsters Garage Co., | ||
+ | Organizational Unit Name (eg, section) [-]: # Enter を入力 | ||
+ | Common Name (eg, your name or your server' | ||
+ | Email Address [domain-admin@monsters-g.com]: | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | CA証明書の確認。 | ||
+ | < | ||
+ | $ openssl x509 -in / | ||
+ | </ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | Certificate: | ||
+ | Data: | ||
+ | Version: 3 (0x2) | ||
+ | Serial Number: | ||
+ | 46: | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | Issuer: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Validity | ||
+ | Not Before: Feb 10 14:33:39 2019 GMT | ||
+ | Not After : Jan 17 14:33:39 2119 GMT | ||
+ | Subject: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | RSA Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | d6: | ||
+ | ca: | ||
+ | f5: | ||
+ | 96: | ||
+ | 8a: | ||
+ | 50: | ||
+ | a1: | ||
+ | 82: | ||
+ | 04: | ||
+ | d8: | ||
+ | 01: | ||
+ | fc: | ||
+ | 2b: | ||
+ | c9: | ||
+ | 92: | ||
+ | cc: | ||
+ | bd:a3 | ||
+ | Exponent: 65537 (0x10001) | ||
+ | X509v3 extensions: | ||
+ | X509v3 Subject Key Identifier: | ||
+ | 75: | ||
+ | X509v3 Authority Key Identifier: | ||
+ | keyid: | ||
+ | |||
+ | X509v3 Basic Constraints: | ||
+ | CA:TRUE | ||
+ | Netscape Cert Type: | ||
+ | SSL CA, S/MIME CA | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | CA のカレントディレクトリの private/ に CA 秘密鍵とカレントディレクトリにCA 証明書が作成される。 | ||
+ | < | ||
+ | $ ll / | ||
+ | -rw------- 1 root root 1854 2月 11 11:40 cakey.pem # CA 秘密鍵 | ||
+ | $ ll / | ||
+ | -rw-r--r-- 1 root root 1586 2月 11 11:40 cacert.pem # CA 証明書 | ||
+ | </ | ||
+ | ==== CA 証明書を DER 形式へ変換 ==== | ||
+ | DER(Distinguished Encoding Rules) 形式は Windows OS で証明書や秘密鍵をインポートするのに使えるフォーマットである。\\ | ||
+ | ここでは PEM 形式の CA 証明書を DER 形式に変換する。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl x509 -inform pem -outform der -in / | ||
+ | </ | ||
+ | </ | ||
+ | CAのカレントディレクトリにCA 証明書(DER形式)が作成される。 | ||
+ | < | ||
+ | $ ll / | ||
+ | -rw-r--r-- 1 root root 1126 2月 11 09:40 mgc_ca_cert.der # CA 証明書(DER形式) | ||
+ | </ | ||
+ | |||
+ | ===== サーバー証明書の作成 ===== | ||
+ | ==== 作成ファイル ==== | ||
+ | ^ ファイル | ||
+ | | serverkey.pem | ||
+ | | serverreq.csr | ||
+ | | servercert.crt | ||
+ | | serverkey-nopwd.pem | ||
+ | | san.ext | ||
+ | ==== サーバー CSR(Certificate Signing Request) の作成 ==== | ||
+ | サーバー CSR は、パブリック認証局(Verisignなど)やプライベート認証局に対するサーバー証明書の署名要求である。\\ 認証局に署名して貰うことによって、証明書として利用できるようになる。\\ | ||
+ | \\ | ||
+ | openssl-mgc-server.cnf(サーバー用設定ファイル)を編集する。\\ < | ||
+ | $ sudo vi / | ||
+ | </ | ||
+ | <code ini> | ||
+ | [ usr_cert ] | ||
+ | basicConstraints=CA: | ||
+ | nsCertType = server # サーバー証明書 | ||
+ | </ | ||
+ | \\ | ||
+ | サーバー CSR(Certificate Signing Request) を作成する。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl req -new -config / | ||
+ | -addext ' | ||
+ | -keyout / | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | Generating a RSA private key | ||
+ | ...................................+++++ | ||
+ | ......................................+++++ | ||
+ | writing new private key to '/ | ||
+ | Enter PEM pass phrase: # パスフレーズを入力 | ||
+ | Verifying - 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 ' | ||
+ | ----- | ||
+ | Country Name (2 letter code) [JP]: # Enter を入力 | ||
+ | State or Province Name (full name) [Hokkaido Pref.]: # Enter を入力 | ||
+ | Locality Name (eg, city) [Sapporo City]: # Enter を入力 | ||
+ | Organization Name (eg, company) [Monsters Garage Co., | ||
+ | Organizational Unit Name (eg, section) [-]: # Enter を入力 | ||
+ | Common Name (eg, your name or your server' | ||
+ | Email Address [domain-admin@monsters-g.com]: | ||
+ | |||
+ | Please enter the following ' | ||
+ | to be sent with your certificate request | ||
+ | A challenge password []: # Enter を入力 | ||
+ | An optional company name []: # Enter を入力 | ||
+ | </ | ||
+ | </ | ||
+ | \\ | ||
+ | CAのカレントディレクトリにサーバー秘密鍵とサーバー CSR(証明書署名要求)が作成される。 | ||
+ | <code bash> | ||
+ | $ ll / | ||
+ | -rw------- 1 root root 1854 2月 10 23:57 serverkey.pem # サーバー秘密鍵 | ||
+ | -rw-r--r-- 1 root root 1106 2月 11 00:03 serverreq.csr # サーバー CSR(証明書署名要求) | ||
+ | </ | ||
+ | \\ | ||
+ | サーバー CSR の内容を確認する。< | ||
+ | $ openssl req -in / | ||
+ | </ | ||
+ | <WRAP prewrap 100%> | ||
+ | <code bash> | ||
+ | Certificate Request: | ||
+ | Data: | ||
+ | Version: 1 (0x0) | ||
+ | Subject: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | RSA Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | ~省略~ | ||
+ | Exponent: 65537 (0x10001) | ||
+ | Attributes: | ||
+ | Requested Extensions: | ||
+ | X509v3 Subject Alternative Name: | ||
+ | DNS: | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | ~省略~ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== プライベート認証局でサーバー CSR に署名する(サーバー証明書作成) ==== | ||
+ | 証明書作成の手前で追加設定ファイルを作成する。\\ | ||
+ | < | ||
+ | $ sudo vi / | ||
+ | </ | ||
+ | <file autoconf / | ||
+ | basicConstraints=CA: | ||
+ | nsCertType=server # サーバー証明書 | ||
+ | nsComment=" | ||
+ | subjectKeyIdentifier=hash | ||
+ | authorityKeyIdentifier=keyid, | ||
+ | subjectAltName=DNS: | ||
+ | </ | ||
+ | サーバー CSR(Certificate Signing Request) に認証局で署名する。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl ca -config / | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | Using configuration from / | ||
+ | Enter pass phrase for / | ||
+ | Check that the request matches the signature | ||
+ | Signature ok | ||
+ | Certificate Details: | ||
+ | Serial Number: 10 (0xa) | ||
+ | Validity | ||
+ | Not Before: Feb 16 11:33:35 2019 GMT | ||
+ | Not After : Jan 23 11:33:35 2119 GMT | ||
+ | Subject: | ||
+ | countryName | ||
+ | stateOrProvinceName | ||
+ | organizationName | ||
+ | organizationalUnitName | ||
+ | commonName | ||
+ | emailAddress | ||
+ | X509v3 extensions: | ||
+ | X509v3 Basic Constraints: | ||
+ | CA:FALSE | ||
+ | Netscape Cert Type: | ||
+ | SSL Server | ||
+ | Netscape Comment: | ||
+ | OpenSSL Generated Certificate | ||
+ | X509v3 Subject Key Identifier: | ||
+ | 4B: | ||
+ | X509v3 Authority Key Identifier: | ||
+ | keyid: | ||
+ | |||
+ | X509v3 Subject Alternative Name: | ||
+ | DNS: | ||
+ | Certificate is to be certified until Jan 23 11:33:35 2119 GMT (36500 days) | ||
+ | Sign the certificate? | ||
+ | |||
+ | |||
+ | 1 out of 1 certificate requests certified, commit? [y/n]y # y と Enter を入力 | ||
+ | Write out database with 1 new entries | ||
+ | Data Base Updated | ||
+ | </ | ||
+ | </ | ||
+ | カレントディレクトリにサーバー証明書が作成される。 | ||
+ | <code bash> | ||
+ | $ ll / | ||
+ | -rw-r--r-- 1 root root 4890 2月 11 00:46 servercert.crt # サーバー証明書 | ||
+ | </ | ||
+ | |||
+ | ==== サーバー証明書の内容確認 ==== | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl x509 -in / | ||
+ | Certificate: | ||
+ | Data: | ||
+ | Version: 3 (0x2) | ||
+ | Serial Number: 10 (0xa) | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | Issuer: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Validity | ||
+ | Not Before: Feb 16 11:33:35 2019 GMT | ||
+ | Not After : Jan 23 11:33:35 2119 GMT | ||
+ | Subject: C = JP, ST = Hokkaido Pref., O = " | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | RSA Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | 91: | ||
+ | 〜省略〜 | ||
+ | Exponent: 65537 (0x10001) | ||
+ | X509v3 extensions: | ||
+ | X509v3 Basic Constraints: | ||
+ | CA:FALSE | ||
+ | Netscape Cert Type: | ||
+ | SSL Server | ||
+ | Netscape Comment: | ||
+ | OpenSSL Generated Certificate | ||
+ | X509v3 Subject Key Identifier: | ||
+ | 4B: | ||
+ | X509v3 Authority Key Identifier: | ||
+ | keyid: | ||
+ | |||
+ | X509v3 Subject Alternative Name: | ||
+ | DNS: | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | | ||
+ | 〜省略〜 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== サーバーで利用する秘密鍵のパスフレーズ除去 ==== | ||
+ | 秘密キーを Web サーバーなどで利用する際にパスフレーズを聞かれないようにするには、サーバー証明書の秘密キーのパスフレーズを除去しておく。\\ | ||
+ | |||
+ | 秘密キーのパスフレーズを除去する。 | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl rsa -in / | ||
+ | Enter pass phrase for / | ||
+ | writing RSA key | ||
+ | </ | ||
+ | </ | ||
+ | カレントディレクトリにパスフレーズを除去した秘密キーが作成される。 | ||
+ | <code bash> | ||
+ | $ ll / | ||
+ | -rw------- 1 root root 1675 2月 11 01:08 serverkey-nopwd.pem # 秘密鍵(パスフレーズなし) | ||
+ | </ | ||
+ | |||
+ | ==== サーバー CSR、証明書、秘密鍵のファイルのバックアップ ==== | ||
+ | 必要に応じて作成したサーバー CSR、証明書、秘密鍵のファイルをわかりやすいように認証局(CA)の管理下のディレクトリにバックアップしておく。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | </ | ||
+ | </ | ||
+ | ===== クライアント証明書の作成 ===== | ||
+ | |||
+ | ==== 作成ファイル ==== | ||
+ | ^ ファイル | ||
+ | | clientkey.pem | ||
+ | | clientreq.csr | ||
+ | | clientcert.crt | ||
+ | | tomoyan-client.p12 | ||
+ | |||
+ | ==== クライアント CSR(Certificate Signing Request) の作成 ==== | ||
+ | クライアント CSR は、パブリック認証局(Verisignなど)やプライベート認証局に対するクライアント証明書の署名要求である。\\ 認証局に署名して貰うことによって、クライアント証明書として利用できるようになる。\\ | ||
+ | \\ | ||
+ | openssl-mgc-client.cnf(クライアント用設定ファイル)を編集する。\\ | ||
+ | < | ||
+ | $ sudo vi / | ||
+ | </ | ||
+ | <WRAP prewrap 100%> | ||
+ | <code ini> | ||
+ | [ usr_cert ] | ||
+ | basicConstraints=CA: | ||
+ | nsCertType = client, email, objsign # クライアント、電子メール、オブジェクトサイン証明書 | ||
+ | </ | ||
+ | </ | ||
+ | \\ | ||
+ | クライアント CSR(Certificate Signing Request) を作成する。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl req -new -config / | ||
+ | </ | ||
+ | </ | ||
+ | **注意: 標準では Country Name, State of Province Name, Organization name は署名する CA のものと同一でなければならない。** | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | Generating a RSA private key | ||
+ | ...+++++ | ||
+ | ........+++++ | ||
+ | writing new private key to '/ | ||
+ | Enter PEM pass phrase: # パスフレーズを入力 | ||
+ | Verifying - 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 ' | ||
+ | ----- | ||
+ | Country Name (2 letter code) [JP]: # Enter を入力 | ||
+ | State or Province Name (full name) [Hokkaido Pref.]: # Enter を入力 | ||
+ | Locality Name (eg, city) [Sapporo City]: # Enter を入力 | ||
+ | Organization Name (eg, company) [Monsters Garage Co., | ||
+ | Organizational Unit Name (eg, section) [-]: # Enter を入力 | ||
+ | Common Name (eg, your name or your server' | ||
+ | Email Address [domain-admin@monsters-g.com]: | ||
+ | |||
+ | Please enter the following ' | ||
+ | to be sent with your certificate request | ||
+ | A challenge password []: # Enter を入力 | ||
+ | An optional company name []: # Enter を入力 | ||
+ | </ | ||
+ | </ | ||
+ | \\ | ||
+ | CAのカレントディレクトリにクライアント秘密鍵とクライアント CSR(証明書署名要求)が作成される。 | ||
+ | <code bash> | ||
+ | $ ll / | ||
+ | -rw------- 1 root root 1854 2月 11 01:35 clientkey.pem # クライアント秘密鍵 | ||
+ | -rw-r--r-- 1 root root 1086 2月 11 01:42 clientreq.csr # クライアント CSR(証明書署名要求) | ||
+ | </ | ||
+ | \\ | ||
+ | クライアント CSR の内容を確認する。< | ||
+ | $ openssl req -in / | ||
+ | </ | ||
+ | <WRAP prewrap 100%> | ||
+ | <code bash> | ||
+ | Certificate Request: | ||
+ | Data: | ||
+ | Version: 1 (0x0) | ||
+ | Subject: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | RSA Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | 98: | ||
+ | f9: | ||
+ | ee: | ||
+ | ec: | ||
+ | 4a: | ||
+ | 32: | ||
+ | 77: | ||
+ | 3f: | ||
+ | f3: | ||
+ | 9b: | ||
+ | 2e: | ||
+ | 46: | ||
+ | e4: | ||
+ | 4a: | ||
+ | 14: | ||
+ | 1c: | ||
+ | e3:39 | ||
+ | Exponent: 65537 (0x10001) | ||
+ | Attributes: | ||
+ | a0:00 | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | ~省略~ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== プライベート認証局でクライアント CSR に署名する(クライアント証明書作成) ==== | ||
+ | クライアント CSR(Certificate Signing Request) に認証局で署名する。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl ca -config / | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | Using configuration from / | ||
+ | Enter pass phrase for / | ||
+ | Check that the request matches the signature | ||
+ | Signature ok | ||
+ | Certificate Details: | ||
+ | Serial Number: 3 (0x3) | ||
+ | Validity | ||
+ | Not Before: Feb 10 17:03:11 2019 GMT | ||
+ | Not After : Jan 17 17:03:11 2119 GMT | ||
+ | Subject: | ||
+ | countryName | ||
+ | stateOrProvinceName | ||
+ | organizationName | ||
+ | organizationalUnitName | ||
+ | commonName | ||
+ | emailAddress | ||
+ | X509v3 extensions: | ||
+ | X509v3 Basic Constraints: | ||
+ | CA:FALSE | ||
+ | Netscape Cert Type: | ||
+ | SSL Client, S/MIME, Object Signing | ||
+ | Netscape Comment: | ||
+ | OpenSSL Generated Certificate | ||
+ | X509v3 Subject Key Identifier: | ||
+ | D8: | ||
+ | X509v3 Authority Key Identifier: | ||
+ | keyid: | ||
+ | |||
+ | Certificate is to be certified until Jan 17 17:03:11 2119 GMT (36500 days) | ||
+ | Sign the certificate? | ||
+ | |||
+ | |||
+ | 1 out of 1 certificate requests certified, commit? [y/n]y # y と Enter を入力 | ||
+ | Write out database with 1 new entries | ||
+ | Data Base Updated | ||
+ | </ | ||
+ | </ | ||
+ | カレントディレクトリにクライアント証明書が作成される。 | ||
+ | <code bash> | ||
+ | $ ll / | ||
+ | -rw-r--r-- 1 root root 4886 2月 11 02:03 clientcert.crt # クライアント証明書 | ||
+ | </ | ||
+ | |||
+ | ==== クライアント証明書の内容確認 ==== | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl x509 -in / | ||
+ | Certificate: | ||
+ | Data: | ||
+ | Version: 3 (0x2) | ||
+ | Serial Number: 2 (0x2) | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | Issuer: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Validity | ||
+ | Not Before: Feb 11 11:49:24 2019 GMT | ||
+ | Not After : Jan 18 11:49:24 2119 GMT | ||
+ | Subject: C = JP, ST = Hokkaido Pref., O = " | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | RSA Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | 3b: | ||
+ | 〜省略〜 | ||
+ | Exponent: 65537 (0x10001) | ||
+ | X509v3 extensions: | ||
+ | X509v3 Basic Constraints: | ||
+ | CA:FALSE | ||
+ | Netscape Cert Type: | ||
+ | SSL Client, S/MIME, Object Signing | ||
+ | Netscape Comment: | ||
+ | OpenSSL Generated Certificate | ||
+ | X509v3 Subject Key Identifier: | ||
+ | 8A: | ||
+ | X509v3 Authority Key Identifier: | ||
+ | keyid: | ||
+ | |||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | | ||
+ | 〜省略〜 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== クライアント証明書、秘密鍵から PKCS#12 個人情報交換ファイルの作成 ==== | ||
+ | PKCS #12 は Personal Information Exchange Syntax Standard という規格で定義された個人情報交換ファイルです。\\ | ||
+ | クライアントでは、証明書と秘密鍵を1つのファイルにまとめた PKCS#12 フォーマットが主に用いられます。\\ | ||
+ | ここでは、クライアント証明書、秘密鍵から PKCS#12 フォーマットの p12 ファイルを作成する。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl pkcs12 -export -in / | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | Enter pass phrase for / | ||
+ | Enter Export Password: # p12 ファイルを読み込むためのパスフレーズを入力 | ||
+ | Verifying - Enter Export Password: # 確認用パスフレーズを入力 | ||
+ | </ | ||
+ | CAのカレントディレクトリに PKCS#12 フォーマットのファイルが作成される。 | ||
+ | < | ||
+ | $ ll / | ||
+ | -rw------- 1 root root 2804 2月 11 07:48 tomoyan-client.p12 # 個人情報交換ファイル | ||
+ | </ | ||
+ | |||
+ | ==== クライアント CSR、証明書、秘密鍵、PKCS# | ||
+ | 必要に応じて作成したクライアント CSR、証明書、秘密鍵、PKCS# | ||
+ | < | ||
+ | $ sudo mkdir / | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | $ sudo mv / | ||
+ | </ | ||
+ | |||
+ | ===== トラブルシューティング ===== | ||
+ | |||
+ | ==== openssl ca で CSR に署名する時に以下のエラーが発生する ==== | ||
+ | openssl ca のバグである可能性が高いが、**-config** で **-keyfile** は分かっているはずなのに **-keyfile** オプションを省略すると、ファイル名: | ||
+ | **-out** オプションをファイル名と勘違いしているので仕様では無いはずである。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | 140354393380672: | ||
+ | 140354393380672: | ||
+ | </ | ||
+ | </ | ||
+ | 以下の様にきちんと **-keyfile** オプションで CA の秘密鍵を指定するとエラーを回避できる。\\ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ sudo openssl ca -config / | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== ブラウザーで SSL のサーバー証明書が NET:: | ||
+ | Chrome 58 以降では、Common Name を評価しなくなったようである。\\ | ||
+ | X509v3 Subject Alternative Name(SAN): DNS: で判定するようである。\\ | ||
+ | CSR を作成する際に openssl.cnf の [ req ] -> req_extensions = v3_req -> [ v3_req ] -> subjectAltName = @alt_names -> [ alt_names ] -> DNS.1, DNS.2 ... を指定する必要があるが、CSR を作成するたびに openssl.cnf を修正するのは面倒である。\\ | ||
+ | OpenSSL Version 1.1.1 より CSR 作成時のコマンド **openssl req** に **-addext** が指定出来るようになった。\\ | ||
+ | < | ||
+ | $ sudo openssl req -new -config / | ||
+ | -addext ' | ||
+ | -keyout / | ||
+ | </ | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | $ openssl req -in / | ||
+ | Certificate Request: | ||
+ | Data: | ||
+ | Version: 1 (0x0) | ||
+ | Subject: C = JP, ST = Hokkaido Pref., L = Sapporo City, O = " | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | RSA Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | 〜省略〜 | ||
+ | Exponent: 65537 (0x10001) | ||
+ | Attributes: | ||
+ | Requested Extensions: | ||
+ | X509v3 Subject Alternative Name: | ||
+ | DNS: | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | 〜省略〜 | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | Requested Extensions: | ||
+ | X509v3 Subject Alternative Name: | ||
+ | DNS: | ||
+ | </ | ||
+ | X509v3 Subject Alternative Name: DNS: が指定出来ている。\\ | ||
+ | |||
+ | ==== openssl ca で ERROR:There is already a certificate for が発生する ==== | ||
+ | <WRAP prewrap 100%> | ||
+ | < | ||
+ | ERROR:There is already a certificate for / | ||
+ | The matching entry has the following details | ||
+ | Type :Valid | ||
+ | Expires on : | ||
+ | Serial Number :09 | ||
+ | File name : | ||
+ | Subject Name :/ | ||
+ | </ | ||
+ | </ | ||
+ | 初期設定では重複して登録できないので revoke 証明書の失効をする。 | ||
+ | < | ||
+ | $ sudo openssl ca -config / | ||
+ | Using configuration from / | ||
+ | Enter pass phrase for / | ||
+ | Revoking Certificate 09. | ||
+ | Data Base Updated | ||
+ | </ | ||
+ | |||
+ | ===== 参考文献 ===== | ||
+ | [[http:// | ||
+ | [[http:// | ||
+ | [[https:// | ||
+ | \\ | ||
+ | [[https:// | ||
+ | [[https:// | ||