Skip to content

Commit b1b49c9

Browse files
committed
dtls13: always send ACKs on detected retransmission
Otherwise the connection can stall due the indefinite delay of an explicit ACK, for exapmle: -> client sends the last Finished message <- server sends the ACK, but the ACK is lost -> client rentrasmit the Finished message - server delay sending of the ACK until a fast timeout -> client rentrasmit the Finished message quicker than the server timeout - server resets the timeout, delaying sending the ACK -> client rentrasmit the Finished...
1 parent 509491f commit b1b49c9

4 files changed

Lines changed: 82 additions & 1 deletion

File tree

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 ==

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68477,6 +68477,7 @@ TEST_CASE testCases[] = {
6847768477
TEST_DECL(test_wolfSSL_dtls_cid_parse),
6847868478
TEST_DECL(test_dtls13_epochs),
6847968479
TEST_DECL(test_dtls_rtx_across_epoch_change),
68480+
TEST_DECL(test_dtls_drop_client_ack),
6848068481
TEST_DECL(test_dtls13_ack_order),
6848168482
TEST_DECL(test_dtls_version_checking),
6848268483
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)