0
votes

My client application running on tomcat server with java 1.7.0_79 version. It will get data from some third party server applications. But time to time server connection failed due to following exception.

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:953) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)

Most of the server applications supports TLSv1.2 and due to that my client application code is like this. When analyzed the packet identified that TLSv1.1 going for the failed connections from client side. Is there any possibility to get different TLS version other than TLSv1.2 with below code? Also this code execute by multiple threads in client application. Please advice.

TrustManager[] trustAllCerts = new TrustManager[]{
     new X509TrustManager() {
          ...
}};

SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
SSLContext.setDefault(sc);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

URL mUrl = new URL(url);
URLConnection ucon = mUrl.openConnection();
HttpURLConnection con = (HttpURLConnection) ucon;
...
responseBody = con.getInputStream();
1

1 Answers

0
votes

Use -Djavax.net.debug=ssl:all to get detail SSL connection log. It will help in getting more detail about error.