Skip to content

Commit 3974375

Browse files
committed
SeleniumHQ#604: add tests about HELLO_REQUEST reception message.
1 parent d15652e commit 3974375

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

scandium-core/src/main/java/org/eclipse/californium/scandium/DTLSConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ private void sendFlight(DTLSFlight flight) {
14711471
}
14721472
}
14731473

1474-
private void sendRecord(Record record) throws IOException {
1474+
protected void sendRecord(Record record) throws IOException {
14751475
byte[] recordBytes = record.toByteArray();
14761476
DatagramPacket datagram = new DatagramPacket(recordBytes, recordBytes.length, record.getPeerAddress());
14771477
sendNextDatagramOverNetwork(datagram);

scandium-core/src/test/java/org/eclipse/californium/scandium/DTLSConnectorTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
import org.eclipse.californium.scandium.dtls.HandshakeMessage;
9393
import org.eclipse.californium.scandium.dtls.HandshakeType;
9494
import org.eclipse.californium.scandium.dtls.Handshaker;
95+
import org.eclipse.californium.scandium.dtls.HelloRequest;
9596
import org.eclipse.californium.scandium.dtls.HelloVerifyRequest;
9697
import org.eclipse.californium.scandium.dtls.InMemoryConnectionStore;
9798
import org.eclipse.californium.scandium.dtls.InMemorySessionCache;
@@ -1676,6 +1677,26 @@ public void testDestroyClearsConnectionStore() throws Exception {
16761677
assertThat(clientConnectionStore.get(serverEndpoint), is(nullValue()));
16771678
}
16781679

1680+
@Test
1681+
public void testNoRenegotiationOnHelloRequest() throws Exception {
1682+
givenAnEstablishedSession(false);
1683+
1684+
// Catch alert receive by the server
1685+
SingleAlertCatcher alertCatcher = new SingleAlertCatcher();
1686+
server.setAlertHandler(alertCatcher);
1687+
1688+
// send a HELLO_REQUEST message to the client
1689+
server.sendRecord(new Record(ContentType.HANDSHAKE, establishedServerSession.getWriteEpoch(),
1690+
establishedServerSession.getSequenceNumber(), new HelloRequest(clientEndpoint),
1691+
establishedServerSession));
1692+
1693+
// ensure client answer with a NO_RENOGIATION alert
1694+
AlertMessage alert = alertCatcher.waitForFirstAlert(MAX_TIME_TO_WAIT_SECS, TimeUnit.SECONDS);
1695+
assertNotNull("Server does not receive alert as answer of HELLO_REQUEST", alert);
1696+
assertEquals("Client must answer to HELLO_REQUEST with a NO_RENEGOTIATION alert", AlertDescription.NO_RENEGOTIATION, alert.getDescription());
1697+
assertEquals("NO_RENEGOTIATION alert MUST be a warning", AlertLevel.WARNING, alert.getLevel());
1698+
}
1699+
16791700
private ClientHello createClientHello() {
16801701
return createClientHello(null);
16811702
}
@@ -2060,4 +2081,30 @@ public void sendRecord(InetSocketAddress peerAddress, byte[] record) throws IOEx
20602081
}
20612082
}
20622083
}
2084+
2085+
private class SingleAlertCatcher implements AlertHandler {
2086+
2087+
private CountDownLatch latch = new CountDownLatch(1);
2088+
private AlertMessage alert;
2089+
2090+
@Override
2091+
public void onAlert(InetSocketAddress peer, AlertMessage alert) {
2092+
if (latch.getCount() != 0) {
2093+
this.alert = alert;
2094+
latch.countDown();
2095+
}
2096+
}
2097+
2098+
/**
2099+
* @return {@code AlertMessage} if the count reached zero and {@code n}
2100+
* if the waiting time elapsed before the count reached zero
2101+
*/
2102+
public AlertMessage waitForFirstAlert(long timeout, TimeUnit unit) throws InterruptedException {
2103+
if (latch.await(timeout, unit)) {
2104+
return alert;
2105+
} else {
2106+
return null;
2107+
}
2108+
}
2109+
}
20632110
}

0 commit comments

Comments
 (0)