jetty配置http2、https以及增强ssl


jetty支持http2从jetty9.3版本开始。

1、下载jetty并解压到目录

jetty官网:https://www.eclipse.org/jetty/download.html
解压到目录,如/data/jetty443

[root@test data]# cd jetty443/
[root@test jetty443]# ll
total 736
drwxr-xr-x.  2 root root   4096 Aug 31 11:05 bin
drwxr-xr-x.  7 root root   4096 Aug 31 11:06 demo-base
drwxr-xr-x.  5 root root   4096 Aug 31 15:01 etc
-rw-r--r--.  1 root root    135 Sep  3 14:15 jetty443.state
drwxr-xr-x. 15 root root   4096 Aug 31 11:25 lib
-rw-r--r--.  1 root root  30012 Aug 31 11:05 license-eplv10-aslv20.html
drwxr-xr-x.  3 root root   4096 Aug 31 11:09 logs
drwxr-xr-x. 22 root root   4096 Aug 31 11:06 modules
-rw-r--r--.  1 root root   6262 Aug 31 11:05 notice.html
-rw-r--r--.  1 root root   1637 Aug 31 11:05 README.TXT
drwxr-xr-x.  2 root root   4096 Aug 31 11:06 resources
drwxr-xr-x.  2 root root   4096 Sep  3 13:57 start.d
-rw-r--r--.  1 root root 147476 Aug 31 11:05 start.jar
-rw-r--r--.  1 root root 504664 Aug 31 11:05 VERSION.txt
drwxr-xr-x.  2 root root   4096 Aug 31 11:09 webapps
[root@test jetty443]# 


2、配置激活jetty模块
进入jetty目录/data/jetty443,执行命令:
 java -jar start.jar --add-to-startd=http,https,http2,http2c,deploy,alpn
激活如下模块:
[root@test jetty443]# ll start.d/
total 28
-rw-r--r--. 1 root root  477 Sep  3 13:57 alpn.ini
-rw-r--r--. 1 root root  427 Aug 31 15:10 http2c.ini
-rw-r--r--. 1 root root  528 Aug 31 15:10 http2.ini
-rw-r--r--. 1 root root  175 Aug 31 15:10 https.ini
-rw-r--r--. 1 root root 3122 Aug 31 15:10 ssl.ini
-rw-r--r--. 1 root root 5371 Aug 31 15:10 start.ini
[root@test jetty443]# 
 

3、修改端口
http端口:start.ini文件jetty.http.port=80
https端口:ssl.ini文件jetty.ssl.port=443
获取修改文件jetty-http.xml和jetty-ssl.xml文件的端口默认值。

4、配置证书
一般证书机构生成的证书有crt、key、pem、pfx几个文件。
如果是个人测试则直接用openssl或keytool正常jetty配置的keystore证书。

如果没有pfx证书,则通过如下命令生成:
openssl pkcs12 -export -out test.pfx -inkey test.key -in test.pem

pfx证书转成keystore:
keytool -importkeystore -srckeystore test.pfx -destkeystore jetty.jks -srcstoretype PKCS12 -deststoretype JKS
执行该命令是需要输入证书密码。

5、配置ssl
打开jetty-ssl-context.xml,修改KeyStorePath、TrustStorePath的证书路径:
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" deprecated="jetty.keystore" default="etc/cert/jetty.jks"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" deprecated="jetty.keymanager.password" default="OBF:19iy19j019j219j419j619j8"/></Set>

修改KeyStorePassword、KeyManagerPassword、 TrustStorePassword密码为证书的密码。 
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" deprecated="jetty.keystore.password" default="OBF:19iy19j019j219j419j619j8"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" deprecated="jetty.keymanager.password" default="OBF:19iy19j019j219j419j619j8"/></Set>
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" deprecated="jetty.truststore.password" default="OBF:19iy19j019j219j419j619j8"/></Set>
  
此处default值可直接输入证书的密码,如123456,也可以使用OBF格式的keystore密码,转换命令:
java -cp jetty-all-9.0.5.v20130815.jar org.eclipse.jetty.util.security.Password yoursslpassword

完成以上配置后可启动jetty,https及http2正常配置,可看到启动日志:
2018-09-03 08:01:22.899:INFO:oejs.AbstractConnector:main: Started ServerConnector@f451970{SSL,[ssl, alpn, h2, http/1.1]}{0.0.0.0:443}
2018-09-03 08:01:22.900:INFO:oejs.AbstractConnector:main: Started ServerConnector@4a7c8cb7{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:80}
表示配置成功,通过chrome浏览器访问url,右键-检查(或者 更多工具-开发者工具)查看network页面,可看到协议。

6、增强ssl
通过以上配置后如果进行ssl server test(https://www.ssllabs.com/ssltest/analyze.html),会提示:
1、This server supports weak Diffie-Hellman (DH) key exchange parameters
2、The server does not support Forward Secrecy with the reference browsers. 
导致不能达到A的评分。
主要原因是存在比较弱的加密算法引起。
解决办法,指定采用保密性更好的ECDHE系列算法:
jetty-ssl-context.xml增加如下配置:
  <!-- Eliminate Old / Insecure / Anonymous Ciphers -->
  <Call name="addExcludeCipherSuites">
    <Arg>
      <Array type="String">
        <Item>.*NULL.*</Item>
        <Item>.*RC4.*</Item>
        <Item>.*MD5.*</Item>
        <Item>.*DES.*</Item>
        <Item>.*DSS.*</Item>
      </Array>
    </Arg>
  </Call>

  <!-- Enable Forward Secrecy Ciphers.
       Note: this replaces the default Include Cipher list -->
  <Set name="IncludeCipherSuites">
    <Array type="String">
      <Item>TLS_ECDHE.*</Item>
    </Array>
  </Set>


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值