Skip to content

Commit 895c758

Browse files
authored
Merge pull request #12143 from Frauschi/dtls13-quick-timeout-fix
Don't back off on a DTLS 1.3 quick timeout that sends ACKs
2 parents 88674fc + ccb05d6 commit 895c758

3 files changed

Lines changed: 81 additions & 2 deletions

File tree

‎src/dtls13.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,8 +3476,6 @@ int Dtls13RtxTimeout(WOLFSSL* ssl)
34763476
(ssl->options.serverState >= SERVER_HELLO_COMPLETE ||
34773477
ssl->options.seenUnifiedHdr)) {
34783478
ssl->dtls13Rtx.sendAcks = 0;
3479-
/* reset fast timeout as we are sending ACKs */
3480-
ssl->dtls13FastTimeout = 0;
34813479
ret = SendDtls13Ack(ssl);
34823480
if (ret != 0)
34833481
return ret;

‎tests/api/test_dtls.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,6 +2999,85 @@ int test_dtls_drop_client_ack(void)
29992999
return EXPECT_RESULT();
30003000
}
30013001

3002+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
3003+
defined(WOLFSSL_DTLS13) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
3004+
!defined(WOLFSSL_NO_CLIENT_AUTH)
3005+
/* A quick timeout that sends ACKs with nothing to retransmit doesn't back
3006+
* off, also when the timeout is already at its maximum. */
3007+
static int test_dtls13_quick_timeout_no_backoff_ex(int atMax)
3008+
{
3009+
EXPECT_DECLS;
3010+
struct test_memio_ctx test_ctx;
3011+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
3012+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
3013+
int timeout = 0;
3014+
3015+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
3016+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
3017+
wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method), 0);
3018+
ExpectIntEQ(wolfSSL_use_certificate_file(ssl_c, cliCertFile,
3019+
WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
3020+
ExpectIntEQ(wolfSSL_use_PrivateKey_file(ssl_c, cliKeyFile,
3021+
WOLFSSL_FILETYPE_PEM), WOLFSSL_SUCCESS);
3022+
ExpectIntEQ(wolfSSL_CTX_load_verify_locations(ctx_s, cliCertFile, NULL),
3023+
WOLFSSL_SUCCESS);
3024+
wolfSSL_set_verify(ssl_s, WOLFSSL_VERIFY_PEER |
3025+
WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
3026+
wolfSSL_dtls13_set_send_more_acks(ssl_s, 0);
3027+
if (atMax) {
3028+
ExpectIntEQ(wolfSSL_dtls_set_timeout_max(ssl_s,
3029+
wolfSSL_dtls_get_current_timeout(ssl_s)), WOLFSSL_SUCCESS);
3030+
}
3031+
3032+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
3033+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
3034+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
3035+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
3036+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
3037+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
3038+
/* The server only gets the first record of the client's flight. */
3039+
ExpectIntGE(test_ctx.s_msg_count, 2);
3040+
while (EXPECT_SUCCESS() && test_ctx.s_msg_count > 1)
3041+
ExpectIntEQ(test_memio_drop_message(&test_ctx, 0, 1), 0);
3042+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
3043+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
3044+
ExpectIntEQ(test_ctx.c_msg_count, 0);
3045+
ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_s), 1);
3046+
timeout = wolfSSL_dtls_get_current_timeout(ssl_s);
3047+
3048+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS);
3049+
ExpectIntEQ(test_ctx.c_msg_count, 1);
3050+
ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_s), timeout);
3051+
ExpectIntEQ(wolfSSL_dtls13_use_quick_timeout(ssl_s), 0);
3052+
3053+
if (!atMax) {
3054+
/* The next full timeout still backs off. */
3055+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_s), WOLFSSL_SUCCESS);
3056+
ExpectIntEQ(wolfSSL_dtls_get_current_timeout(ssl_s),
3057+
timeout * DTLS_TIMEOUT_MULTIPLIER);
3058+
}
3059+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
3060+
3061+
wolfSSL_free(ssl_c);
3062+
wolfSSL_free(ssl_s);
3063+
wolfSSL_CTX_free(ctx_c);
3064+
wolfSSL_CTX_free(ctx_s);
3065+
return EXPECT_RESULT();
3066+
}
3067+
#endif
3068+
3069+
int test_dtls13_quick_timeout_no_backoff(void)
3070+
{
3071+
EXPECT_DECLS;
3072+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
3073+
defined(WOLFSSL_DTLS13) && !defined(NO_RSA) && !defined(NO_FILESYSTEM) && \
3074+
!defined(WOLFSSL_NO_CLIENT_AUTH)
3075+
ExpectIntEQ(test_dtls13_quick_timeout_no_backoff_ex(0), TEST_SUCCESS);
3076+
ExpectIntEQ(test_dtls13_quick_timeout_no_backoff_ex(1), TEST_SUCCESS);
3077+
#endif
3078+
return EXPECT_RESULT();
3079+
}
3080+
30023081
int test_dtls_bogus_finished_epoch_zero(void)
30033082
{
30043083
EXPECT_DECLS;

‎tests/api/test_dtls.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ int test_records_span_network_boundaries(void);
5656
int test_dtls_record_cross_boundaries(void);
5757
int test_dtls_rtx_across_epoch_change(void);
5858
int test_dtls_drop_client_ack(void);
59+
int test_dtls13_quick_timeout_no_backoff(void);
5960
int test_dtls_bogus_finished_epoch_zero(void);
6061
int test_dtls_replay(void);
6162
int test_dtls_timeout(void);
@@ -262,6 +263,7 @@ int test_dtls_no_cookie_ch_pause(WOLFSSL* ssl, void* ctx);
262263
TEST_DECL_GROUP("dtls", test_dtls_record_cross_boundaries), \
263264
TEST_DECL_GROUP("dtls", test_dtls_rtx_across_epoch_change), \
264265
TEST_DECL_GROUP("dtls", test_dtls_drop_client_ack), \
266+
TEST_DECL_GROUP("dtls", test_dtls13_quick_timeout_no_backoff), \
265267
TEST_DECL_GROUP("dtls", test_dtls_bogus_finished_epoch_zero), \
266268
TEST_DECL_GROUP("dtls", test_dtls_replay), \
267269
TEST_DECL_GROUP("dtls", test_dtls_certreq_order), \

0 commit comments

Comments
 (0)