8231810: javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java fails intermittently with "java.lang.Exception: Unexpected EOF"
Reviewed-by: xuelei
This commit is contained in:
parent
dd758e2a84
commit
c2f68eacaa
test/jdk
@ -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/PacketLossRetransmission.java 8169086 macosx-x64
|
||||||
javax/net/ssl/DTLS/RespondToRetransmit.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/DTLS/CipherSuite.java 8202059 macosx-x64
|
||||||
javax/net/ssl/templates/SSLSocketSSLEngineTemplate.java 8231810 generic-all
|
|
||||||
|
|
||||||
sun/security/provider/KeyStore/DKSTest.sh 8180266 windows-all
|
sun/security/provider/KeyStore/DKSTest.sh 8180266 windows-all
|
||||||
|
|
||||||
|
@ -30,7 +30,10 @@
|
|||||||
* @test
|
* @test
|
||||||
* @bug 7105780
|
* @bug 7105780
|
||||||
* @summary Add SSLSocket client/SSLEngine server to templates directory.
|
* @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 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
private static final boolean debug = false;
|
private static final boolean debug = false;
|
||||||
private final SSLContext sslc;
|
private final SSLContext sslc;
|
||||||
private SSLEngine serverEngine; // server-side SSLEngine
|
private SSLEngine serverEngine; // server-side SSLEngine
|
||||||
|
private SSLSocket clientSocket;
|
||||||
|
|
||||||
private final byte[] serverMsg =
|
private final byte[] serverMsg =
|
||||||
"Hi there Client, I'm a Server.".getBytes();
|
"Hi there Client, I'm a Server.".getBytes();
|
||||||
private final byte[] clientMsg =
|
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 serverOut; // write side of serverEngine
|
||||||
private ByteBuffer serverIn; // read side of serverEngine
|
private ByteBuffer serverIn; // read side of serverEngine
|
||||||
@ -135,6 +139,8 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
* Main entry point for this test.
|
* Main entry point for this test.
|
||||||
*/
|
*/
|
||||||
public static void main(String args[]) throws Exception {
|
public static void main(String args[]) throws Exception {
|
||||||
|
String protocol = args[0];
|
||||||
|
|
||||||
// reset security properties to make sure that the algorithms
|
// reset security properties to make sure that the algorithms
|
||||||
// and keys used in this test are not disabled.
|
// and keys used in this test are not disabled.
|
||||||
Security.setProperty("jdk.tls.disabledAlgorithms", "");
|
Security.setProperty("jdk.tls.disabledAlgorithms", "");
|
||||||
@ -144,26 +150,20 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
System.setProperty("javax.net.debug", "all");
|
System.setProperty("javax.net.debug", "all");
|
||||||
}
|
}
|
||||||
|
|
||||||
String [] protocols = new String [] {
|
/*
|
||||||
"SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" };
|
* Run the tests with direct and indirect buffers.
|
||||||
|
*/
|
||||||
|
SSLSocketSSLEngineTemplate test =
|
||||||
|
new SSLSocketSSLEngineTemplate(protocol);
|
||||||
|
log("-------------------------------------");
|
||||||
|
log("Testing " + protocol + " for direct buffers ...");
|
||||||
|
test.runTest(true);
|
||||||
|
|
||||||
for (String protocol : protocols) {
|
log("---------------------------------------");
|
||||||
log("Testing " + protocol);
|
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("Test Passed.");
|
||||||
log("Testing " + protocol + " for indirect buffers ...");
|
|
||||||
test.runTest(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Test Passed.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -213,6 +213,7 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
* sections of code.
|
* sections of code.
|
||||||
*/
|
*/
|
||||||
private void runTest(boolean direct) throws Exception {
|
private void runTest(boolean direct) throws Exception {
|
||||||
|
clientSocket = null;
|
||||||
boolean serverClose = direct;
|
boolean serverClose = direct;
|
||||||
|
|
||||||
// generates the server-side Socket
|
// generates the server-side Socket
|
||||||
@ -220,6 +221,7 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
serverSocket.setReuseAddress(false);
|
serverSocket.setReuseAddress(false);
|
||||||
serverSocket.bind(null);
|
serverSocket.bind(null);
|
||||||
int port = serverSocket.getLocalPort();
|
int port = serverSocket.getLocalPort();
|
||||||
|
log("Port: " + port);
|
||||||
Thread thread = createClientThread(port, serverClose);
|
Thread thread = createClientThread(port, serverClose);
|
||||||
|
|
||||||
createSSLEngine();
|
createSSLEngine();
|
||||||
@ -260,11 +262,18 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
try {
|
try {
|
||||||
len = is.read(inbound);
|
len = is.read(inbound);
|
||||||
if (len == -1) {
|
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);
|
cTOs.put(inbound, 0, len);
|
||||||
} catch (SocketTimeoutException ste) {
|
} catch (SocketTimeoutException ste) {
|
||||||
// swallow. Nothing yet, probably waiting on us.
|
// swallow. Nothing yet, probably waiting on us.
|
||||||
}
|
}
|
||||||
|
|
||||||
cTOs.flip();
|
cTOs.flip();
|
||||||
@ -367,6 +376,8 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
// client-side socket
|
// client-side socket
|
||||||
try (SSLSocket sslSocket = (SSLSocket)sslc.getSocketFactory().
|
try (SSLSocket sslSocket = (SSLSocket)sslc.getSocketFactory().
|
||||||
createSocket("localhost", port)) {
|
createSocket("localhost", port)) {
|
||||||
|
clientSocket = sslSocket;
|
||||||
|
|
||||||
OutputStream os = sslSocket.getOutputStream();
|
OutputStream os = sslSocket.getOutputStream();
|
||||||
InputStream is = sslSocket.getInputStream();
|
InputStream is = sslSocket.getInputStream();
|
||||||
|
|
||||||
@ -475,6 +486,15 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
return (engine.isOutboundDone() && engine.isInboundDone());
|
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
|
* Logging code
|
||||||
*/
|
*/
|
||||||
@ -486,7 +506,7 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
}
|
}
|
||||||
if (resultOnce) {
|
if (resultOnce) {
|
||||||
resultOnce = false;
|
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\"getStatus() / getHandshakeStatus()\" +\n"
|
||||||
+ "\t\"bytesConsumed() / bytesProduced()\"\n");
|
+ "\t\"bytesConsumed() / bytesProduced()\"\n");
|
||||||
}
|
}
|
||||||
@ -502,7 +522,11 @@ public class SSLSocketSSLEngineTemplate {
|
|||||||
|
|
||||||
private static void log(String str) {
|
private static void log(String str) {
|
||||||
if (logging) {
|
if (logging) {
|
||||||
System.out.println(str);
|
if (debug) {
|
||||||
|
System.err.println(str);
|
||||||
|
} else {
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user