0

I write a demo to access a server with java HttpsUrlConnection. I implement the X509TrustManager interface with MyX509TrustManager to trust all certificates.

It works fine with JDK7 and JDK8, but when use JDK6 and JDK5, error happens:

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:882)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1215)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1199)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)

For server side, running on Tomcat 8 and JDK8.

EDIT I add -Djavax.net.debug=ssl,handshake and find following:

*** main, WRITE: TLSv1 Handshake, length = 177 main, WRITE: SSLv2 client hello message, length = 173
main, received EOFException: error main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
main, SEND TLSv1 ALERT: fatal, description = handshake_failure
main, WRITE: TLSv1 Alert, length = 2 main, called closeSocket()
main, called close() main, called closeInternal(true)
user207421
  • 305,947
  • 44
  • 307
  • 483
fcbflying
  • 693
  • 1
  • 7
  • 23
  • You probably need to disable SSLv3, but you would need to post the output of `-Djavax.net.debug=ssl,handshake` for us to be sure. Could also be a client certificate issue. – user207421 Aug 10 '15 at 03:48
  • I add -Djavax.net.debug=ssl,handshake and find following:*** main, WRITE: TLSv1 Handshake, length = 177 main, WRITE: SSLv2 client hello message, length = 173 main, received EOFException: error main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake main, SEND TLSv1 ALERT: fatal, description = handshake_failure main, WRITE: TLSv1 Alert, length = 2 main, called closeSocket() main, called close() main, called closeInternal(true) – fcbflying Aug 10 '15 at 04:14
  • @EJB thanks very much. I try this code:System.setProperty("https.protocols","TLSv1"); and it works fine in JDK5, JDK6, JDK7, JDK8. – fcbflying Aug 10 '15 at 04:50
  • have you try ssllabs.com to check if the sever is compatible with java 6 / 7 ? – Tom Aug 13 '15 at 23:00
  • I test on my local with different java versions. – fcbflying Sep 01 '15 at 01:10

0 Answers0