————————————————
https://blog.csdn.net/qq_17298387/article/details/53232341
https://www.jianshu.com/p/1daae319d5fc 【使用 OpenSSL 命令行管理證書】node
cp /etc/pki/tls/openssl.cnf ./
sed -i 's|/etc/pki|.|g' openssl.cnf
sed -i '/req_extensions/s/^# //g' openssl.cnfgit
#use for openssl ca command
mkdir -p CA/{certs,crl,newcerts,private}
touch CA/index.txt
echo 00 > CA/serial算法
1. 生成ca.key並自簽署生成根證書.net
openssl genrsa -des3 -out ca.key 2048
去掉中間的-des3能夠生成不輸密碼的密鑰. 這樣是生成rsa私鑰,des3算法,openssl格式,2048位強度。server.key是密鑰文件名。爲了生成這樣的密鑰,須要一個至少四位的密碼。命令行
openssl req \
-sha256 -new -x509 -days 3650 \
-key ca.key -out ca.crt \
-config openssl.cnf \
-subj "/C=CN/ST=GD/L=ShenZhen/O=ISPC Co.,LTD/OU=elite/CN=ca.ispc.com/emailAddress=macj@ispc.com"orm
2. 生成ServerXX0 key和證書籤名請求
openssl genrsa -out serverXX0.key 2048
openssl req \
-new -sha256 \
-key serverXX0.key -out serverXX0.csr \
-config openssl.cnf \
-subj "/C=CN/ST=GD/L=ShenZhen/O=ISPC Co.,LTD/OU=elite/CN=agee.ispc.com/emailAddress=macj@ispc.com"server
3. 查看簽名請求文件信息
openssl req -text -in serverXX0.csr
檢查 Signature Algorithm 是否是sha256WithRSAEncryptioblog
4. 使用自簽署的CA,簽署serverXX0.scr
4.1 使用ca僞命令簽發證書
openssl ca \
-cert ca.crt -keyfile ca.key \
-md sha256 -days 3650 -extensions v3_req -config openssl.cnf \
-in serverXX0.csr -out serverXX0.crt
ip
4.2 使用x509僞命令簽發證書
openssl x509 -req \
-CA ca.crt -CAkey ca.key \
-sha256 -days 3650 -CAcreateserial -extensions v3_req -extfile openssl.cnf \
-in serverXX0.csr -out serverXX0.crt
ssl
5.查看證書
openssl x509 -text -in serverXX0.crt
6. 轉換格式
6.1 轉換成IIS可以使用的pfx格式
openssl pkcs12 -export -out serverXX0.pfx -inkey serverXX0.key -in serverXX0.crt
6.2 轉換成pem格式
openssl rsa -in serverXX0.key -out serverXX0-np.key
cat serverXX0-np.key serverXX0.crt > serverXX0.pem
6.3 轉換成p12格式
openssl pkcs12 -export -out tsa.p12 -inkey tsa.key -in tsa.crt -chain -CAfile tsaroot.crt
# 從 PEM 轉換到 DER:
$ openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
# 從 DER 轉換到 PEM:
$ openssl x509 -in cert.der -inform DER -out cert.pem -outform PEM
7. 定義openssl.cnf subjectAltName,增長下行,可實現證書給多個域名使用
7.1 取消req_extentions = v3_req這一行的註釋
sed -i '/req_extensions/s/^# //g' openssl.cnf
7.2 在[ v3_req ]增長配置
subjectAltName = @alt_names
7.3 添加alt_names配置信息
[ alt_names ]
DNS.1 = *.ecmms.ispcmj
DNS.2 = *.ispcmj.com
DNS.3 = 928.ecmms.ispcmj
8. 建立crt格式的自簽名證書
openssl req \
-sha256 -newkey rsa:2048 -nodes \
-keyout agsenterprise.key -out agsenterprise.crt \
-x509 -days 3650 \
-config openssl.cnf -extensions v3_req \
-subj "/C=CN/ST=GD/L=ShenZhen/O=ISPC Co.,LTD/OU=elite/CN=928.ecmms.ispcmj/emailAddress=macj@ispc.com"
-----------agee.ispcmj.com
#1. 配置openssl.cnf文件
cp /etc/pki/tls/openssl.cnf openssl.cnf
cat <<EOF>> openssl.cnf
[ v3_req2 ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage=serverAuth,clientAuth
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = 930.ecmms.ispcmj
DNS.2 = *.ispcmj.com
EOF
#2. 生成ca.key並自簽署生成根證書
openssl genrsa -out ca.key 4096
openssl req \
-sha512 -new -x509 -days 7300 \
-key ca.key -out ca.crt \
-config openssl.cnf \
-subj "/C=CN/ST=GD/L=ShenZhen/O=ispcmj Co.,LTD/OU=ispcmj/CN=ca.ispc/emailAddress=mac.j.zhang@ispcmj.com"
#3. 生成ServerXX0 key和證書籤名請求
openssl genrsa -out agee.ispcmj.com.key 2048
openssl req \
-new -sha256 \
-key agee.ispcmj.com.key -out agee.ispcmj.com.csr \
-config openssl.cnf \
-subj "/C=CN/ST=GD/L=ShenZhen/O=ispcmj Co.,LTD/OU=ispcmj/CN=agee.ispcmj.com/emailAddress=cmm-lhit-sa@ispcmj.com"
#4. 使用自簽署的CA,簽署serverXX0.scr 使用x509僞命令簽發證書 openssl x509 -req \ -CA ca.crt -CAkey ca.key \ -sha256 -days 3650 -CAcreateserial -extensions v3_req2 -extfile openssl.cnf \ -in agee.ispcmj.com.csr -out agee.ispcmj.com.crt