Skip to content

Commit 79adc16

Browse files
fgualliniXueleiFan
authored andcommittedApr 16, 2021
8264152: javax/net/ssl/DTLS/RespondToRetransmit.java timed out
Reviewed-by: xuelei
1 parent 1c3fd46 commit 79adc16

File tree

3 files changed

+170
-222
lines changed

3 files changed

+170
-222
lines changed
 

‎test/jdk/javax/net/ssl/DTLS/DTLSOverDatagram.java

+164-216
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,33 +50,33 @@
5050
*/
5151
public class DTLSOverDatagram {
5252

53-
private static int MAX_HANDSHAKE_LOOPS = 200;
54-
private static int MAX_APP_READ_LOOPS = 60;
55-
private static int SOCKET_TIMEOUT = 10 * 1000; // in millis
56-
private static int BUFFER_SIZE = 1024;
57-
private static int MAXIMUM_PACKET_SIZE = 1024;
53+
private static final int MAX_HANDSHAKE_LOOPS = 200;
54+
private static final int MAX_APP_READ_LOOPS = 60;
55+
private static final int SOCKET_TIMEOUT = 10 * 1000; // in millis
56+
private static final int BUFFER_SIZE = 1024;
57+
private static final int MAXIMUM_PACKET_SIZE = 1024;
5858

5959
/*
6060
* The following is to set up the keystores.
6161
*/
62-
private static String pathToStores = "../etc";
63-
private static String keyStoreFile = "keystore";
64-
private static String trustStoreFile = "truststore";
65-
66-
private static String keyFilename =
67-
System.getProperty("test.src", ".") + "/" + pathToStores +
68-
"/" + keyStoreFile;
69-
private static String trustFilename =
70-
System.getProperty("test.src", ".") + "/" + pathToStores +
71-
"/" + trustStoreFile;
72-
private static Exception clientException = null;
73-
private static Exception serverException = null;
74-
75-
private static ByteBuffer serverApp =
62+
private static final String PATH_TO_STORES = "../etc";
63+
private static final String KEY_STORE_FILE = "keystore";
64+
private static final String TRUST_STORE_FILE = "truststore";
65+
66+
private static final String KEY_FILENAME =
67+
System.getProperty("test.src", ".") + "/" + PATH_TO_STORES +
68+
"/" + KEY_STORE_FILE;
69+
private static final String TRUST_FILENAME =
70+
System.getProperty("test.src", ".") + "/" + PATH_TO_STORES +
71+
"/" + TRUST_STORE_FILE;
72+
73+
private static final ByteBuffer SERVER_APP =
7674
ByteBuffer.wrap("Hi Client, I'm Server".getBytes());
77-
private static ByteBuffer clientApp =
75+
private static final ByteBuffer CLIENT_APP =
7876
ByteBuffer.wrap("Hi Server, I'm Client".getBytes());
7977

78+
private static Exception clientException = null;
79+
private static Exception serverException = null;
8080
/*
8181
* =============================================================
8282
* The test case
@@ -91,37 +91,39 @@ public static void main(String[] args) throws Exception {
9191
*/
9292
void doServerSide(DatagramSocket socket, InetSocketAddress clientSocketAddr)
9393
throws Exception {
94+
String side = "Server";
9495

9596
// create SSLEngine
9697
SSLEngine engine = createSSLEngine(false);
9798

9899
// handshaking
99-
handshake(engine, socket, clientSocketAddr, "Server");
100+
handshake(engine, socket, clientSocketAddr, side);
100101

101102
// read client application data
102-
receiveAppData(engine, socket, clientApp);
103+
receiveAppData(engine, socket, CLIENT_APP);
103104

104105
// write server application data
105-
deliverAppData(engine, socket, serverApp, clientSocketAddr);
106+
deliverAppData(engine, socket, SERVER_APP, clientSocketAddr, side);
106107
}
107108

108109
/*
109110
* Define the client side of the test.
110111
*/
111112
void doClientSide(DatagramSocket socket, InetSocketAddress serverSocketAddr)
112113
throws Exception {
114+
String side = "Client";
113115

114116
// create SSLEngine
115117
SSLEngine engine = createSSLEngine(true);
116118

117119
// handshaking
118-
handshake(engine, socket, serverSocketAddr, "Client");
120+
handshake(engine, socket, serverSocketAddr, side);
119121

120122
// write client application data
121-
deliverAppData(engine, socket, clientApp, serverSocketAddr);
123+
deliverAppData(engine, socket, CLIENT_APP, serverSocketAddr, side);
122124

123125
// read server application data
124-
receiveAppData(engine, socket, serverApp);
126+
receiveAppData(engine, socket, SERVER_APP);
125127
}
126128

127129
/*
@@ -153,117 +155,94 @@ void handshake(SSLEngine engine, DatagramSocket socket,
153155

154156
if (--loops < 0) {
155157
throw new RuntimeException(
156-
"Too much loops to produce handshake packets");
158+
"Too many loops to produce handshake packets");
157159
}
158160

159161
SSLEngineResult.HandshakeStatus hs = engine.getHandshakeStatus();
160162
log(side, "=======handshake(" + loops + ", " + hs + ")=======");
161-
if (hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP ||
162-
hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP_AGAIN) {
163-
164-
log(side, "Receive DTLS records, handshake status is " + hs);
165-
166-
ByteBuffer iNet;
167-
ByteBuffer iApp;
168-
if (hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) {
169-
byte[] buf = new byte[BUFFER_SIZE];
170-
DatagramPacket packet = new DatagramPacket(buf, buf.length);
171-
try {
172-
socket.receive(packet);
173-
} catch (SocketTimeoutException ste) {
174-
log(side, "Warning: " + ste);
175-
176-
List<DatagramPacket> packets = new ArrayList<>();
177-
boolean finished = onReceiveTimeout(
178-
engine, peerAddr, side, packets);
179-
180-
log(side, "Reproduced " + packets.size() + " packets");
181-
for (DatagramPacket p : packets) {
182-
printHex("Reproduced packet",
183-
p.getData(), p.getOffset(), p.getLength());
184-
socket.send(p);
185-
}
186163

187-
if (finished) {
188-
log(side, "Handshake status is FINISHED "
189-
+ "after calling onReceiveTimeout(), "
190-
+ "finish the loop");
191-
endLoops = true;
164+
switch (hs) {
165+
case NEED_UNWRAP, NEED_UNWRAP_AGAIN -> {
166+
log(side, "Receive DTLS records, handshake status is " + hs);
167+
168+
ByteBuffer iNet;
169+
ByteBuffer iApp;
170+
171+
if (hs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) {
172+
byte[] buf = new byte[BUFFER_SIZE];
173+
DatagramPacket packet = new DatagramPacket(buf, buf.length);
174+
try {
175+
socket.receive(packet);
176+
} catch (SocketTimeoutException ste) {
177+
log(side, "Warning: " + ste);
178+
179+
List<DatagramPacket> packets = new ArrayList<>();
180+
boolean finished = onReceiveTimeout(
181+
engine, peerAddr, side, packets);
182+
183+
log(side, "Reproduced " + packets.size() + " packets");
184+
for (DatagramPacket p : packets) {
185+
printHex("Reproduced packet",
186+
p.getData(), p.getOffset(), p.getLength());
187+
socket.send(p);
188+
}
189+
190+
if (finished) {
191+
log(side, "Handshake status is FINISHED "
192+
+ "after calling onReceiveTimeout(), "
193+
+ "finish the loop");
194+
endLoops = true;
195+
}
196+
197+
log(side, "New handshake status is "
198+
+ engine.getHandshakeStatus());
199+
200+
continue;
192201
}
193202

194-
log(side, "New handshake status is "
195-
+ engine.getHandshakeStatus());
196-
197-
continue;
203+
iNet = ByteBuffer.wrap(buf, 0, packet.getLength());
204+
} else {
205+
iNet = ByteBuffer.allocate(0);
198206
}
199207

200-
iNet = ByteBuffer.wrap(buf, 0, packet.getLength());
201-
iApp = ByteBuffer.allocate(BUFFER_SIZE);
202-
} else {
203-
iNet = ByteBuffer.allocate(0);
204208
iApp = ByteBuffer.allocate(BUFFER_SIZE);
205-
}
206209

207-
SSLEngineResult r = engine.unwrap(iNet, iApp);
208-
SSLEngineResult.Status rs = r.getStatus();
209-
hs = r.getHandshakeStatus();
210-
if (rs == SSLEngineResult.Status.OK) {
211-
// OK
212-
} else if (rs == SSLEngineResult.Status.BUFFER_OVERFLOW) {
213-
log(side, "BUFFER_OVERFLOW, handshake status is " + hs);
214-
215-
// the client maximum fragment size config does not work?
216-
throw new Exception("Buffer overflow: " +
217-
"incorrect client maximum fragment size");
218-
} else if (rs == SSLEngineResult.Status.BUFFER_UNDERFLOW) {
219-
log(side, "BUFFER_UNDERFLOW, handshake status is " + hs);
210+
SSLEngineResult r = engine.unwrap(iNet, iApp);
211+
hs = r.getHandshakeStatus();
220212

221-
// bad packet, or the client maximum fragment size
222-
// config does not work?
223-
if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
224-
throw new Exception("Buffer underflow: " +
225-
"incorrect client maximum fragment size");
226-
} // otherwise, ignore this packet
227-
} else if (rs == SSLEngineResult.Status.CLOSED) {
228-
throw new Exception(
229-
"SSL engine closed, handshake status is " + hs);
230-
} else {
231-
throw new Exception("Can't reach here, result is " + rs);
213+
verifySSLEngineResultStatus(r, side);
214+
if (hs == SSLEngineResult.HandshakeStatus.FINISHED) {
215+
log(side, "Handshake status is FINISHED, finish the loop");
216+
endLoops = true;
217+
}
232218
}
219+
case NEED_WRAP -> {
220+
List<DatagramPacket> packets = new ArrayList<>();
221+
boolean finished = produceHandshakePackets(
222+
engine, peerAddr, side, packets);
223+
224+
log(side, "Produced " + packets.size() + " packets");
225+
for (DatagramPacket p : packets) {
226+
socket.send(p);
227+
}
233228

234-
if (hs == SSLEngineResult.HandshakeStatus.FINISHED) {
235-
log(side, "Handshake status is FINISHED, finish the loop");
236-
endLoops = true;
237-
}
238-
} else if (hs == SSLEngineResult.HandshakeStatus.NEED_WRAP) {
239-
List<DatagramPacket> packets = new ArrayList<>();
240-
boolean finished = produceHandshakePackets(
241-
engine, peerAddr, side, packets);
242-
243-
log(side, "Produced " + packets.size() + " packets");
244-
for (DatagramPacket p : packets) {
245-
socket.send(p);
229+
if (finished) {
230+
log(side, "Handshake status is FINISHED "
231+
+ "after producing handshake packets, "
232+
+ "finish the loop");
233+
endLoops = true;
234+
}
246235
}
247-
248-
if (finished) {
249-
log(side, "Handshake status is FINISHED "
250-
+ "after producing handshake packets, "
251-
+ "finish the loop");
236+
case NEED_TASK -> runDelegatedTasks(engine);
237+
case NOT_HANDSHAKING -> {
238+
log(side,
239+
"Handshake status is NOT_HANDSHAKING, finish the loop");
252240
endLoops = true;
253241
}
254-
} else if (hs == SSLEngineResult.HandshakeStatus.NEED_TASK) {
255-
runDelegatedTasks(engine);
256-
} else if (hs == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
257-
log(side,
258-
"Handshake status is NOT_HANDSHAKING, finish the loop");
259-
endLoops = true;
260-
} else if (hs == SSLEngineResult.HandshakeStatus.FINISHED) {
261-
throw new Exception(
262-
"Unexpected status, SSLEngine.getHandshakeStatus() "
263-
+ "shouldn't return FINISHED");
264-
} else {
265-
throw new Exception(
266-
"Can't reach here, handshake status is " + hs);
242+
case FINISHED -> throw new Exception( "Unexpected status, " +
243+
"SSLEngine.getHandshakeStatus() shouldn't return FINISHED");
244+
default -> throw new Exception("Can't reach here, " +
245+
"handshake status is " + hs);
267246
}
268247
}
269248

@@ -291,13 +270,39 @@ void handshake(SSLEngine engine, DatagramSocket socket,
291270
}
292271
}
293272

273+
void verifySSLEngineResultStatus(SSLEngineResult r, String side) throws Exception {
274+
SSLEngineResult.Status rs = r.getStatus();
275+
SSLEngineResult.HandshakeStatus hs = r.getHandshakeStatus();
276+
switch (rs) {
277+
case OK -> log(side, "SSLEngineResult status OK");
278+
case BUFFER_OVERFLOW -> {
279+
log(side, "BUFFER_OVERFLOW, handshake status is " + hs);
280+
// the client maximum fragment size config does not work?
281+
throw new Exception("Buffer overflow: " +
282+
"incorrect client maximum fragment size");
283+
}
284+
case BUFFER_UNDERFLOW -> {
285+
log(side, "BUFFER_UNDERFLOW, handshake status is " + hs);
286+
// bad packet, or the client maximum fragment size
287+
// config does not work?
288+
if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
289+
throw new Exception("Buffer underflow: " +
290+
"incorrect client maximum fragment size");
291+
} // otherwise, ignore this packet
292+
}
293+
case CLOSED -> throw new Exception(
294+
"SSL engine closed, handshake status is " + hs);
295+
default -> throw new Exception("Can't reach here, result is " + rs);
296+
}
297+
}
298+
294299
// deliver application data
295300
void deliverAppData(SSLEngine engine, DatagramSocket socket,
296-
ByteBuffer appData, SocketAddress peerAddr) throws Exception {
301+
ByteBuffer appData, SocketAddress peerAddr, String side) throws Exception {
297302

298303
// Note: have not consider the packet loses
299304
List<DatagramPacket> packets =
300-
produceApplicationPackets(engine, appData, peerAddr);
305+
produceApplicationPackets(engine, appData, peerAddr, side);
301306
appData.flip();
302307
for (DatagramPacket p : packets) {
303308
socket.send(p);
@@ -344,7 +349,7 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
344349

345350
if (--loops < 0) {
346351
throw new RuntimeException(
347-
"Too much loops to produce handshake packets");
352+
"Too many loops to produce handshake packets");
348353
}
349354

350355
ByteBuffer oNet = ByteBuffer.allocate(32768);
@@ -356,30 +361,9 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
356361
SSLEngineResult.HandshakeStatus hs = r.getHandshakeStatus();
357362
log(side, "----produce handshake packet(" +
358363
loops + ", " + rs + ", " + hs + ")----");
359-
if (rs == SSLEngineResult.Status.BUFFER_OVERFLOW) {
360-
// the client maximum fragment size config does not work?
361-
throw new Exception("Buffer overflow: " +
362-
"incorrect server maximum fragment size");
363-
} else if (rs == SSLEngineResult.Status.BUFFER_UNDERFLOW) {
364-
log(side,
365-
"Produce handshake packets: BUFFER_UNDERFLOW occured");
366-
log(side,
367-
"Produce handshake packets: Handshake status: " + hs);
368-
// bad packet, or the client maximum fragment size
369-
// config does not work?
370-
if (hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
371-
throw new Exception("Buffer underflow: " +
372-
"incorrect server maximum fragment size");
373-
} // otherwise, ignore this packet
374-
} else if (rs == SSLEngineResult.Status.CLOSED) {
375-
throw new Exception("SSLEngine has closed");
376-
} else if (rs == SSLEngineResult.Status.OK) {
377-
// OK
378-
} else {
379-
throw new Exception("Can't reach here, result is " + rs);
380-
}
381364

382-
// SSLEngineResult.Status.OK:
365+
verifySSLEngineResultStatus(r, side);
366+
383367
if (oNet.hasRemaining()) {
384368
byte[] ba = new byte[oNet.remaining()];
385369
oNet.get(ba);
@@ -396,24 +380,20 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
396380
boolean endInnerLoop = false;
397381
SSLEngineResult.HandshakeStatus nhs = hs;
398382
while (!endInnerLoop) {
399-
if (nhs == SSLEngineResult.HandshakeStatus.NEED_TASK) {
400-
runDelegatedTasks(engine);
401-
} else if (nhs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP ||
402-
nhs == SSLEngineResult.HandshakeStatus.NEED_UNWRAP_AGAIN ||
403-
nhs == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) {
404-
405-
endInnerLoop = true;
406-
endLoops = true;
407-
} else if (nhs == SSLEngineResult.HandshakeStatus.NEED_WRAP) {
408-
endInnerLoop = true;
409-
} else if (nhs == SSLEngineResult.HandshakeStatus.FINISHED) {
410-
throw new Exception(
383+
switch (nhs) {
384+
case NEED_TASK -> runDelegatedTasks(engine);
385+
case NEED_UNWRAP, NEED_UNWRAP_AGAIN, NOT_HANDSHAKING -> {
386+
endInnerLoop = true;
387+
endLoops = true;
388+
}
389+
case NEED_WRAP -> endInnerLoop = true;
390+
case FINISHED -> throw new Exception(
411391
"Unexpected status, SSLEngine.getHandshakeStatus() "
412-
+ "shouldn't return FINISHED");
413-
} else {
414-
throw new Exception("Can't reach here, handshake status is "
392+
+ "should not return FINISHED");
393+
default -> throw new Exception("Can't reach here, handshake status is "
415394
+ nhs);
416395
}
396+
417397
nhs = engine.getHandshakeStatus();
418398
}
419399
}
@@ -428,30 +408,15 @@ DatagramPacket createHandshakePacket(byte[] ba, SocketAddress socketAddr) {
428408
// produce application packets
429409
List<DatagramPacket> produceApplicationPackets(
430410
SSLEngine engine, ByteBuffer source,
431-
SocketAddress socketAddr) throws Exception {
411+
SocketAddress socketAddr, String side) throws Exception {
432412

433413
List<DatagramPacket> packets = new ArrayList<>();
434414
ByteBuffer appNet = ByteBuffer.allocate(32768);
435415
SSLEngineResult r = engine.wrap(source, appNet);
436416
appNet.flip();
437417

438-
SSLEngineResult.Status rs = r.getStatus();
439-
if (rs == SSLEngineResult.Status.BUFFER_OVERFLOW) {
440-
// the client maximum fragment size config does not work?
441-
throw new Exception("Buffer overflow: " +
442-
"incorrect server maximum fragment size");
443-
} else if (rs == SSLEngineResult.Status.BUFFER_UNDERFLOW) {
444-
// unlikely
445-
throw new Exception("Buffer underflow during wraping");
446-
} else if (rs == SSLEngineResult.Status.CLOSED) {
447-
throw new Exception("SSLEngine has closed");
448-
} else if (rs == SSLEngineResult.Status.OK) {
449-
// OK
450-
} else {
451-
throw new Exception("Can't reach here, result is " + rs);
452-
}
418+
verifySSLEngineResultStatus(r, side);
453419

454-
// SSLEngineResult.Status.OK:
455420
if (appNet.hasRemaining()) {
456421
byte[] ba = new byte[appNet.remaining()];
457422
appNet.get(ba);
@@ -472,7 +437,7 @@ static DatagramPacket getPacket(
472437
int offset = packet.getOffset();
473438
int length = packet.getLength();
474439

475-
// Normally, this pakcet should be a handshake message
440+
// Normally, this packet should be a handshake message
476441
// record. However, even if the underlying platform
477442
// splits the record more, we don't really worry about
478443
// the improper packet loss because DTLS implementation
@@ -490,12 +455,12 @@ static DatagramPacket getPacket(
490455
if (data[offset + 4] == 0x00) { // plaintext
491456
matched =
492457
(data[offset + 13] == handshakeType);
493-
} else { // cipherext
458+
} else { // ciphertext
494459
// The 1st ciphertext is a Finished message.
495460
//
496461
// If it is not proposed to loss the Finished
497462
// message, it is not necessary to check the
498-
// following packets any mroe as a Finished
463+
// following packets any more as a Finished
499464
// message is the last handshake message.
500465
matched = (handshakeType == 20);
501466
}
@@ -540,8 +505,8 @@ boolean onReceiveTimeout(SSLEngine engine, SocketAddress socketAddr,
540505
SSLContext getDTLSContext() throws Exception {
541506
String passphrase = "passphrase";
542507
return SSLContextBuilder.builder()
543-
.trustStore(KeyStoreUtils.loadKeyStore(trustFilename, passphrase))
544-
.keyStore(KeyStoreUtils.loadKeyStore(keyFilename, passphrase))
508+
.trustStore(KeyStoreUtils.loadKeyStore(TRUST_FILENAME, passphrase))
509+
.keyStore(KeyStoreUtils.loadKeyStore(KEY_FILENAME, passphrase))
545510
.kmfPassphrase(passphrase)
546511
.protocol("DTLS")
547512
.build();
@@ -559,17 +524,22 @@ public boolean isGoodJob() {
559524
}
560525

561526
public final void runTest(DTLSOverDatagram testCase) throws Exception {
562-
try (DatagramSocket serverSocket = new DatagramSocket();
563-
DatagramSocket clientSocket = new DatagramSocket()) {
527+
InetSocketAddress serverSocketAddress = new InetSocketAddress
528+
(InetAddress.getLoopbackAddress(), 0);
529+
InetSocketAddress clientSocketAddress = new InetSocketAddress
530+
(InetAddress.getLoopbackAddress(), 0);
531+
532+
try (DatagramSocket serverSocket = new DatagramSocket(serverSocketAddress);
533+
DatagramSocket clientSocket = new DatagramSocket(clientSocketAddress)) {
564534

565535
serverSocket.setSoTimeout(SOCKET_TIMEOUT);
566536
clientSocket.setSoTimeout(SOCKET_TIMEOUT);
567537

568538
InetSocketAddress serverSocketAddr = new InetSocketAddress(
569-
InetAddress.getLocalHost(), serverSocket.getLocalPort());
539+
InetAddress.getLoopbackAddress(), serverSocket.getLocalPort());
570540

571541
InetSocketAddress clientSocketAddr = new InetSocketAddress(
572-
InetAddress.getLocalHost(), clientSocket.getLocalPort());
542+
InetAddress.getLoopbackAddress(), clientSocket.getLocalPort());
573543

574544
ExecutorService pool = Executors.newFixedThreadPool(2);
575545
Future<String> server, client;
@@ -611,19 +581,8 @@ public final void runTest(DTLSOverDatagram testCase) throws Exception {
611581
}
612582
}
613583

614-
final static class ServerCallable implements Callable<String> {
615-
616-
private final DTLSOverDatagram testCase;
617-
private final DatagramSocket socket;
618-
private final InetSocketAddress clientSocketAddr;
619-
620-
ServerCallable(DTLSOverDatagram testCase, DatagramSocket socket,
621-
InetSocketAddress clientSocketAddr) {
622-
623-
this.testCase = testCase;
624-
this.socket = socket;
625-
this.clientSocketAddr = clientSocketAddr;
626-
}
584+
record ServerCallable(DTLSOverDatagram testCase, DatagramSocket socket,
585+
InetSocketAddress clientSocketAddr) implements Callable<String> {
627586

628587
@Override
629588
public String call() throws Exception {
@@ -649,19 +608,8 @@ public String call() throws Exception {
649608
}
650609
}
651610

652-
final static class ClientCallable implements Callable<String> {
653-
654-
private final DTLSOverDatagram testCase;
655-
private final DatagramSocket socket;
656-
private final InetSocketAddress serverSocketAddr;
657-
658-
ClientCallable(DTLSOverDatagram testCase, DatagramSocket socket,
659-
InetSocketAddress serverSocketAddr) {
660-
661-
this.testCase = testCase;
662-
this.socket = socket;
663-
this.serverSocketAddr = serverSocketAddr;
664-
}
611+
record ClientCallable(DTLSOverDatagram testCase, DatagramSocket socket,
612+
InetSocketAddress serverSocketAddr) implements Callable<String> {
665613

666614
@Override
667615
public String call() throws Exception {
@@ -687,7 +635,7 @@ public String call() throws Exception {
687635
}
688636
}
689637

690-
final static void printHex(String prefix, ByteBuffer bb) {
638+
static void printHex(String prefix, ByteBuffer bb) {
691639

692640
synchronized (System.out) {
693641
System.out.println(prefix);
@@ -700,7 +648,7 @@ final static void printHex(String prefix, ByteBuffer bb) {
700648
}
701649
}
702650

703-
final static void printHex(String prefix,
651+
static void printHex(String prefix,
704652
byte[] bytes, int offset, int length) {
705653

706654
synchronized (System.out) {

‎test/jdk/javax/net/ssl/DTLS/PacketLossRetransmission.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -84,7 +84,7 @@ public class PacketLossRetransmission extends DTLSOverDatagram {
8484

8585
public static void main(String[] args) throws Exception {
8686
isClient = args[0].equals("client");
87-
handshakeType = Byte.valueOf(args[1]);
87+
handshakeType = Byte.parseByte(args[1]);
8888

8989
PacketLossRetransmission testCase = new PacketLossRetransmission();
9090
testCase.runTest(testCase);
@@ -97,7 +97,7 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
9797
boolean finished = super.produceHandshakePackets(
9898
engine, socketAddr, side, packets);
9999

100-
if (needPacketLoss && (!(isClient ^ engine.getUseClientMode()))) {
100+
if (needPacketLoss && (isClient == engine.getUseClientMode())) {
101101
DatagramPacket packet = getPacket(packets, handshakeType);
102102
if (packet != null) {
103103
needPacketLoss = false;

‎test/jdk/javax/net/ssl/DTLS/RespondToRetransmit.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -85,7 +85,7 @@ public class RespondToRetransmit extends DTLSOverDatagram {
8585

8686
public static void main(String[] args) throws Exception {
8787
isClient = args[0].equals("client");
88-
handshakeType = Byte.valueOf(args[1]);
88+
handshakeType = Byte.parseByte(args[1]);
8989

9090
RespondToRetransmit testCase = new RespondToRetransmit();
9191
testCase.runTest(testCase);
@@ -98,7 +98,7 @@ boolean produceHandshakePackets(SSLEngine engine, SocketAddress socketAddr,
9898
boolean finished = super.produceHandshakePackets(
9999
engine, socketAddr, side, packets);
100100

101-
if (needPacketDuplicate && (!(isClient ^ engine.getUseClientMode()))) {
101+
if (needPacketDuplicate && (isClient == engine.getUseClientMode())) {
102102
DatagramPacket packet = getPacket(packets, handshakeType);
103103
if (packet != null) {
104104
needPacketDuplicate = false;

0 commit comments

Comments
 (0)
Please sign in to comment.