如何在apache HttpClient上设置TLS版本
如何在HttpClient上更改受支持的TLS版本?
我正在做:
SSLContext sslContext = SSLContext.getInstance("TLSv1.1");sslContext.init(
keymanagers.toArray(new KeyManager[keymanagers.size()]),
null,
null);
SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext, new String[]{"TLSv1.1"}, null, null);
Scheme scheme = new Scheme("https", 443, socketFactory);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(scheme);
BasicClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
httpClient = new DefaultHttpClient(cm);
但是当我检查创建的套接字时,它仍然说支持的协议是TLSv1.0,TLSv1.1和TLSv1.2。
实际上,我只希望它针对此特定HttpClient停止使用TLSv1.2。
回答:
解决方案是:
SSLContext sslContext = SSLContexts.custom() .useTLS()
.build();
SSLConnectionSocketFactory f = new SSLConnectionSocketFactory(
sslContext,
new String[]{"TLSv1", "TLSv1.1"},
null,
BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom()
.setSSLSocketFactory(f)
.build();
不过,这需要org.apache.httpcomponents.httpclient4.3.x。
以上是 如何在apache HttpClient上设置TLS版本 的全部内容, 来源链接: utcz.com/qa/432312.html