tomcat/nginx及阿里云slb做双向认证

tomcat

1. 生成服务端证书

keytool -genkey -v -alias tomcat1 -keyalg RSA -keystore tomcat1.keystore -dname "CN=xxx.com,OU=xxx,O=xxx,L=xxx,ST=xxx,C=CN" -validity 3650 -storepass xxxxxxxxx -keypass xxxxxxx

2. 生成客户端证书

keytool -genkey -v -alias client -keyalg RSA -storetype PKCS12 -keystore client.p12 -dname "CN=xxx.com,OU=xxx,O=xxx,L=xxx,ST=xxx,C=CN" -validity 3650 -storepass xxxxxxx -keypass xxxxxxx

3. 客户端p12文件导出cer文件

keytool -export -alias client -keystore client.p12 -storetype PKCS12 -storepass xxxxxxx -rfc -file 
 client.cer

4. 将CER文件导入到服务器的证书库

keytool -import -v -file client.cer -keystore tomcat1.keystore

5. tomcat server.xml配置

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
           maxThreads="150" scheme="https" secure="true"
           clientAuth="true" sslProtocol="TLS"
           keystoreFile="tomcat1.keystore" keystorePass="xxxxxx"
           truststoreFile="tomcat1.keystore" truststorePass="xxxxxx" />

nginx配置网上一大堆,不贴了

阿里云SLB配置双向,slb的证书需要pem格式,所以需要将格式转换,在上面的基础上,继续以下操作

6. 让客户端信任服务器证书

keytool -export -alias tomcat1 -keystore tomcat1.keystore -file tomcat1.cer -storepass xxxxxx

7. keystore转p12

keytool -importkeystore -srckeystore tomcat1.keystore -destkeystore tomcat1.keystore.p12 -srcstoretype JKS -deststoretype PKCS12

8. p12转pem, 导出私钥

openssl pkcs12 -nocerts -nodes -in tomcat1.keystore.p12 -out tomcat1-private-key.pem

9. 导出cer证书

keytool -export -alias tomcat1 -file tomcat1-pub.cer -keystore tomcat1.keystore -storepass xxxxx

10. cer证书转pem格式

openssl x509 -in tomcat1-pub.cer -inform DER -out tomcat1-pub.pem -outform PEM

11. 客户端证书p12转pem即slb ca证书

openssl pkcs12 -in clinet.p12 -out client.pem -nodes

至此slb需要的服务器证书 证书在tomcat1-pub.per文件中,私钥在tomcat1-private-key.pem文件中

ca证书在client.pem文件中

转载于:https://my.oschina.net/illone/blog/1551726

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值