如何让球衣客户端使用 TLSv1.1? 我正在尝试强制 com.sun.jersey.client.urlconnection.HTTPSProperties(球衣客户端代码最终进入此类)使用TLSv1.1(或 TLSv1)来编写确认服务器协议的测试代码。在设置客户端时,我执行以下操作:
SSLContext context = SSLContext.getInstance("TLSv1.1");
context.init(null, trustAll, new SecureRandom());
HTTPSProperties props = new HTTPSProperties(hv, context);
clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, props);
在 HTTPSProperties 内部(我下载了 1.x 源代码,所以这可能是错误的)我看到:
public void setConnection(HttpsURLConnection connection) {
if (hostnameVerifier != null)
connection.setHostnameVerifier(hostnameVerifier);
connection.setSSLSocketFactory(sslContext.getSocketFactory());
}
如果我SSLContext.getInstance("TLS");
改用,代码可以正常工作。我试过添加System.setProperty("https.protocols", "TLSv1.1");
,但它仍然不起作用。上面的代码给出了堆栈跟踪:
Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2020)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1127)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1580)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1508)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:240)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
... 22 more
我的服务器(Jetty 9.4.41)认为它允许 TLSV1.1。当我转储 sslFactory 时,我得到:
I. 2021-09-29 16:37:59. [main] SSL context: Server@239105a8[provider=null,keyStore=file:***,trustStore=null] -
STOPPED
+> trustAll=false
+> Protocol Selections
| +> Enabled size=3
| | +> TLSv1.1
| | +> TLSv1.2
| | +> TLSv1.3
| +> Disabled size=3
| +> SSLv2Hello - ConfigExcluded:'SSLv2Hello', ConfigIncluded:NotSelected
| +> SSLv3 - ConfigExcluded:'SSLv3', ConfigIncluded:NotSelected JVM:disabled
| +> TLSv1 - ConfigExcluded:'TLSv1', ConfigIncluded:NotSelected JVM:disabled
+> Cipher Suite Selections
+> Enabled size=39
| +> TLS_AES_128_GCM_SHA256
| +> TLS_AES_256_GCM_SHA384
| +> TLS_DHE_DSS_WITH_AES_128_CBC_SHA
| +> TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
| +> TLS_DHE_DSS_WITH_AES_128_GCM_SHA256
| +> TLS_DHE_DSS_WITH_AES_256_CBC_SHA
| +> TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
| +> TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
| +> TLS_DHE_RSA_WITH_AES_128_CBC_SHA
| +> TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
| +> TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
| +> TLS_DHE_RSA_WITH_AES_256_CBC_SHA
| +> TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
| +> TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
| +> TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
| +> TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
| +> TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
| +> TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
| +> TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
| +> TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
| +> TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
| +> TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
| +> TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
| +> TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
| +> TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
| +> TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
| +> TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
| +> TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
| +> TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
| +> TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
| +> TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
| +> TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
| +> TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
| +> TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
| +> TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
| +> TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
| +> TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
| +> TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
| +> TLS_EMPTY_RENEGOTIATION_INFO_SCSV
+> Disabled size=6
+> TLS_RSA_WITH_AES_128_CBC_SHA - ConfigExcluded:'^TLS_RSA_.*$'
+> TLS_RSA_WITH_AES_128_CBC_SHA256 - ConfigExcluded:'^TLS_RSA_.*$'
+> TLS_RSA_WITH_AES_128_GCM_SHA256 - ConfigExcluded:'^TLS_RSA_.*$'
+> TLS_RSA_WITH_AES_256_CBC_SHA - ConfigExcluded:'^TLS_RSA_.*$'
+> TLS_RSA_WITH_AES_256_CBC_SHA256 - ConfigExcluded:'^TLS_RSA_.*$'
+> TLS_RSA_WITH_AES_256_GCM_SHA384 - ConfigExcluded:'^TLS_RSA_.*$'
任何帮助表示赞赏!提前致谢。