Linux中快捷生成自签名ssl证书_113资讯网

一、生成CA私钥

mkdir ca
cd ca
#创建私钥 (建议设置密码)
openssl genrsa -des3 -out myCA.key 2048
  • 生成CA证书
# 20 年有效期
openssl req -x509 -new -nodes -key myCA.key -sha256 -days 7300 -out myCA.crt

把此证书导入需要部署的PC中即可,以后用此CA签署的证书都可以使用 查看证书信息命令 openssl x509 -in myCA.crt -noout -text 二、创建ssl证书私钥

cd ..
# 此文件夹存放待签名的证书
mkdir certs
cd certs
openssl genrsa -out localhost.key 2048
  • 创建ssl证书CSR
openssl req -new -key localhost.key -out localhost.csr
  • 创建域名附加配置文件cert.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
IP.2 = 127.0.0.1
DNS.3 = test.com
DNS.4 = *.test.com

三、使用CA签署ssl证书

# ssl证书有效期10年,此步骤需要输入CA私钥的密码
openssl x509 -req -in localhost.csr -out localhost.crt -days 3650 \
  -CAcreateserial -CA ../ca/myCA.crt -CAkey ../ca/myCA.key \
  -CAserial serial -extfile cert.ext

四、查看签署的证书信息

openssl x509 -in localhost.crt -noout -text
  • 使用CA验证一下证书是否通过
root@ubuntu:/home/test/certs# openssl verify -CAfile ../ca/myCA.crt localhost.crt
localhost.crt: OK

五、 把服务端代码转换浏览器可以识别的PCS12格式,密码使用上面输入的密码

openssl pkcs12 -export -in localhost.crt -inkey localhost.key -out server.p12

六、使用jetty中的PKCS12Import工具类完成转换,密码同上

wget https://biteeniu.github.io/files/jetty-6.1.26.jar
java -cp jetty-6.1.26.jar org.mortbay.jetty.security.PKCS12Import server.p12 server.jks

七、使用下面命令查看jks文件中包含的证书信息

keytool -v -list -keystore server.jks


文章原文:https://www.113p.cn/266.html(113资讯网)

猜你喜欢

转载自www.cnblogs.com/113p/p/13209614.html