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/
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值