Reputation: 71
With reference to the solution provided in How to use TLS 1.2 in Java 6, is it possible to use the TSLSocketConnectionFactory with the Apache HttpClient4.4.
Regards, j
Upvotes: 3
Views: 3811
Reputation: 101
You should be able to use TSLSocketConnectionFactory with HttpClient like following:
SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(new TLSSocketConnectionFactory(), new String[]{"TLSv1.2"}, null, new DefaultHostnameVerifier());
HttpClient client = HttpClientBuilder.create()
.setSSLSocketFactory(sf)
.build();
You may need to change some of the SSLSession method implementations at the TSLSocketConnectionFactory.
In my case, when I tried to use it with HttpClient, I had to change the following:
At SSLSocket() implementation:
@Override
public String[] getEnabledCipherSuites() {
// return null;
return new String[]{""};
}
@Override
public String[] getEnabledProtocols() {
// return null;
return new String[]{""};
}
At SSLSession() implementation:
@Override
public String getProtocol() {
// throw new UnsupportedOperationException();
return null;
}
@Override
public String getProtocol() {
// throw new UnsupportedOperationException();
return "";
}
@Override
public String getCipherSuite() {
// throw new UnsupportedOperationException();
return "":
}
Upvotes: 5