Skip to content

Commit b440ece

Browse files
committed
Re-arm the DTLS 1.3 retained-epoch application data test, relates to github #1468.
1 parent af96b84 commit b440ece

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

‎tls/src/test/java/org/bouncycastle/tls/DTLSRecordLayer13Test.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,29 @@ public void testMultipleRecordsInOneDatagram() throws Exception
158158

159159
public void testApplicationDataAfterHandshakeWithRetransmitState() throws Exception
160160
{
161-
setUpPair(CipherSuite.TLS_AES_128_GCM_SHA256, CryptoHashAlgorithm.sha256);
162-
163-
// A real handshake hands the record layer a retransmit handler; in DTLS 1.3 mode it must not
164-
// put the write epoch into the legacy "retransmit" state that reclassifies sends as handshake.
161+
// A real handshake hands the record layer a retransmit handler, which retains the handshake epoch
162+
// (RFC 9147 5.8.1) for as long as a retransmitted final flight might still arrive. Drive that
163+
// retention through the harness itself - calling handshakeSuccessful a second time here would find
164+
// nothing left to retain, since the harness's own completed-handshake transition already cleared it.
165165
DTLSHandshakeRetransmit retransmit = new DTLSHandshakeRetransmit()
166166
{
167167
public void receivedHandshakeRecord(int epoch, byte[] buf, int off, int len)
168168
{
169169
}
170170
};
171-
client.recordLayer.handshakeSuccessful(retransmit);
171+
172+
support = new DTLSRecordLayer13TestSupport();
173+
support.setUpPair(CipherSuite.TLS_AES_128_GCM_SHA256, CryptoHashAlgorithm.sha256, retransmit, retransmit);
174+
clientToServer = support.clientToServer;
175+
serverToClient = support.serverToClient;
176+
client = support.client;
177+
server = support.server;
178+
179+
// In DTLS 1.3 mode the retained handshake epoch must never become the write epoch: resetWriteEpoch
180+
// puts it there anyway (it is DTLS 1.2 only, guarded at its sole call site in
181+
// DTLSReliableHandshake.resendOutboundFlight by !isDTLS13()), so calling it directly here forces
182+
// exactly the state sendReturningRecordNumber's own dtls13 guard must not be fooled by.
183+
client.recordLayer.resetWriteEpoch();
172184

173185
byte[] data = new byte[]{ 0x14, 0x15, 0x16 }; // first byte would parse as handshake type finished (20)
174186
client.recordLayer.send(data, 0, data.length);

‎tls/src/test/java/org/bouncycastle/tls/DTLSRecordLayer13TestSupport.java‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ static class Side
121121
Side client, server;
122122

123123
void setUpPair(int cipherSuite, int hash) throws IOException
124+
{
125+
setUpPair(cipherSuite, hash, null, null);
126+
}
127+
128+
/**
129+
* As {@link #setUpPair(int, int)}, but each side's completed-handshake transition is driven with its own
130+
* {@link DTLSHandshakeRetransmit}, retaining the handshake epoch (RFC 9147 5.8.1) for that side instead of
131+
* dropping it. Pass null for a side that should complete the handshake with nothing retained, exactly as
132+
* {@link #setUpPair(int, int)} does for both sides.
133+
*/
134+
void setUpPair(int cipherSuite, int hash, DTLSHandshakeRetransmit clientRetransmit,
135+
DTLSHandshakeRetransmit serverRetransmit) throws IOException
124136
{
125137
TlsCrypto crypto = new BcTlsCrypto();
126138
byte[] clientSecret = new byte[48];
@@ -132,13 +144,14 @@ void setUpPair(int cipherSuite, int hash) throws IOException
132144
serverToClient = new Queue();
133145

134146
client = createSide(crypto, false, cipherSuite, hash, clientSecret, serverSecret,
135-
new QueueTransport(serverToClient, clientToServer));
147+
new QueueTransport(serverToClient, clientToServer), clientRetransmit);
136148
server = createSide(crypto, true, cipherSuite, hash, clientSecret, serverSecret,
137-
new QueueTransport(clientToServer, serverToClient));
149+
new QueueTransport(clientToServer, serverToClient), serverRetransmit);
138150
}
139151

140152
private static Side createSide(TlsCrypto crypto, boolean isServer, int cipherSuite, int hash,
141-
byte[] clientSecret, byte[] serverSecret, DatagramTransport transport) throws IOException
153+
byte[] clientSecret, byte[] serverSecret, DatagramTransport transport,
154+
DTLSHandshakeRetransmit retransmit) throws IOException
142155
{
143156
AbstractTlsContext context = TlsAEADCipherDTLS13Test.createContext(crypto, isServer, cipherSuite, hash,
144157
clientSecret, serverSecret);
@@ -166,7 +179,7 @@ public TlsAuthentication getAuthentication()
166179
checkEquals(3, recordLayer.getPendingEpoch());
167180
recordLayer.enablePendingEpochWrite();
168181
recordLayer.enablePendingEpochRead();
169-
recordLayer.handshakeSuccessful(null);
182+
recordLayer.handshakeSuccessful(retransmit);
170183

171184
checkEquals(3, recordLayer.getReadEpoch());
172185

0 commit comments

Comments
 (0)