原文链接:https://blog.csdn.net/weixin_41581158/article/details/80916467
背景
项目开发完成后一般会进行高危漏洞检测,检测时出现
步骤
整体步骤
第一步:为服务器生成证书
keytool -genkey -v -alias tomcat -keyalg RSA -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore -validity 36500
第二步:为客户端生成证书
keytool -genkey -v -alias mykey -keyalg RSA -storetype PKCS12 -keystore D:\apache-tomcat-8.5.35\keystores\mykey.p12
第三步:让服务器信任客户端证书
keytool -export -alias mykey -keystore D:\apache-tomcat-8.5.35\keystores\mykey.p12 -storetype PKCS12 -storepass aaa111 -rfc -file D:\apache-tomcat-8.5.35\keystores\mykey.cer
keytool -import -v -file D:\apache-tomcat-8.5.35\keystores\mykey.cer -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore
第四步:验证客户端证书是否已经加入到服务器端的受信任证书中了
keytool -list -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore
第五步:让客户端信任服务器证书
keytool -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore -export -alias mykey -file D:\apache-tomcat-8.5.35\keystores\tomcat.cer
第六步:配置Tomcat服务器
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
SSLEnabled="true" maxThreads="150" scheme="https"
secure="true" clientAuth="true" sslProtocol="TLS"
keystoreFile="D:\\apache-tomcat-8.5.35\\keystores\\tomcat.keystore" keystorePass="aaa111"
truststoreFile="D:\\apache-tomcat-8.5.35\\keystores\\tomcat.keystore" truststorePass="aaa111" />
第一步:为服务器生成证书
keytool -genkey -v -alias tomcat -keyalg RSA -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore -validity 36500
参数说明:
tomcat:证书的名称。
D:\apache-tomcat-8.5.35\keystores\tomcat.keystore:含义是将证书文件的保存路径;
validity 36500:含义是证书有效期,36500表示100年,默认值是90天;
此时已经生成了这个文件
第二步:为客户端生成证书
keytool -genkey -v -alias mykey -keyalg RSA -storetype PKCS12 -keystore D:\apache-tomcat-8.5.35\keystores\mykey.p12
此时已经生成了客户端证书
双击证书,将证书导入浏览器中
第三步:让服务器信任客户端证书
3.1 由于.p12文件无法导入到keystore文件中,需要转换成.cre文件
keytool -export -alias mykey -keystore D:\apache-tomcat-8.5.35\keystores\mykey.p12 -storetype PKCS12 -storepass aaa111 -rfc -file D:\apache-tomcat-8.5.35\keystores\mykey.cer
3.2 把客户端凭证导入到服务端凭证中
keytool -import -v -file D:\apache-tomcat-8.5.35\keystores\mykey.cer -keystore D:\apache-tomcat-8.5.35\keystores
第四步:验证客户端证书是否已经加入到服务器端的受信任证书中了
keytool -list -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore
第五步:让客户端信任服务器证书
keytool -keystore D:\apache-tomcat-8.5.35\keystores\tomcat.keystore -export -alias mykey -file D:\apache-tomcat-8.5.35\keystores\tomcat.cer
此时会生成一个新文件,双击操作
把证书安装后会自动导入到浏览器中
第六步:配置Tomcat服务器
找到tomcat配置文件:D:\apache-tomcat-8.5.35\conf\server.xml
找到port=“8443” 的配置节点,把以下内容加入重启tomcat访问
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
SSLEnabled="true"
maxThreads="150"
scheme="https"
secure="true"
<!--此处可设置是否进行双向验证,如果只是在服务器端验证就设置false -->
clientAuth="false"
sslProtocol="TLS"
keystoreFile="D:\\apache-tomcat-8.5.35\\keystores\\tomcat.keystore"
keystorePass="aaa111"
truststoreFile="D:\\apache-tomcat-8.5.35\\keystores\\tomcat.keystore"
truststorePass="aaa111" />