Skip to content
Permalink
Browse files

8231810: javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java fail…

…s intermittently with "java.lang.Exception: Unexpected EOF"

Reviewed-by: xuelei
  • Loading branch information
John Jiang
John Jiang committed Dec 11, 2019
1 parent dd758e2 commit c2f68eacaae709a628b392c4e965eb38feaa43a7
Showing with 49 additions and 26 deletions.
  1. +0 −1 test/jdk/ProblemList.txt
  2. +49 −25 test/jdk/javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java
@@ -681,7 +681,6 @@ javax/net/ssl/ServerName/SSLEngineExplorerMatchedSNI.java 8212096 generic-
javax/net/ssl/DTLS/PacketLossRetransmission.java 8169086 macosx-x64
javax/net/ssl/DTLS/RespondToRetransmit.java 8169086 macosx-x64
javax/net/ssl/DTLS/CipherSuite.java 8202059 macosx-x64
javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java 8231810 generic-all

sun/security/provider/KeyStore/DKSTest.sh 8180266 windows-all

@@ -30,7 +30,10 @@
* @test
* @bug 7105780
* @summary Add SSLSocket client/SSLEngine server to templates directory.
* @run main/othervm SSLSocketSSLEngineTemplate
* @run main/othervm SSLSocketSSLEngineTemplate TLSv1
* @run main/othervm SSLSocketSSLEngineTemplate TLSv1.1
* @run main/othervm SSLSocketSSLEngineTemplate TLSv1.2
* @run main/othervm SSLSocketSSLEngineTemplate TLSv1.3
*/

/**
@@ -100,11 +103,12 @@
private static final boolean debug = false;
private final SSLContext sslc;
private SSLEngine serverEngine; // server-side SSLEngine
private SSLSocket clientSocket;

private final byte[] serverMsg =
"Hi there Client, I'm a Server.".getBytes();
private final byte[] clientMsg =
"Hello Server, I'm a Client! Pleased to meet you!".getBytes();
"Hello Server, I'm a Client! Pleased to meet you!".getBytes();

private ByteBuffer serverOut; // write side of serverEngine
private ByteBuffer serverIn; // read side of serverEngine
@@ -135,6 +139,8 @@
* Main entry point for this test.
*/
public static void main(String args[]) throws Exception {
String protocol = args[0];

// reset security properties to make sure that the algorithms
// and keys used in this test are not disabled.
Security.setProperty("jdk.tls.disabledAlgorithms", "");
@@ -144,26 +150,20 @@ public static void main(String args[]) throws Exception {
System.setProperty("javax.net.debug", "all");
}

String [] protocols = new String [] {
"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" };

for (String protocol : protocols) {
log("Testing " + protocol);
/*
* Run the tests with direct and indirect buffers.
*/
SSLSocketSSLEngineTemplate test =
new SSLSocketSSLEngineTemplate(protocol);
log("-------------------------------------");
log("Testing " + protocol + " for direct buffers ...");
test.runTest(true);

log("---------------------------------------");
log("Testing " + protocol + " for indirect buffers ...");
test.runTest(false);
}
/*
* Run the tests with direct and indirect buffers.
*/
SSLSocketSSLEngineTemplate test =
new SSLSocketSSLEngineTemplate(protocol);
log("-------------------------------------");
log("Testing " + protocol + " for direct buffers ...");
test.runTest(true);

log("---------------------------------------");
log("Testing " + protocol + " for indirect buffers ...");
test.runTest(false);

System.out.println("Test Passed.");
log("Test Passed.");
}

/*
@@ -213,13 +213,15 @@ public SSLSocketSSLEngineTemplate(String protocol) throws Exception {
* sections of code.
*/
private void runTest(boolean direct) throws Exception {
clientSocket = null;
boolean serverClose = direct;

// generates the server-side Socket
try (ServerSocket serverSocket = new ServerSocket()) {
serverSocket.setReuseAddress(false);
serverSocket.bind(null);
int port = serverSocket.getLocalPort();
log("Port: " + port);
Thread thread = createClientThread(port, serverClose);

createSSLEngine();
@@ -260,11 +262,18 @@ private void runTest(boolean direct) throws Exception {
try {
len = is.read(inbound);
if (len == -1) {
throw new Exception("Unexpected EOF");
logSocketStatus(clientSocket);
if (clientSocket.isClosed()
|| clientSocket.isOutputShutdown()) {
log("Client socket was closed or shutdown output");
break;
} else {
throw new Exception("Unexpected EOF");
}
}
cTOs.put(inbound, 0, len);
} catch (SocketTimeoutException ste) {
// swallow. Nothing yet, probably waiting on us.
// swallow. Nothing yet, probably waiting on us.
}

cTOs.flip();
@@ -367,6 +376,8 @@ public void run() {
// client-side socket
try (SSLSocket sslSocket = (SSLSocket)sslc.getSocketFactory().
createSocket("localhost", port)) {
clientSocket = sslSocket;

OutputStream os = sslSocket.getOutputStream();
InputStream is = sslSocket.getInputStream();

@@ -475,6 +486,15 @@ private static boolean isEngineClosed(SSLEngine engine) {
return (engine.isOutboundDone() && engine.isInboundDone());
}

private static void logSocketStatus(Socket socket) {
log("##### " + socket + " #####");
log("isBound: " + socket.isBound());
log("isConnected: " + socket.isConnected());
log("isClosed: " + socket.isClosed());
log("isInputShutdown: " + socket.isInputShutdown());
log("isOutputShutdown: " + socket.isOutputShutdown());
}

/*
* Logging code
*/
@@ -486,7 +506,7 @@ private static void log(String str, SSLEngineResult result) {
}
if (resultOnce) {
resultOnce = false;
System.out.println("The format of the SSLEngineResult is: \n"
log("The format of the SSLEngineResult is: \n"
+ "\t\"getStatus() / getHandshakeStatus()\" +\n"
+ "\t\"bytesConsumed() / bytesProduced()\"\n");
}
@@ -502,7 +522,11 @@ private static void log(String str, SSLEngineResult result) {

private static void log(String str) {
if (logging) {
System.out.println(str);
if (debug) {
System.err.println(str);
} else {
System.out.println(str);
}
}
}
}

0 comments on commit c2f68ea

Please sign in to comment.
You can’t perform that action at this time.