SSL Connection Reset

SSL Connection Reset

  1. Blog
  2. 15 November 2026
  3. 5 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding java.net.SocketException: Connection Reset on Specific SSL Endpoints

When a Java application throws java.net.SocketException: Connection reset during an HTTPS handshake, the immediate instinct is to blame the server's certificate or the JVM's crypto provider. However, when connectivity works fine in browsers, via curl, and against other endpoints, the issue almost certainly lies in a mismatch between the client's SSL/TLS expectations and the server's configuration. The stack trace you are seeing indicates that the remote peer closed the connection abruptly before Java could complete the initial handshake or read the response headers.

Since standard libraries like javax.xml.soap and basic URL.openConnection() fail, but raw socket manipulation also fails, we must look at the protocol negotiation itself. The fact that curl succeeds suggests the server is not rejecting the connection based on IP reputation or simple connectivity issues. Instead, it implies a strict handshake requirement that Java's default implementation does not satisfy.

Protocol Version and Cipher Suite Mismatches

The most common cause for this specific symptom—where other clients work but Java fails—is a divergence in supported TLS versions or cipher suites. Your server headers indicate an Apache setup running OpenSSL 0.9.8g, which is quite legacy. Older OpenSSL configurations often defaulted to SSLv3 or early TLS versions with weak ciphers that modern Java JDKs (post-Java 8 updates) disable by default for security reasons.

If the server expects a specific cipher suite that has been removed from Java's default enabled list, the handshake will fail immediately. The server may attempt to close the socket upon receiving a ClientHello it cannot negotiate with, resulting in the Connection reset exception on the client side.

To investigate this without changing the server configuration, you can inspect what ciphers your JVM is offering versus what the server requires. You can check the available protocols and ciphers by printing the SSL socket properties before connecting:

SSLContext context = SSLContext.getDefault();
SSLSocketFactory factory = context.getSocketFactory();
SSLSocket socket = (SSLSocket) factory.createSocket("target-host", 443);

System.out.println("Enabled Protocols: " + Arrays.toString(socket.getEnabledProtocols()));
System.out.println("Enabled Cipher Suites: " + Arrays.toString(socket.getSupportedCipherSuites()));

If the server logs show a rejected handshake attempt, this confirms a version mismatch. The solution often involves adding an older JDK or explicitly enabling legacy protocols in your Java application if business requirements mandate compatibility with such legacy infrastructure. However, relying on SSLv3 is strongly discouraged due to known vulnerabilities like POODLE and BEAST.

Certificate Verification and Hostname Validation

Another frequent culprit is hostname verification. Modern Java versions strictly enforce that the certificate's Common Name (CN) or Subject Alternative Name (SAN) matches the host being contacted. While browsers are more forgiving, presenting warnings, and curl can be configured to skip verification, Java throws exceptions immediately if validation fails.

If the server presents a self-signed certificate or one with an incorrect CN, Java will abort the handshake. This behavior is distinct from a simple connection reset; however, depending on the underlying OS network stack, the abrupt termination of the SSL layer by the server (due to cert errors) might be reported as a socket exception depending on how the stream is handled.

Check your code for any trustManager logic. If you are using system defaults, ensure that the certificate chain is correctly installed in the Java TrustStore. If you are developing locally, you might need to import the server's root CA into your local keystore:

keytool -importcert -alias "partner-server" -file "server.crt" -keystore $JAVA_HOME/lib/security/cacerts

Apache Configuration and Legacy SSL Support

Given the server headers (OpenSSL/0.9.8g, mod_ssl/2.2.9), the server is likely configured to accept older protocols that Java no longer supports by default. The people controlling this server need to check their sslvinfo output or Apache logs (error.log) for handshake failures.

Specifically, look for messages indicating "no shared cipher" or "protocol too old." If the server is hard-coded to only allow SSLv3 and Java sends TLS 1.2, the negotiation fails. Since you cannot modify the server directly, the workaround in Java involves creating a custom SSLContext that explicitly enables legacy protocols:

SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, null, null); // Or use specific trust managers if needed
SSLSocketFactory factory = ctx.getSocketFactory();

Alternatively, using an older JDK version (e.g., Java 7 or early Java 8) might restore compatibility if the business logic permits it. This is a significant trade-off between security and connectivity; upgrading the server's OpenSSL to a modern version (1.0.2 or higher) and configuring it for TLS 1.2 is the permanent fix, but requires coordination with your partner.

Debugging Network Level Issues

If protocol mismatches are ruled out, the issue could be at the network level. Some legacy firewalls or NAT devices inspect SSL traffic and drop packets if they cannot decrypt them (MITM scenarios). Since curl works, this is less likely unless curl is using a different proxy or DNS resolution that Java isn't seeing.

Ensure your Java application isn't resolving the hostname to an IP address that triggers port forwarding rules differently than the one used by curl. Also, check if the server has connection timeouts configured in Apache (Timeout, KeepAliveTimeout) that are too aggressive for the time it takes Java to establish the handshake over a high-latency link.

Finally, verify that the specific endpoint isn't being rate-limited or throttled specifically for Java user-agents, though this is rare for raw socket connections. The headers show X-Powered-By: PHP, so ensure no application-level logic in PHP is rejecting connections based on missing HTTP headers (like User-Agent) that Java might omit compared to a browser or curl command.

Our network