Skip to content

Commit 7d77446

Browse files
authored
Merge pull request wolfSSL#8882 from rizlik/dtls13_always_transmit_explicit_ack
dtls13: always send ACKs on detected retransmission
2 parents d392951 + e82c099 commit 7d77446

File tree

5 files changed

+90
-4
lines changed

5 files changed

+90
-4
lines changed

src/dtls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ static int Dtls13RtxMsgRecvd(WOLFSSL* ssl, enum HandShakeType hs,
905905
/* the other peer may have retransmitted because an ACK for a flight
906906
that needs explicit ACK was lost.*/
907907
if (ssl->dtls13Rtx.seenRecords != NULL)
908-
ssl->dtls13Rtx.sendAcks = (byte)ssl->options.dtls13SendMoreAcks;
908+
ssl->dtls13Rtx.sendAcks = 1;
909909
}
910910

911911
if (ssl->keys.dtls_peer_handshake_number ==

src/ssl.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12817,6 +12817,13 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1281712817
if (ssl == NULL)
1281812818
return 0;
1281912819

12820+
#if defined(WOLFSSL_DTLS13) && !defined(WOLFSSL_NO_CLIENT)
12821+
if (ssl->options.side == WOLFSSL_CLIENT_END && ssl->options.dtls
12822+
&& IsAtLeastTLSv1_3(ssl->version)) {
12823+
return ssl->options.serverState == SERVER_FINISHED_ACKED;
12824+
}
12825+
#endif /* WOLFSSL_DTLS13 && !WOLFSSL_NO_CLIENT */
12826+
1282012827
/* Can't use ssl->options.connectState and ssl->options.acceptState
1282112828
* because they differ in meaning for TLS <=1.2 and 1.3 */
1282212829
if (ssl->options.handShakeState == HANDSHAKE_DONE)
@@ -26762,4 +26769,3 @@ void wolfSSL_FIPS_drbg_set_app_data(WOLFSSL_DRBG_CTX *ctx, void *app_data)
2676226769

2676326770

2676426771
#endif /* !WOLFCRYPT_ONLY */
26765-

tests/api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66090,8 +66090,7 @@ static int test_dtls13_missing_finished_server(void)
6609066090
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
6609166091
/* Let's clear the output */
6609266092
test_memio_clear_buffer(&test_ctx, 0);
66093-
/* We should signal that the handshake is done */
66094-
ExpectTrue(wolfSSL_is_init_finished(ssl_c));
66093+
ExpectFalse(wolfSSL_is_init_finished(ssl_c));
6609566094
/* Let's send some app data */
6609666095
ExpectIntEQ(wolfSSL_write(ssl_c, test_str, sizeof(test_str)),
6609766096
sizeof(test_str));
@@ -68496,6 +68495,7 @@ TEST_CASE testCases[] = {
6849668495
TEST_DECL(test_wolfSSL_dtls_cid_parse),
6849768496
TEST_DECL(test_dtls13_epochs),
6849868497
TEST_DECL(test_dtls_rtx_across_epoch_change),
68498+
TEST_DECL(test_dtls_drop_client_ack),
6849968499
TEST_DECL(test_dtls13_ack_order),
6850068500
TEST_DECL(test_dtls_version_checking),
6850168501
TEST_DECL(test_ocsp_status_callback),

tests/api/test_dtls.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,3 +1383,82 @@ int test_dtls_rtx_across_epoch_change(void)
13831383
defined(WOLFSSL_DTLS13) */
13841384
return EXPECT_RESULT();
13851385
}
1386+
int test_dtls_drop_client_ack(void)
1387+
{
1388+
EXPECT_DECLS;
1389+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
1390+
defined(WOLFSSL_DTLS13) && defined(WOLFSSL_DTLS)
1391+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
1392+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1393+
struct test_memio_ctx test_ctx;
1394+
char data[32];
1395+
1396+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
1397+
1398+
/* Setup DTLS contexts */
1399+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
1400+
wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method),
1401+
0);
1402+
1403+
/* disable new session ticket to simplify testing */
1404+
ExpectIntEQ(wolfSSL_no_ticket_TLSv13(ssl_s), 0);
1405+
1406+
/* CH0 */
1407+
wolfSSL_SetLoggingPrefix("client:");
1408+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
1409+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
1410+
1411+
/* HRR */
1412+
wolfSSL_SetLoggingPrefix("server:");
1413+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
1414+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
1415+
1416+
/* CH1 */
1417+
wolfSSL_SetLoggingPrefix("client:");
1418+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
1419+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
1420+
1421+
/* SH ... FINISHED */
1422+
wolfSSL_SetLoggingPrefix("server:");
1423+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
1424+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
1425+
1426+
/* ... FINISHED */
1427+
wolfSSL_SetLoggingPrefix("client:");
1428+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
1429+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
1430+
1431+
/* init is finished should return false at this point */
1432+
ExpectFalse(wolfSSL_is_init_finished(ssl_c));
1433+
1434+
/* ACK */
1435+
ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_SUCCESS);
1436+
/* Drop the ack */
1437+
test_memio_clear_buffer(&test_ctx, 1);
1438+
1439+
/* trigger client timeout, finished should be rtx */
1440+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
1441+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
1442+
/* this should have triggered a rtx */
1443+
ExpectIntGT(test_ctx.s_msg_count, 0);
1444+
1445+
/* this should re-send the ack immediately */
1446+
ExpectIntEQ(wolfSSL_read(ssl_s, data, 32), -1);
1447+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
1448+
ExpectIntEQ(test_ctx.c_msg_count, 1);
1449+
1450+
/* This should advance the connection on the client */
1451+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), WOLFSSL_SUCCESS);
1452+
1453+
/* Test communication works correctly */
1454+
ExpectIntEQ(test_dtls_communication(ssl_s, ssl_c), TEST_SUCCESS);
1455+
1456+
/* Cleanup */
1457+
wolfSSL_free(ssl_c);
1458+
wolfSSL_CTX_free(ctx_c);
1459+
wolfSSL_free(ssl_s);
1460+
wolfSSL_CTX_free(ctx_s);
1461+
#endif /* defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
1462+
defined(WOLFSSL_DTLS13) */
1463+
return EXPECT_RESULT();
1464+
}

tests/api/test_dtls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ int test_dtls13_short_read(void);
3737
int test_records_span_network_boundaries(void);
3838
int test_dtls_record_cross_boundaries(void);
3939
int test_dtls_rtx_across_epoch_change(void);
40+
int test_dtls_drop_client_ack(void);
4041
#endif /* TESTS_API_DTLS_H */

0 commit comments

Comments
 (0)