2



I,ve got a Problem here, I have some code that works perfect in 1.7 and above but once I switch to 1.6 I always get this error:

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)

I think the problem is with the HttpsURLConnection but I can't figure out what. Here is how I initialize the HttpsURLConnection:

 // create URL Object from String
 URL url = new URL(https_url);
 // set IP Adress for X509TrustManager
 caTrustManager.setHostIP(url.getHost());     
 TrustManager[] trustCerts = new TrustManager[]{
     caTrustManager
 };
 SSLContext sc = SSLContext.getInstance("SSL");
 sc.init(null, trustCerts, new java.security.SecureRandom());
 //'ArrayList' where the data is saved from the URL
 ArrayList data = null;
 // open URL
 HttpsURLConnection httpsVerbindung = (HttpsURLConnection) url.openConnection();           
 httpsVerbindung.setSSLSocketFactory(sc.getSocketFactory());
 // Read the data from the URL
 data = PerformAction.getContent(httpsVerbindung);

And here is the Methode where the Error happens:
Class = PerformAction
Methode = getContent(HttpsURLConnection con):

public static ArrayList getContent(HttpsURLConnection con) {

    // The ArrayList where the information is saved
    ArrayList infoFromTheSite = new ArrayList();
    // check if connection not null
    if (con != null) {

        BufferedReader br = null;
        try {
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // !!!! **Error happens Here** !!!!
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            br = new BufferedReader(new InputStreamReader(con.getInputStream()));

            String input;
            // go through all the Data
            while ((input = br.readLine()) != null) {
                // save to ArrayList
                infoFromTheSite.add(input);
            }

        } catch (IOException ex) {
            Logging.StringTimeFail("Fehler mit dem BufferedReaders");
            ex.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException ex) {
                    Logger.getLogger(PerformAction.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }

}


I hope my problem is kinda clear and someone understands me :P
Thanks for taking your time to go over my problem!

EDIT

So I found out with Wireshark that the Packets that Fail are Smaller then the ones that succed (157 bytes = fail; 208 bytes = true)

I was thinking maybe he isnt encrypting the Data in the IP Packet oder isnt sending the Certificate.

I also noticed that the SSL Handshake is successful, but once the Client requests data it fails and the Server anwsers with:

Connection Reset

(Yes the Server is calling "Connection Reset")
I am really lost here :D

JoCoaker
  • 633
  • 9
  • 18
  • 2
    If the server you are communicating with is securely maintained you will have problems with Java 1.6 because it does only support the insecure versions of SSL/TLS (no TLS 1.1 and 1.2 support and only outdated ciphers). Fix: Upgrade your Java version. – Robert Sep 01 '15 at 11:25
  • The problem is, I cant. The Application has to run on the Companys computer Network and they only have Java 1.6 on it and it doesnt look like it will be updated soon since it just was recently. Looks like Ill have to rewrite the thing in C# :D Thanks For the Heads up btw! ;) – JoCoaker Sep 01 '15 at 11:47
  • @Robert Could you write that comment as an answer, because I think it would be helpful if fellow Programmmers could see that this is a problem with **Java 1.6**. Cheers! – JoCoaker Sep 01 '15 at 12:05
  • @JoCoaker not sure about this, but you might be able to use apache HTTPClient. – Dakshinamurthy Karra Sep 01 '15 at 12:17
  • @KDM Thanks for the Tip. I checked it out but I dont really understand how it works. I guess Ill have to keep trying then – JoCoaker Sep 01 '15 at 13:18

1 Answers1

3

As @Robert mentioned in the comment:

If the server you are communicating with is securely maintained you will have problems with Java 1.6 because it does only support the insecure versions of SSL/TLS (no TLS 1.1 and 1.2 support and only outdated ciphers).

Fix: Upgrade your Java version.

If you are unable to upgrade your Java version, you can use Apache HTTPClient.

Community
  • 1
  • 1
Dakshinamurthy Karra
  • 5,353
  • 1
  • 17
  • 28