我有一個內網伺服器,需要安裝 SSL。
這是openssl.cnf
[ req ]
default_md = sha256
distinguished_name = req_distinguished_name
attributes = req_attributes
req_extensions = req_ext
#prompt = no
[ req_distinguished_name ]
countryName = US
countryName_min = 2
countryName_max = 2
stateOrProvinceName = CHICAGO
localityName = CHICAGO
0.organizationName = MY COMPANY
organizationalUnitName = IOS DEVELOPMENT
commonName = server2.myserver.local
commonName_max = 64
emailAddress = [email protected]
emailAddress_max = 64
[ req_attributes ]
challengePassword = password
challengePassword_min = 4
challengePassword_max = 20
[ req_ext ]
subjectAltName = @alt_names
extendedKeyUsage = serverAuth
[alt_names]
DNS.1 = server2.myserver.local
DNS.2 = myserver.local
這是我用來創建它的命令。
產生根 CA 金鑰
openssl genrsa -des3 -out rootCA.key 4096
2.這是產生根CA憑證
openssl req \
-x509 -new -nodes \
-key rootCA.key -sha256 \
-days 825 \
-out rootCA.crt \
-subj /CN=server2.myserver.local \
-reqexts SAN \
-extensions SAN \
-config <(cat ./openssl.cnf \
<(printf '[SAN]\nsubjectAltName=DNS:server2.myserver.local')) \
-extensions 'req_ext'
產生憑證金鑰
openssl genrsa -out mydomain.com.key 4096
產生證書
openssl req -new -sha256 -key mydomain.com.key \ -subj "/C=US/ST=CA/O=MyOrg, Inc./CN=server2.myserver.local" \ -reqexts SAN \ -config <(cat ./openssl.cnf \ <(printf "\n[SAN]\nsubjectAltName=DNS:server2.myserver.local,DNS:myserver.local")) \ -out mydomain.com.csr
將 CA 憑證轉換為 p12
openssl pkcs12 -export -out ca.p12 -inkey rootCA.key -in rootCA.crt
將證書轉換為 p12
openssl pkcs12 -export -out certificate.p12 -inkey mydomain.com.key -in mydomain.com.crt
然後我在 IIS 伺服器和設備上安裝ca.p12
和。certificate.p12
當我嘗試訪問時server2.myserver.local
我明白了
以聖人證書的名義我該如何做到這一點?
答案1
我想說你的根CA憑證是完全錯誤的。 CA 憑證與最終主機 TLS 憑證有很大不同 - 您無法對兩者使用相同的設定。
不要將伺服器的網域放在主題中 - 這是沒有用的。如果是 CA,則應該有
CN=My internal CA
類似的內容。新增
basicConstraints
擴展名。必須說該憑證是 CA。添加正確的
keyUsage
.您需要有“keyCertSign”和(只是為了完整性)“cRLSign”。不要添加
subjectAltName
.此證書適用於頒發機構/頒發者,而不適用於伺服器!不要添加
extendedKeyUsage
.它有時用於限制 CA 可以頒發的證書,但最好不要這麼複雜地開始。添加 是個好主意
subjectKeyIdentifier
,以防您以後最終擁有多個具有相同主題 DN 的內部 CA。 (通常 CA DN 必須是唯一的,但擁有 SKI/AKI 可以緩解這一點。)
所以你應該有一個看起來更像這樣的“CA”設定檔(並停止透過命令列添加 SAN 和其他內容 - 這就是配置的用途):
[ req ]
default_md = sha256
distinguished_name = req_distinguished_name
req_extensions = req_ext
[ req_dn ]
countryName = US
stateOrProvinceName = Chicago
organizationName = Company Name
organizationalUnitName = iOS development
commonName = Internal development CA
[ req_ext ]
basicConstraints = critical, CA:TRUE
keyUsage = keyCertSign, cRLSign
subjectKeyIdentifier = hash
而最終實體憑證(TLS 伺服器)應具有以下副檔名:
...
[ req_ext ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid, issuer
subjectAltName = DNS:server2.myserver.local
然後我在 IIS 伺服器和裝置上安裝 ca.p12 和certificate.p12。
不要在您的裝置上安裝 CA 的私鑰!也不要將其安裝在伺服器上。你應該安裝僅有的CA 憑證rootCA.crt
(公共部分),僅此而已。
我的最終建議:不要浪費時間嘗試使用原始openssl
.而是使用簡易RSA(OpenVPN 附帶的),或使用XCA(圖形 Linux 應用程式),或使用其中之一可能有幾十個已經編寫和測試的程式。