・CentOS8でプライベート認証局を作って、LAN内のWEBサーバにHTTPSアクセスができるようにしたい。
・ネットで検索すると、新旧のいろいろな情報が出てきて、同じように真似してやってみたが上手くいかないので、最新の手順を詳しく知りたい。
こういった疑問に答えます。
本記事の内容
- CentOS8とOpenSSLでプライベート認証局(ルートCA)を作る方法
- CentOS8とOpenSSLで中間認証局を作る方法
- CentOS8のWEBサーバの証明書を作る方法
- CentOS8・ApacheのWEBサーバに証明書を設定してHTTPSアクセスを許可する方法
この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。
私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。
前回の記事
前回の記事では、中間CAの署名要求CSRファイルの作成までを済ませました。
①~⑦までをまとめて読みたい方は下記のまとめ記事から。
中間CAにルートCAが署名
中間CAからルートCAに対しての署名要求CSRファイルに対して、
ルートCAが署名を行います。
中間CA用のconfファイルの作成
openssl.cnf をコピーしてopenssl-inter-ca.cnfを作成
cd /etc/pki/tls
cp openssl.cnf openssl-inter-ca.cnf
[root@SV-EARTH interCA]# cd /etc/pki/tls [root@SV-EARTH tls]# cp openssl.cnf openssl-inter-ca.cnf
confの内容を編集
vi /etc/pki/tls/openssl-inter-ca.cnf
[ v3_ca ] # Extensions for a typical CA # PKIX recommendation. subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer basicConstraints = critical,CA:true, pathlen:0 # Key usage: this is typical for a CA certificate. However since it will # prevent it being used as an test self-signed certificate it is best # left out by default. keyUsage = critical, cRLSign, digitalSignature, keyCertSign extendedKeyUsage = critical, serverAuth, clientAuth, emailProtection # Some might want this also nsCertType = sslCA, emailCA # Include email address in subject alt name: another PKIX recommendation # subjectAltName=email:copy # Copy issuer details # issuerAltName=issuer:copy # DER hex encoding of an extension: beware experts only! # obj=DER:02:03 # Where 'obj' is a standard or added object # You can even override a supported extension: # basicConstraints= critical, DER:30:03:01:01:FF
[ v3_ca ]
の以下の部分を中間CA用に編集
basicConstraints = critical,CA:true, pathlen:0
keyUsage = critical, cRLSign, digitalSignature, keyCertSign
を変更extendedKeyUsage = critical, serverAuth, clientAuth, emailProtection
を追記nsCertType = sslCA, emailCA
ルートCAが秘密鍵で中間CAの署名要求CSRファイルに署名して、中間CAの証明書を作成
openssl ca -config /etc/pki/tls/openssl-inter-ca.cnf \
-days 365 -policy policy_anything \
-out /etc/pki/interCA/interCA_cert.pem \
-extensions v3_ca \
-infiles /etc/pki/interCA/interCA_csr.pem
[root@SV-EARTH interCA]# openssl ca -config /etc/pki/tls/openssl-inter-ca.cnf \ > -days 365 -policy policy_anything \ > -out /etc/pki/interCA/interCA_cert.pem \ > -extensions v3_ca \ > -infiles /etc/pki/interCA/interCA_csr.pem Using configuration from /etc/pki/tls/openssl-inter-ca.cnf Enter pass phrase for /etc/pki/CA/private/cakey.pem:★★★秘密鍵のパスワード★★★ Check that the request matches the signature Signature ok Certificate Details: Serial Number: 08:90:dc:22:c5:bf:cc:56:77:7a:d6:64:09:19:0f:bf:34:03:1d:1b Validity Not Before: Sep 12 22:51:37 2020 GMT Not After : Sep 12 22:51:37 2021 GMT Subject: countryName = JP stateOrProvinceName = Tokyo localityName = Shinagawa-ku organizationName = EARTH PLANET Inc. commonName = EARTH PLANET Inter CA emailAddress = interca@sv-earth.planet.jp X509v3 extensions: X509v3 Subject Key Identifier: 51:01:1C:CF:0D:28:0F:6E:6B:5F:B7:00:A7:3B:A7:30:42:4E:D0:7E X509v3 Authority Key Identifier: keyid:3B:C6:C5:A4:75:5A:1F:E9:DA:40:AD:E6:EC:40:34:14:53:34:26:E8 X509v3 Basic Constraints: critical CA:TRUE, pathlen:0 X509v3 Key Usage: critical Digital Signature, Certificate Sign, CRL Sign X509v3 Extended Key Usage: critical TLS Web Server Authentication, TLS Web Client Authentication, E-mail Protection Netscape Cert Type: SSL CA, S/MIME CA Certificate is to be certified until Sep 12 22:51:37 2021 GMT (365 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 Data Base Updated
作成された中間CAの証明書の内容を表示
openssl x509 -in /etc/pki/interCA/interCA_cert.pem -text
[root@SV-EARTH interCA]# openssl x509 -in /etc/pki/interCA/interCA_cert.pem -text Certificate: Data: Version: 3 (0x2) Serial Number: 08:90:dc:22:c5:bf:cc:56:77:7a:d6:64:09:19:0f:bf:34:03:1d:1b Signature Algorithm: sha256WithRSAEncryption Issuer: C = JP, ST = Tokyo, O = EARTH PLANET Inc., CN = EARTH PLANET Root CA, emailAddress = rootca@sv-earth.planet.jp Validity Not Before: Sep 12 22:51:37 2020 GMT Not After : Sep 12 22:51:37 2021 GMT Subject: C = JP, ST = Tokyo, L = Shinagawa-ku, O = EARTH PLANET Inc., CN = EARTH PLANET Inter CA, emailAddress = interca@sv-earth.planet.jp Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:bc:86:c1:17:01:5c:f0:84:86:54:31:77:5c:c7: 4c:92:07:ef:89:f5:33:44:3d:d3:b3:e2:fe:14:c1: --------------------(中略)---------------- cc:da:01:b9:da:2f:9d:89:48:c9:81:a0:e6:5f:d0: 47:7c:50:26:da:12:8f:7b:22:18:13:8a:57:23:f6: 38:5f Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Subject Key Identifier: 51:01:1C:CF:0D:28:0F:6E:6B:5F:B7:00:A7:3B:A7:30:42:4E:D0:7E X509v3 Authority Key Identifier: keyid:3B:C6:C5:A4:75:5A:1F:E9:DA:40:AD:E6:EC:40:34:14:53:34:26:E8 X509v3 Basic Constraints: critical CA:TRUE, pathlen:0 X509v3 Key Usage: critical Digital Signature, Certificate Sign, CRL Sign X509v3 Extended Key Usage: critical TLS Web Server Authentication, TLS Web Client Authentication, E-mail Protection Netscape Cert Type: SSL CA, S/MIME CA Signature Algorithm: sha256WithRSAEncryption 74:5d:7d:b1:85:9d:a9:35:cb:f0:89:66:cc:f2:5e:fa:d4:be: c9:f6:a9:96:b4:a6:50:37:03:19:1b:db:d2:6f:43:75:91:3e: --------------------(中略)---------------- 04:b1:6f:b9:f1:7a:01:10:4c:b8:7c:98:cc:ba:b4:65:a1:64: 56:b3:07:15:92:67:8e:8c:3b:07:09:23:05:08:8d:73:1c:26: e5:59:71:ce:9a:e8:4e:e8:d1:ef:8d:bd:c1:88:f1:cf:67:5d: 2c:50:24:8c:15:8f:9c:9d:e0:19:61:18:dc:4b:20:1b:57:74: b6:6f:67:ee -----BEGIN CERTIFICATE----- MIIEVDCCAzygAwIBAgIUCJDcIsW/zFZ3etZkCRkPvzQDHRswDQYJKoZIhvcNAQEL BQAwgYIxCzAJBgNVBAYTAkpQMQ4wDAYDVQQIDAVUb2t5bzEaMBgGA1UECgwRRUFS VEggUExBTkVUIEluYy4xHTAbBgNVBAMMFEVBUlRIIFBMQU5FVCBSb290IENBMSgw --------------------(中略)---------------- DzMJAbEoP4lHY2T+T4tn6SOkc/yJfr9vyizxJEZyBSKOl0q2hROrI5Df2ll1jepw x3noT51iHglNFgTixSWRFVztG3aDdbNe1Bi6qASxb7nxegEQTLh8mMy6tGWhZFaz BxWSZ46MOwcJIwUIjXMcJuVZcc6a6E7o0e+NvcGI8c9nXSxQJIwVj5yd4BlhGNxL IBtXdLZvZ+4= -----END CERTIFICATE-----
少し長くなったので、続きはまた次の記事に書きます。