Java – SSL connection reset
I tried to connect to an HTTPS endpoint via Java Each method I tried (more details below) eventually generates this stack trace:
java.net.socketException: Connection reset at java.net.socketInputStream.read(SocketInputStream.java:168) at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293) at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:753) at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
I tried:
>Connect the javax soap library and a new URL ("HTTPS: / /...") > connect a new URL ("HTTPS: / /...") Openconnection() manually creates an SSL connection:
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket socket = (SSLSocket) factory.createSocket("...",443); Writer out = new OutputStreamWriter(socket.getOutputStream()); // https requires the full URL in the GET line // out.write("GET / HTTP/1.0\r\n"); out.write("\r\n"); out.flush(); // read response BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream())); int c; while ((c = in.read()) != -1) { System.out.write(c); } out.close(); in.close(); socket.close();
More details:
>Every method I have tried works on other SSL servers. This is a specific server (I can't discuss what server, it's a business partner) > I can connect to this server using a web browser and forge soap requests with curls; This is java specific
Therefore, it is obvious how the handshake between Java and HTTPS servers should drop, which may mean that the server has some strange SSL configurations and some inconsistencies However, I don't have direct access to the server, and people all over the world do, so communication is a little nervous because of different time zones
If my hypothesis is correct, what are the possible SSL problems? What could cause such a thing? Where can I ask the person who controls the server to find the problem? When I execute a request using curl, I retract these server configuration headers:
Server: Apache/2.2.9 (Debian) mod_jk/1.2.26 PHP/5.2.6-1+lenny10 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g mod_perl/2.0.4 Perl/v5.10.0 X-Powered-By: PHP/5.2.6-1+lenny10 X-SOAP-Server: NuSOAP/0.7.3 (1.114)
Solution
This is a problem with the SSL version The server only supports SSL v3. Java will start from V2 and try to negotiate upward, but not all servers support this negotiation
Forcing java to use only SSL V3 is the only solution I know
Editor, there are two ways to do this, I know:
>If you create a socket manually, you can set the enabled protocol
socket. setEnabledProtocols(new String [] {“SSLv3”}); > If you are using a higher-level library, you may need to set all SSL requests to use V3 only, which is done through the "HTTPS. Protocols" system attribute:
java -Dhttps. protocols = SSLv3