I have the following simple code to establish an SSL connection.
public static void main(String[] args) throws IOException {
System.setProperty("javax.net.debug", "ALL");
System.setProperty("java.net.useSystemProxies", "true");
URL url = new URL("https://google.com");
URLConnection con = url.openConnection();
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
If I run this code under Java 8 it doesn't work. It stops at starting the SSL Handshake with a java.net.SocketException: Connection reset
.
main, WRITE: TLSv1.2 Handshake, length = 214 main, waiting for close_notify or alert: state 1 Exception in thread "main" java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:209) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.InputRecord.readFully(InputRecord.java:465) at sun.security.ssl.InputRecord.read(InputRecord.java:503) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973) at sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1769) at sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:124) at sun.security.ssl.Handshaker.kickstart(Handshaker.java:1020) at sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1487) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1351) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) at com.hlcl.exp.Main.main(Main.java:18) main, Exception while waiting for close java.net.SocketException: Connection reset main, handling exception: java.net.SocketException: Connection reset main, SEND TLSv1.2 ALERT: fatal, description = unexpected_message main, WRITE: TLSv1.2 Alert, length = 2 main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error main, called closeSocket()
If I execute the same code in a Java 10 environment it works.
I have checked the proxy which is detected by java. Under Java 8 a DIRECT (no proxy) connection is detected. With Java 10 the following proxy settings are detected.
proxy type: HTTP
proxy hostname: ipv4.xxx.xxx.xxx.com
proxy port: 8081
If I remove System.setProperty("java.net.useSystemProxies", "true");
or set it to false it also not work with Java 10. But setting the proxy settings via the system properties is not working.