0

I have an external web server (running on java 7) witch i am trying to reach through https.

Here is my request code:

        //Inserted cert into truststore because unsigned
        System.setProperty("javax.net.ssl.trustStore", "truststore");
        System.setProperty("javax.net.ssl.trustStorePassword", "password");

        DefaultHttpClient httpClient = new DefaultHttpClient();

        //Because connecting through ip hostname verification would fail
        SSLSocketFactory socketFactory = (SSLSocketFactory) httpClient.getConnectionManager().getSchemeRegistry().get("https").getSchemeSocketFactory();
        socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpGet httpRequest = new HttpGet("https://<ip>:<port>/test");
        HttpResponse httpResponse = httpClient.execute(httpRequest);
        System.out.println(httpResponse);

This code is ran with java 6 and im getting an exception:

Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
    at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:572)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:640)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
    at com.example.HttpClient.App.main(App.java:54)

The interesting thing is that when i use java7 to run previous code then everything works. Also if I use java 6 to run the web server then also everything works. This problem only happens when using java 1.6 for client and java 1.7 for server.

What could be the problem?

user1985273
  • 1,817
  • 15
  • 50
  • 85
  • The problem is that Java 7 introduced SNI support which is enabled by default.Check [this](http://stackoverflow.com/questions/7615645/ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0/14884941#14884941) – HadiRj Aug 24 '15 at 08:24
  • Support for Java 6 ended february 2013. Do you really need to support such outdated software? – Gerald Schneider Aug 24 '15 at 08:24
  • @HadiRj Tried starting the server with "java -Djsse.enableSNIExtension=false -jar server.jar" and still getting the same exception. – user1985273 Aug 24 '15 at 08:41

0 Answers0