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文件中