Tomcat配置单向SSL证书并强https请求
一、背景
window环境
进行安全漏洞扫描时:发送敏感信息时,始终使用 SSL 和 POST(主体)参数。
二、步骤
1、生成key
打开dos,在dos下输入一下命令
keytool -genkey -v -alias tomcat -keyalg RSA -keystore D:\tomcat\keystores\tomcat.keystore -validity 36500
2、在tomcat下开启https并配置key
打开你自己的tomcat下的 D:\tomcat\conf 下的server.xml 文件
找到<Connector port=“8443” 并按照下面的方法进行设置,一般这个端口是被注释调用的,只需要把注释放开并作修改就可以了
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="D:\\tomcat\\keystores\\tomcat.keystore" keystorePass="aaa111"/>
此时访问:https://localhost:8443/ 时会出现,表示https一配置好,但是当我们访问http://localhost:8089/ 时还是可以正常访问,这样就绕过了ssl的验证,还没有解决开头的漏洞问题,需要强制将http请求重定向到https请求才可以。
3、强制使用https访问
打开你自己的tomcat下的 D:\tomcat\conf 下的web.xml 文件,在</welcome-file-list>后面
加上以下内容
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
此时访问:http://localhost:8089/ 就会从定向到 https://localhost:8443/