Skip to content
Permalink
Browse files
8262438: sun/security/ssl/SSLLogger/LoggingFormatConsistency.java fai…
…led with "SocketException: Socket is closed"

Reviewed-by: rhalade
  • Loading branch information
Evan Whelan authored and Rob McKenna committed Mar 10, 2021
1 parent c8c0234 commit b2a2ddff44331475ba17051936dbc402cc6a3f46
Showing with 7 additions and 62 deletions.
  1. +7 −62 test/jdk/sun/security/ssl/SSLLogger/LoggingFormatConsistency.java
@@ -38,18 +38,7 @@
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.security.SecurityUtils;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;

import static java.nio.charset.StandardCharsets.UTF_8;

public class LoggingFormatConsistency extends SSLSocketTemplate {

@@ -89,63 +78,19 @@ public static void main(String[] args) throws Exception {
"LoggingFormatConsistency",
"runTest"); // Ensuring args.length is greater than 0 when test JVM starts

output.asLines()
.stream()
.filter(line -> line.startsWith("Connecting to"))
.forEach(System.out::println); // prints connection info from test jvm output

if (output.getExitValue() != 0) {
throw new RuntimeException("Test JVM process failed. JVM stderr= " + output.getStderr());
output.asLines().forEach(System.out::println);
throw new RuntimeException("Test JVM process failed");
}

output.shouldContain(expectedTLSVersion);
output.shouldNotContain(incorrectTLSVersion);
}
}
}

@Override
protected boolean isCustomizedClientConnection() { return true; }

@Override
protected void runServerApplication(SSLSocket socket) throws Exception {
var response = "Hello World!";
var out = new DataOutputStream(socket.getOutputStream());
try {
// We don't need to process the data from the socket
// Simply sending a response right away is sufficient
// to generate the desired debug output
var responseBytes = response.getBytes(UTF_8);

out.writeBytes("HTTP/1.0 200 OK\r\n");
out.writeBytes("Content-Length: " + responseBytes.length + "\r\n");
out.writeBytes("Content-Type: text/html\r\n\r\n");
out.write(responseBytes);
out.flush();
} catch (IOException e) {
out.writeBytes("HTTP/1.0 400 " + e.getMessage() + "\r\n");
out.writeBytes("Content-Type: text/html\r\n\r\n");
out.flush();
}
}

@Override
protected void runClientApplication(int serverPort) throws Exception {
var context = createClientSSLContext();
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier());

var host = serverAddress == null ? "localhost" : serverAddress.getHostAddress();
var url = new URL("https://" + host + ":" + serverPort + "/");
var httpsConnection = (HttpsURLConnection) url.openConnection();
httpsConnection.disconnect();
try (var in = new BufferedReader(new InputStreamReader(httpsConnection.getInputStream()))) {
// Getting the input stream from the BufferedReader is sufficient to generate the desired debug output
// We don't need to process the data
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static class NameVerifier implements HostnameVerifier {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}
}

3 comments on commit b2a2ddf

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot replied Mar 10, 2021

@GoeLin

This comment has been minimized.

Copy link
Member

@GoeLin GoeLin replied Oct 5, 2021

/backport jdk11u-dev

@openjdk

This comment has been minimized.

Copy link

@openjdk openjdk bot replied Oct 5, 2021

@GoeLin the backport was successfully created on the branch GoeLin-backport-b2a2ddff in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

this pull request contains a backport of commit b2a2ddff from the openjdk/jdk repository.

The commit being backported was authored by Evan Whelan on 10 Mar 2021 and was reviewed by Rajan Halade.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-b2a2ddff:GoeLin-backport-b2a2ddff
$ git checkout GoeLin-backport-b2a2ddff
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev GoeLin-backport-b2a2ddff
Please sign in to comment.