How can I change the supported TLS versions on my HttpClient?
I'm doing:
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);
But when I check the created socket, it still says the supported protocols are TLSv1.0, TLSv1.1 and TLSv1.2.
In reality I just want it to stop using TLSv1.2, for this specific HttpClient.
Using the
HttpClientBuilder
in HttpClient 4.5.x with a customHttpClientConnectionManager
with the defaults ofHttpClientBuilder
:Without a custom
HttpClientConnectionManager
:This is how I got it working on httpClient 4.5 (as per Olive Tree request):
For HttpClient-4.1 using TLSv1.2, code would go something like this:
Since this only came up hidden in comments, difficult to find as a solution:
You can use
java -Dhttps.protocols=TLSv1,TLSv1.1
, but you need to use also useSystemProperties()We use this setup in our system now as this enables us to set this only for some usage of the code. In our case we still have some Java 7 running and one API end point disallowed TLSv1, so we use
java -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
to enable current TLS versions. Thanks @jebeaudet for pointing in this direction.If you have a javax.net.ssl.SSLSocket class reference in your code, you can set the enabled TLS protocols by a call to SSLSocket.setEnabledProtocols():
The solution is:
This requires org.apache.httpcomponents.httpclient 4.3.x though.