提交 b879cbad 编写于 作者: I igerasim

8189760: sun/security/ssl/CertPathRestrictions/TLSRestrictions.java failed...

8189760: sun/security/ssl/CertPathRestrictions/TLSRestrictions.java failed with unexpected Exception intermittently
Summary: Adds synchronization to make sure the server exception is available
Reviewed-by: xuelei
上级 fb29e369
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,8 +36,6 @@ public class JSSEServer { ...@@ -36,8 +36,6 @@ public class JSSEServer {
private SSLServerSocket server = null; private SSLServerSocket server = null;
private Exception exception = null;
public JSSEServer(SSLContext context, public JSSEServer(SSLContext context,
boolean needClientAuth) throws Exception { boolean needClientAuth) throws Exception {
SSLServerSocketFactory serverFactory = context.getServerSocketFactory(); SSLServerSocketFactory serverFactory = context.getServerSocketFactory();
...@@ -47,14 +45,11 @@ public class JSSEServer { ...@@ -47,14 +45,11 @@ public class JSSEServer {
System.out.println("Server: port=" + getPort()); System.out.println("Server: port=" + getPort());
} }
public void start() { public Exception start() {
new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("Server: started"); System.out.println("Server: started");
Exception exception = null;
try (SSLSocket socket = (SSLSocket) server.accept()) { try (SSLSocket socket = (SSLSocket) server.accept()) {
System.out.println("Server: accepted connection");
socket.setSoTimeout(TLSRestrictions.TIMEOUT); socket.setSoTimeout(TLSRestrictions.TIMEOUT);
InputStream sslIS = socket.getInputStream(); InputStream sslIS = socket.getInputStream();
OutputStream sslOS = socket.getOutputStream(); OutputStream sslOS = socket.getOutputStream();
...@@ -62,20 +57,16 @@ public class JSSEServer { ...@@ -62,20 +57,16 @@ public class JSSEServer {
sslOS.write('S'); sslOS.write('S');
sslOS.flush(); sslOS.flush();
System.out.println("Server: finished"); System.out.println("Server: finished");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(System.out);
exception = e; exception = e;
e.printStackTrace(System.out);
System.out.println("Server: failed");
} }
}
}).start(); return exception;
} }
public int getPort() { public int getPort() {
return server.getLocalPort(); return server.getLocalPort();
} }
public Exception getException() {
return exception;
}
} }
/* /*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,6 +36,10 @@ import java.security.cert.Certificate; ...@@ -36,6 +36,10 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateFactory; import java.security.cert.CertificateFactory;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64; import java.util.Base64;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.KeyManagerFactory;
...@@ -210,11 +214,13 @@ public class TLSRestrictions { ...@@ -210,11 +214,13 @@ public class TLSRestrictions {
needClientAuth, needClientAuth,
pass); pass);
setConstraint("Server", serverConstraint); setConstraint("Server", serverConstraint);
ExecutorService executor = Executors.newFixedThreadPool(1);
try {
JSSEServer server = new JSSEServer( JSSEServer server = new JSSEServer(
createSSLContext(trustNames, certNames), createSSLContext(trustNames, certNames),
needClientAuth); needClientAuth);
int port = server.getPort(); int port = server.getPort();
server.start(); Future<Exception> serverFuture = executor.submit(() -> server.start());
// Run client on another JVM so that its properties cannot be in conflict // Run client on another JVM so that its properties cannot be in conflict
// with server's. // with server's.
...@@ -228,18 +234,13 @@ public class TLSRestrictions { ...@@ -228,18 +234,13 @@ public class TLSRestrictions {
trustNameStr, trustNameStr,
certNameStr, certNameStr,
clientConstraint); clientConstraint);
int exitValue = outputAnalyzer.getExitValue(); int clientExitValue = outputAnalyzer.getExitValue();
String clientOut = outputAnalyzer.getOutput(); String clientOut = outputAnalyzer.getOutput();
Exception serverException = server.getException();
if (serverException != null) {
System.out.println("Server: failed");
}
System.out.println("---------- Client output start ----------"); System.out.println("---------- Client output start ----------");
System.out.println(clientOut); System.out.println(clientOut);
System.out.println("---------- Client output end ----------"); System.out.println("---------- Client output end ----------");
Exception serverException = serverFuture.get(TIMEOUT, TimeUnit.MILLISECONDS);
if (serverException instanceof SocketTimeoutException if (serverException instanceof SocketTimeoutException
|| clientOut.contains("SocketTimeoutException")) { || clientOut.contains("SocketTimeoutException")) {
System.out.println("The communication gets timeout and skips the test."); System.out.println("The communication gets timeout and skips the test.");
...@@ -247,12 +248,12 @@ public class TLSRestrictions { ...@@ -247,12 +248,12 @@ public class TLSRestrictions {
} }
if (pass) { if (pass) {
if (serverException != null || exitValue != 0) { if (serverException != null || clientExitValue != 0) {
throw new RuntimeException( throw new RuntimeException(
"Unexpected failure. Operation was blocked."); "Unexpected failure. Operation was blocked.");
} }
} else { } else {
if (serverException == null && exitValue == 0) { if (serverException == null && clientExitValue == 0) {
throw new RuntimeException( throw new RuntimeException(
"Unexpected pass. Operation was allowed."); "Unexpected pass. Operation was allowed.");
} }
...@@ -263,6 +264,9 @@ public class TLSRestrictions { ...@@ -263,6 +264,9 @@ public class TLSRestrictions {
throw new RuntimeException("Failure with unexpected exception."); throw new RuntimeException("Failure with unexpected exception.");
} }
} }
} finally {
executor.shutdown();
}
} }
/* /*
...@@ -513,7 +517,6 @@ public class TLSRestrictions { ...@@ -513,7 +517,6 @@ public class TLSRestrictions {
true); true);
break; break;
} }
System.out.println("Case passed"); System.out.println("Case passed");
System.out.println("========================================"); System.out.println("========================================");
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册