mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-12 14:39:49 +00:00
8167146: sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java failed with "Remote host terminated the handshake"
The fix takes the server to accept request after the client threads start, and also deal with possible timeout issue. Reviewed-by: xuelei
This commit is contained in:
parent
9d3f1e001a
commit
48706a1a2a
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -28,7 +28,6 @@ import java.util.concurrent.*;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.Certificate;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
|
||||
@ -61,6 +60,8 @@ public class CipherTest {
|
||||
|
||||
private static PeerFactory peerFactory;
|
||||
|
||||
static final CountDownLatch clientCondition = new CountDownLatch(1);
|
||||
|
||||
static abstract class Server implements Runnable {
|
||||
|
||||
final CipherTest cipherTest;
|
||||
@ -313,6 +314,10 @@ public class CipherTest {
|
||||
}
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
// The client threads are ready.
|
||||
clientCondition.countDown();
|
||||
|
||||
try {
|
||||
for (int i = 0; i < THREADS; i++) {
|
||||
threads[i].join();
|
||||
@ -367,6 +372,10 @@ public class CipherTest {
|
||||
try {
|
||||
runTest(params);
|
||||
System.out.println("Passed " + params);
|
||||
} catch (SocketTimeoutException ste) {
|
||||
System.out.println("The client connects to the server timeout, "
|
||||
+ "so ignore the test.");
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
cipherTest.setFailed();
|
||||
System.out.println("** Failed " + params + "**");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,10 +23,7 @@
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.cert.*;
|
||||
import java.security.cert.Certificate;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
@ -46,10 +43,30 @@ class JSSEClient extends CipherTest.Client {
|
||||
SSLSocket socket = null;
|
||||
try {
|
||||
keyManager.setAuthType(params.clientAuth);
|
||||
sslContext.init(new KeyManager[] {keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom);
|
||||
SSLSocketFactory factory = (SSLSocketFactory)sslContext.getSocketFactory();
|
||||
socket = (SSLSocket)factory.createSocket("127.0.0.1", cipherTest.serverPort);
|
||||
socket.setSoTimeout(cipherTest.TIMEOUT);
|
||||
sslContext.init(
|
||||
new KeyManager[] { keyManager },
|
||||
new TrustManager[] { CipherTest.trustManager },
|
||||
CipherTest.secureRandom);
|
||||
SSLSocketFactory factory
|
||||
= (SSLSocketFactory) sslContext.getSocketFactory();
|
||||
|
||||
socket = (SSLSocket) factory.createSocket();
|
||||
try {
|
||||
socket.connect(new InetSocketAddress("127.0.0.1",
|
||||
CipherTest.serverPort), 15000);
|
||||
} catch (IOException ioe) {
|
||||
// The server side may be impacted by naughty test cases or
|
||||
// third party routines, and cannot accept connections.
|
||||
//
|
||||
// Just ignore the test if the connection cannot be
|
||||
// established.
|
||||
System.out.println(
|
||||
"Cannot make a connection in 15 seconds. " +
|
||||
"Ignore in client side.");
|
||||
return;
|
||||
}
|
||||
|
||||
socket.setSoTimeout(CipherTest.TIMEOUT);
|
||||
socket.setEnabledCipherSuites(new String[] {params.cipherSuite});
|
||||
socket.setEnabledProtocols(new String[] {params.protocol});
|
||||
InputStream in = socket.getInputStream();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -24,8 +24,11 @@
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
@ -40,24 +43,37 @@ class JSSEServer extends CipherTest.Server {
|
||||
JSSEServer(CipherTest cipherTest) throws Exception {
|
||||
super(cipherTest);
|
||||
SSLContext serverContext = SSLContext.getInstance("TLS");
|
||||
serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom);
|
||||
serverContext.init(
|
||||
new KeyManager[] { CipherTest.keyManager },
|
||||
new TrustManager[] { CipherTest.trustManager },
|
||||
CipherTest.secureRandom);
|
||||
|
||||
SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
|
||||
serverSocket = (SSLServerSocket)factory.createServerSocket(0);
|
||||
cipherTest.serverPort = serverSocket.getLocalPort();
|
||||
serverSocket.setSoTimeout(CipherTest.TIMEOUT);
|
||||
CipherTest.serverPort = serverSocket.getLocalPort();
|
||||
serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
|
||||
serverSocket.setWantClientAuth(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("JSSE Server listening on port " + cipherTest.serverPort);
|
||||
System.out.println("JSSE Server listening on port " + CipherTest.serverPort);
|
||||
Executor exec = Executors.newFixedThreadPool
|
||||
(CipherTest.THREADS, DaemonThreadFactory.INSTANCE);
|
||||
|
||||
try {
|
||||
if (!CipherTest.clientCondition.await(CipherTest.TIMEOUT,
|
||||
TimeUnit.MILLISECONDS)) {
|
||||
System.out.println(
|
||||
"The client is not the expected one or timeout. "
|
||||
+ "Ignore in server side.");
|
||||
return;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
final SSLSocket socket = (SSLSocket)serverSocket.accept();
|
||||
socket.setSoTimeout(cipherTest.TIMEOUT);
|
||||
socket.setSoTimeout(CipherTest.TIMEOUT);
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -86,11 +102,12 @@ class JSSEServer extends CipherTest.Server {
|
||||
};
|
||||
exec.execute(r);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (SocketTimeoutException ste) {
|
||||
System.out.println("The server got timeout for waiting for the connection, "
|
||||
+ "so ignore the test.");
|
||||
} catch (Exception e) {
|
||||
cipherTest.setFailed();
|
||||
e.printStackTrace();
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user