概念介绍:
- JSSE(Java Secure Socket Extension)。java web应用利用JSSE实现SSL/TSL安全协议
- keystore、truststore:JSSE使用keystore与truststore文件来提供客户端和服务器之间的安全数据传输
- keytool:jdk自带的可以用来创建自签名证书与keystore文件的工具
自签名步骤:
- 生成一个含有私钥的keystore文件:
keytool -genkeypair -alias andy_keystore_ip -keyalg RSA -validity 36500 -keystore andy_keystore_ip.jks -ext san=ip:172.22.144.16
1步骤操作后,会生成andy_keystore_ip.jks文件
-
利用keystore文件导出凭证文件
keytool -export -alias andy_keystore_ip -keystore andy_keystore_ip.jks -rfc -file andy_cer_ip.cer
-
将证书文件导入到truststore文件中
keytool -import -alias andy_truststore_ip -file andy_cer_ip.cer -keystore andy_truststore_ip.jks
-
将安全证书andy_cer_ip.cer复制web服务运行的jdk安装目录的jre/lib/security目录中:
-
将安全证书导入到jdk的keystore cacerts文件中,cacerts文件默认密码changeit
keytool -import -alias andy_keystore_ip -keystore cacerts -file andy_cer_ip.cer
-
重启web服务即可