Tomcat8 Https配置

前言:最近有客户使用burp suite扫描出了一些安全问题,涉及到tomcat的配置一脸懵逼,搜到的文章也不太靠谱,记录此文希望对大家有帮助。

 

一、确认Tomcat版本

  本文针对tomcat8,其他版本不保证是否可行,需要先确认版本是否OK。

  cmd进入tomcat/bin,执行命令查看版本:catalina version,如下图所示版本号为8.5.23

 

二、配置https

1、生成密钥

  cmd中输入(其中您的名字与姓氏是什么?需要填入主机域名,如本机测试可以写localhost):

keytool -genkey -alias tomcat -keyalg RSA -keystore D:\keystore

输入密钥库口令:cnblogs
再次输入新口令:cnblogs
您的名字与姓氏是什么?
  [Unknown]:  cnblogs
您的组织单位名称是什么?
  [Unknown]:  cnblogs
您的组织名称是什么?
  [Unknown]:  cnblogs
您所在的城市或区域名称是什么?
  [Unknown]:  beijing
您所在的省/市/自治区名称是什么?
  [Unknown]:  beijing
该单位的双字母国家/地区代码是什么?
  [Unknown]:  cn
CN=cnblogs, OU=cnblogs, O=cnblogs, L=beijing, ST=beijing, C=cn是否正确?
  [否]:  y

输入 <tomcat> 的密钥口令
        (如果和密钥库口令相同, 按回车):

 

2、将生成的keystore放进tomcat的根目录

3、修改tomcat/conf/server.xml文件:

  搜索到“8443”,找到如下内容:

  修改如下,keystorePass为第一步输入的密钥口令

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
       maxThreads="150" scheme="https" secure="true"
       clientAuth="false" sslProtocol="TLS" 
       keystoreFile="D:\cnblogs\tomcat\keystore"
       keystorePass="cnblogs" /> 

 

4、修改tomcat/webapps/projectName/WEB-INF/web.xml,在标签web-app中添加如下内容:

    <security-constraint>
        <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>

 

 

三、安全配置

  如上配置后,用burpsuite扫描会报两个漏洞:

1、SSL cookie without secure flag set

  修改tomcat/conf/web.xml文件,在标签session-config下添加:

    <session-config>
        <session-timeout>0</session-timeout>
        <cookie-config>
            <http-only>true</http-only>
            <secure>true</secure>
        </cookie-config>
    </session-config>

 

2、Strict transport security not enforced

  修改tomcat/conf/web.xml文件,在标签web-app中添加:

    <filter>
        <filter-name>httpHeaderSecurity</filter-name>
        <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
        <init-param>
            <param-name>hstsEnabled</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>hstsMaxAgeSeconds</param-name>
            <param-value>31536000</param-value>
        </init-param>
        <init-param>
            <param-name>antiClickJackingOption</param-name>
            <param-value>SAMEORIGIN</param-value>
        </init-param>
        <async-supported>true</async-supported>
    </filter>
    
    <filter-mapping>
        <filter-name>httpHeaderSecurity</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

 

3、配置check,重启后,访问之前的http端口,可以看到返回302重定向从8085端口到8443端口(HSTS要求强制转换为https),且Set-Cookie中有了Secure和HttpOnly

  重定向后https请求可以看到有了Strict-Transport-Security消息头

转载于:https://www.cnblogs.com/andyshu/p/https_config.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值