Skip to content

Commit 6a7ddb9

Browse files
committed
8344629: SSLSocketNoServerHelloClientShutdown test timeout
Backport-of: 2207749c8915a4b65faec51948a183f4bb6ae20f
1 parent 94afa91 commit 6a7ddb9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/jdk/sun/security/ssl/SSLCipher/SSLSocketNoServerHelloClientShutdown.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
import static jdk.test.lib.security.SecurityUtils.inspectTlsBuffer;
3737

3838
import java.io.InputStream;
39+
import java.lang.Override;
3940
import java.net.InetSocketAddress;
4041
import java.nio.channels.SocketChannel;
4142
import java.security.GeneralSecurityException;
42-
43+
import java.util.concurrent.CountDownLatch;
4344
import javax.net.ssl.SSLContext;
4445
import javax.net.ssl.SSLEngineResult;
4546
import javax.net.ssl.SSLEngineResult.Status;
@@ -52,19 +53,23 @@
5253
* To reproduce @bug 8331682 (client sends an unencrypted TLS alert during
5354
* TLSv1.3 handshake) with SSLSockets we use an SSLSocket on the server side
5455
* and a plain TCP socket backed by SSLEngine on the client side.
56+
* Using SSLEngine allows the client to force the generation of the plaintext
57+
* alert messages.
5558
*/
5659
public class SSLSocketNoServerHelloClientShutdown
5760
extends SSLEngineNoServerHelloClientShutdown {
5861

5962
private volatile Exception clientException;
6063
private volatile Exception serverException;
64+
private final CountDownLatch serverLatch;
6165

6266
public static void main(String[] args) throws Exception {
6367
new SSLSocketNoServerHelloClientShutdown().runTest();
6468
}
6569

6670
public SSLSocketNoServerHelloClientShutdown() throws Exception {
6771
super();
72+
serverLatch = new CountDownLatch(1);
6873
}
6974

7075
private void runTest() throws Exception {
@@ -84,7 +89,6 @@ private void runTest() throws Exception {
8489
try {
8590
// Server-side SSL socket that will read.
8691
SSLSocket socket = (SSLSocket) serverSocket.accept();
87-
socket.setSoTimeout(2000);
8892
InputStream is = socket.getInputStream();
8993
byte[] inbound = new byte[512];
9094

@@ -96,10 +100,12 @@ private void runTest() throws Exception {
96100
serverException = e;
97101
log(e.toString());
98102
} finally {
103+
serverLatch.countDown();
99104
thread.join();
100105
}
101106
} finally {
102107
if (serverException != null) {
108+
serverException.printStackTrace();
103109
assertEquals(
104110
SSLProtocolException.class, serverException.getClass());
105111
assertEquals(GeneralSecurityException.class,
@@ -125,7 +131,6 @@ public void run() {
125131
new InetSocketAddress("localhost", port))) {
126132

127133
SSLEngineResult clientResult;
128-
clientSocketChannel.socket().setSoTimeout(500);
129134

130135
log("=================");
131136

@@ -162,9 +167,7 @@ public void run() {
162167
log("---Client sends unencrypted alerts---");
163168
int len = clientSocketChannel.write(cTOs);
164169

165-
// Give server a chance to read before we shutdown via
166-
// the try-with-resources block.
167-
Thread.sleep(2000);
170+
serverLatch.await();
168171
} catch (Exception e) {
169172
clientException = e;
170173
}

0 commit comments

Comments
 (0)