用openssl為WEB服務器生成證書(自簽名CA證書,服務器證書)
用openssl為WEB服務器生成證書(自簽名CA證書,服務器證書)
來源: https://www.cnblogs.com/osnosn/p/10608455.html 來自osnosn的博客
寫於: 2019-03-28.
- 不想用自簽名證書,想在網上申請一個免費服務器證書,見這篇: 去freessl.org申請免費ssl服務器證書
以下內容是用自簽名證書,為網站生成服務器證書。
照著這一篇"用openssl為EAP-TLS生成證書(CA證書,服務器證書,用戶證書)",建立所有文件。
其中openssl.cnf 按以下新增幾行。用於匹配你的服務器域名,或者是IP。
openssl.cnf
#openssl.cnf [ ca ] default_ca = hostapd [ hostapd ] dir = . serial = $dir/0serial database = $dir/2indexdb.txt new_certs_dir = $dir/3certs_new certificate = $dir/ca_cert.pem private_key = $dir/ca_key.pem RANDFILE = /dev/urandom default_bits = 4096 default_days = 36500 default_crl_days = 36500 default_md = sha512 #unique_subject = no policy = policy_anything [ policy_anything ] countryName = optional stateOrProvinceName = optional localityName = optional organizationName = supplied organizationalUnitName = optional commonName = supplied emailAddress = optional [ req ] distinguished_name = req_distinguished_name string_mask = utf8only [ req_distinguished_name ] [ v3_ca ] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer basicConstraints = critical,CA:true certificatePolicies=ia5org,@pl_section [ server_cert ] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer basicConstraints = CA:false extendedKeyUsage = serverAuth,msSGC,nsSGC certificatePolicies=ia5org,@pl_section subjectAltName = @dns_names <---新增 [ dns_names ] <---新增 DNS.1 = my.domain.com <---新增 DNS.2 = your.domain.net <---新增 IP.1 = 1.2.3.4 <---新增 IP.2 = 5.6.7.8 <---新增 [ user_cert ] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer basicConstraints = CA:false #subjectAltName = email:copy extendedKeyUsage = clientAuth,emailProtection,timeStamping certificatePolicies=ia5org,@pl_section [ pl_section ] policyIdentifier = "X509v3 Any Policy" # 頒發者說明的鏈接. windows中,要導入信任之後才生效. CPS.1 = https://your.web.com/cps/readme.html userNotice.1=@pl_notice [ pl_notice ] # 頒發者說明,Issuer statment. 不支持utf8中文,因為ia5org。 explicitText="Read deail at https://your.web.com/xxx.html"
userNotice.1 的文字說明,只能是英文,中文會亂碼。
文字說明,無論此證書是否被系統信任,查看證書時都會出現在"頒發者說明"中(Issuer Statement)。
CPS.1 的鏈接。系統未信任此證書時,是不顯示的。信任後,才會出現在"頒發者說明"中(Issuer Statement)。
CPS.1= 可以是 "http://" 也可以是 "https://"。
只有一個域名,就只寫 DNS.1=
,其他的不要了。
有多個域名,配置中就寫 DNS.1=
, DNS.2=
, DNS.3=
... DNS.9=
可以寫通配符域名,
DNS.1=*.mydom.org
,將匹配所有以
.mydom.org
的所有域名。如: abc.mydom.org
, www.mydom.org
...但不匹配
mydom.org
所以通配符域名一般寫兩行
DNS.1=mydom.org
, DNS.2=*.mydom.org
使用方法,只使用這兩個命令:
new-ca.sh
創建自簽名root證書。
new-server.sh
創建web用的服務器證書。
這三個文件,就是用於配置web服務器需要的證書。
ca_cert.pem
, server_cert.pem
, server_key.pem
如需要,參考以下證書格式轉換的指令:
把 pem 轉為 der 格式,(證書,密鑰)
openssl x509 -outform der -in server_cert.pem -out server.cer
服務器證書。
openssl rsa -in server_key.pem -outform der -out server_key.cer
服務器密鑰。
把 pem 轉為 P12 格式,(證書,密鑰)
openssl pkcs12 -export -out ./server.p12 -inkey server_key.pem -in server_cert.pem -certfile ca_cert.pem
把 pem 轉 pkcs#7 格式,(證書)
openssl crl2pkcs7 -nocrl -certfile server_cert.pem -out server.p7b
不想用自簽名證書,那去網上申請一個免費服務器證書吧: 去freessl.org申請免費ssl服務器證書
轉載請註明來源。
來源: https://www.cnblogs.com/osnosn/p/10608455.html 來自osnosn的博客
--------- end ---------
用openssl為WEB服務器生成證書(自簽名CA證書,服務器證書)