有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java客户端SSL重新协商

我有一个Dropwizard应用程序,其中一个资源需要调用另一个Dropwizard应用程序上的资源。我们注意到在SSL重新协商上花费了很多时间。仔细检查后,仅当其他应用程序位于同一台机器上时,才会发生这种情况。即:

client.target("https://mymachine.com/test").request().post(null);
client.target("https://mymachine.com/test").request().post(null);
// renegotiation

如果使用命令行选项-Djavax.net.debug=ssl:handshake:verbose,日志会显示

%% Client cached [Session-13, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256]
%% Try resuming [Session-13, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256] from port 55043
...
%% Invalidated:  [Session-13, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256]
%% Initialized:  [Session-15, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256]

但在本地计算机上调用同一服务时:

client.target("https://othermachine.com/test").request().post(null);
client.target("https://othermachine.com/test").request().post(null);
// SSL session re-use (=wanted)

日志上写着:

%% Client cached [Session-15, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256]
%% Try resuming [Session-15, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256] from port 55051
...
%% Server resumed [Session-15, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256]

这是怎么回事


共 (1) 个答案

  1. # 1 楼答案

    结果是java版本不同。我的本地主机使用的是旧版本:-$

    Java™ SE Development Kit 8, Update 161 (JDK 8u161) January 16, 2018

    New Features

    security-libs/javax.net.ssl Added TLS session hash and extended master secret extension support Support has been added for the TLS session hash and extended master secret extension (RFC 7627) in JDK JSSE provider. Note that in general, server certificate change is restricted if endpoint identification is not enabled and the previous handshake is a session-resumption abbreviated initial handshake, unless the identities represented by both certificates can be regarded as the same. However, if the extension is enabled or negotiated, the server certificate changing restriction is not necessary and will be discarded accordingly. In case of compatibility issues, an application may disable negotiation of this extension by setting the System Property jdk.tls.useExtendedMasterSecret to false in the JDK. By setting the System Property jdk.tls.allowLegacyResumption to false, an application can reject abbreviated handshaking when the session hash and extended master secret extension is not negotiated. By setting the System Property jdk.tls.allowLegacyMasterSecret to false, an application can reject connections that do not support the session hash and extended master secret extension.

    见JDK-8148421