12

Sometimes the code below fails and sometimes it work. I'm using Java8. Is it a server side problem?

Exception in thread "main" javax.net.ssl.SSLException: Unsupported record version Unknown-0.0.

EDIT: I downgrade to JDK7 from JDK8 and it works. The only solution i found that works.

public static void main(String[] args) throws Exception {
    URL u = new URL("https://c********.web.cddbp.net/webapi/xml/1.0/");
    HttpURLConnection connection = (HttpURLConnection) u.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setInstanceFollowRedirects(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-Type", "text/plain");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", "" + 140);
    connection.setUseCaches(false);
    DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
}
daniele.guiducci
  • 153
  • 1
  • 1
  • 5

5 Answers5

9

I got the same error message in a new java installation when trying to use an SSL connection that enforces 256-bit encryption. To fix the problem I found I needed to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files (e.g. http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html)

  • 3
    It's fair enough providing a remedy that may help some but this doesn't explain in detail what is actually causing the randomness of his error. I experience this exact issue with the latest JDK and JCE applied in our production environment so I don't see this as a solution. – JavaJedi Feb 01 '17 at 23:08
2

I had this line

    SSLContext sc = SSLContext.getInstance("SSL");

Had to change it to

    SSLContext sc = SSLContext.getInstance("TLSv1");

And now it works on both, java 7 and java 8

Note: (In java 7 SSL and TLS both worked with the same url, in java 8 just tried TLSv1 but I guess SSLv1 also works)

1

Download the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files according to your JDK/JRE version and put it in lib/security folder

By default,Java Cryptographic Extension is limited in accessing function and algorithm usage.We need to make it unlimited.

paradox
  • 51
  • 7
0

According to the stack trace, the RecordVersion Unknow-0.0 is produced from here => referenced from here => which is invoked in InputRecord.readV3Record

most of the time, these two values should not be 0, the reason for this happening is probably the wrong response from server while handshaking.

(This is not an answer though, just some information for easier figuring out the problem and solution)

Valen
  • 1,693
  • 1
  • 20
  • 17
0

This error is fixed in latest jre's, just upgrade the version of jre. This issue is caused by SNI

paradox
  • 51
  • 7