我有一个类似的用例,它使Tomcat 7严格只使用TLSv1.2,而不回退到TLSv1.1或SSLv3等早期的SSL协议。
我正在使用:C:\ apache-tomcat-7.0.64-64bit和C:\ Java64 \ jdk1.8.0_60。
按照以下说明进行操作:https : //tomcat.apache.org/tomcat-7.0-doc/security-howto.html。Tomcat相对容易设置SSL支持。
从许多参考资料中,我测试了许多组合,最后我发现1将强制Tomcat 7仅接受TLSv1.2。需要触摸2个地方:
1)在C:\ apache-tomcat-7.0.64-64bit \ conf \ server.xml中
<Connector port="8443"
protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
keystoreFile="ssl/.keystore" keystorePass="changeit"
clientAuth="false" sslProtocol="SSL" sslEnabledProtocols="TLSv1.2" />
哪里
keystoreFile
=本地自签名信任库
org.apache.coyote.http11.Http11Protocol
= JSSE BIO实现。
我们不使用org.apache.coyote.http11.Http11AprProtocol
,因为它由openssl驱动。基本的openssl将回退以支持较早的SSL协议。
2)启动Tomcat时,启用以下环境参数。
set JAVA_HOME=C:\Java64\jdk1.8.0_60
set PATH=%PATH%;C:\Java64\jdk1.8.0_60\bin
set CATALINA_HOME=C:\apache-tomcat-7.0.64-64bit
set JAVA_OPTS=-Djdk.tls.client.protocols="TLSv1.2" -Dsun.security.ssl.allowUnsafeRenegotiation=false -Dhttps.protocols="TLSv1.2"
需要JAVA_OPTS限制,否则Tomcat(由Java8支持)将回退以支持较早的SSL协议。
启动Tomcat C:\apache-tomcat-7.0.64-64bit\bin\startup.bat
我们可以看到JAVA_OPTS出现在Tomcat启动日志中。
Oct 16, 2015 4:10:17 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djdk.tls.client.protocols=TLSv1.2
Oct 16, 2015 4:10:17 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dsun.security.ssl.allowUnsafeRenegotiation=false
Oct 16, 2015 4:10:17 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dhttps.protocols=TLSv1.2
然后,我们可以使用openssl命令来验证我们的设置。首先使用TLSv1.1协议连接localhost:8443。Tomcat拒绝使用服务器证书答复。
C:\OpenSSL-Win32\bin>openssl s_client -connect localhost:8443 -tls1_1
Loading 'screen' into random state - done
CONNECTED(000001C0)
5372:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:.\ssl\s3_pkt.c:362:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 5 bytes and written 0 bytes
使用TLSv1.2协议连接localhost:8443,Tomcat会使用证书回复ServerHello:
C:\OpenSSL-Win32\bin>openssl s_client -connect localhost:8443 -tls1_2
Loading 'screen' into random state - done
CONNECTED(000001C0)
depth=1 C = US, ST = Washington, L = Seattle, O = getaCert - www.getacert.com
verify error:num=19:self signed certificate in certificate chain
---
Certificate chain
0 s:/C=SG/ST=SG/L=Singapore/O=Xxxx/OU=Development/CN=Myself
i:/C=US/ST=Washington/L=Seattle/O=getaCert - www.getacert.com
1 s:/C=US/ST=Washington/L=Seattle/O=getaCert - www.getacert.com
i:/C=US/ST=Washington/L=Seattle/O=getaCert - www.getacert.com
---
Server certificate
-----BEGIN CERTIFICATE-----
(ignored)
-----END CERTIFICATE-----
subject=/C=SG/ST=SG/L=Singapore/O=Xxxx/OU=Development/CN=Myself
issuer=/C=US/ST=Washington/L=Seattle/O=getaCert - www.getacert.com
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 2367 bytes and written 443 bytes
这证明Tomcat现在仅严格响应TLSv1.2请求。