2

Thanks for your time to read my question - I am using Eclipse IDE. I want Jsoup to connect a https url - https://www.icegate.gov.in/ using Document doc = Jsoup.connect("https://www.icegate.gov.in/").get();

but it giving error Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake while when i use same code for other https like linkedin then it works ... I don't know how to resolve this issue.

I got certificate of that website and installed in my jre/lib/security folder but it also not helped me.

How to add these certificate & jks in eclipse.

Here is my code:

public static void main(String[] args) throws IOException {

    Document doc = Jsoup.connect("https://www.linkedin.com/in/xxxxxx").get();

    Element summaryDetails = doc.getElementById("profile");


    System.out.println("Summary Details  is - "+ summaryDetails.text());

    Document doc2 = Jsoup.connect("https://www.icegate.gov.in/").get();
}

And error I am getting is:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:512)
    at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)
    at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)
    at org.jsoup.helper.HttpConnection.get(HttpConnection.java:194)
    at com.deepak.TestLinkedIn.main(TestLinkedIn.java:39)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(InputRecord.java:482)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
fonkap
  • 2,469
  • 1
  • 14
  • 30
Deepak Kumar
  • 21
  • 1
  • 2

1 Answers1

1

Just run java with these VM arguments:

-Dhttps.protocols=TLSv1.2 -Djsse.enableSNIExtension=false

more info in these other questions:

SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0

How to make Java 6, which fails SSL connection with "SSL peer shut down incorrectly", succeed like Java 7?

Bytheway, I didn't need to add any certificate to my truststore because site certificate's CA was already trusted.

Community
  • 1
  • 1
fonkap
  • 2,469
  • 1
  • 14
  • 30
  • My console app was working monthes, but today I getting same error. Do not know why, but surprisingly it works – Dimmduh Nov 03 '16 at 10:30