制作自簽名證書(無用戶名密碼保護)
openssl req -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt -days 3650 -subj "http://C=CN\ST=Chongqing\L=Chongqing\O=org\OU=OrgUnit\CN=localhost\emailAddress=admin@localhost.com"
制作自簽名證書(有用戶名密碼保護)
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl rsa -passin pass:x -in server.pass.key -out server.key
openssl req -new -key server.key -out server.csr -subj "http://C=CN\ST=Chongqing\L=Chongqing\O=org\OU=OrgUnit\CN=localhost\emailAddress=admin@localhost.com"
openssl x509 -req -sha256 -days 3650 -in server.csr -signkey server.key -out server.crt
制作CA根證書并為第三方頒發證書
openssl genrsa -out ca.key 2048
openssl req -new -x509 -nodes -days 3650 -key ca.key -out ca.crt -subj "http://C=CN\ST=Chongqing\L=Chongqing\O=org\OU=OrgUnit\CN=ca.example.com\emailAddress=admin@ca.com"
openssl req -newkey rsa:2048 -days 3650 -nodes -keyout server.key -out server.csr -subj "http://C=CN\ST=Chongqing\L=Chongqing\O=org\OU=OrgUnit\CN=server.example.com\emailAddress=admin@server.com"
openssl x509 -req -in server.csr -days 3650 -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
openssl req -newkey rsa:2048 -days 3650 -nodes -keyout client.key -out client.csr -subj "http://C=CN\ST=Chongqing\L=Chongqing\O=org\OU=OrgUnit\CN=client.example.com\emailAddress=admin@client.com"
openssl x509 -req -in client.csr -days 3650 -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
#頒發泛域名證書
openssl req -newkey rsa:2048 -days 3650 -nodes -keyout example.key -out example.csr -subj /C=CN/ST=Chongqing/L=Chongqing/O=org/OU=OrgUnit/CN=*.example.com/emailAddress=admin@example.com
cat << EOF > v3.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.example.com
DNS.2 = example.com
IP.1 = 192.168.1.100
IP.2 = 192.168.1.200
EOF
openssl x509 -req -in example.csr -days 3650 -CA ca.crt -CAkey ca.key -set_serial 100 -out example.crt -extfile v3.ext
#轉p12格式
openssl pkcs12 -chain -CAfile ca.crt -export -in example.crt -inkey example.key -out example.p12 -name example.com
獲取服務器上的證書
openssl s_client -servername baidu.com -connect baidu.com:443 \
< /dev/null 2>/dev/null \
| openssl x509 -outform pem \
> baidu.com.crt
ubuntu 上安裝證書
sudo su -
cp baidu.com.crt /usr/local/share/ca-certificates/baidu.com.crt
update-ca-certificates
centos 上安裝證書
cp baidu.com.crt /etc/pki/ca-trust/source/anchors/baidu.com.crt
update-ca-trust
java 中安裝證書
cd $JAVA_HOME
#導入證書
./jre/bin/keytool -keystore jre/lib/security/cacerts -importcert -alias baidu.com -file baidu.com.crt -storepass changeit
#查看證書
./jre/bin/keytool -list -keystore jre/lib/security/cacerts -storepass changeit | grep baidu.com
./jre/bin/keytool -keystore jre/lib/security/cacerts -delete -alias baidu.com
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。