Skip to content

Commit cd0d986

Browse files
committed
Reset DTLS 1.3 timeout
1 parent 874633d commit cd0d986

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

src/internal.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22799,7 +22799,12 @@ static int DoProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2279922799
return ZERO_RETURN;
2280022800
}
2280122801
#endif /* WOLFSSL_EARLY_DATA */
22802-
22802+
if (ret == 0 ||
22803+
ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
22804+
/* Reset timeout as we have received a valid
22805+
* DTLS handshake message */
22806+
ssl->dtls_timeout = ssl->dtls_timeout_init;
22807+
}
2280322808
}
2280422809
#endif /* WOLFSSL_DTLS13 */
2280522810
}

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51407,6 +51407,7 @@ TEST_DECL(test_wc_RsaPSS_DigitalSignVerify),
5140751407
TEST_DECL(test_dtls_bogus_finished_epoch_zero),
5140851408
TEST_DECL(test_dtls_replay),
5140951409
TEST_DECL(test_dtls_srtp),
51410+
TEST_DECL(test_dtls_timeout),
5141051411
TEST_DECL(test_dtls13_ack_order),
5141151412
TEST_DECL(test_dtls_version_checking),
5141251413
TEST_DECL(test_ocsp_status_callback),

tests/api/test_dtls.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,3 +1637,62 @@ int test_dtls_srtp(void)
16371637
return EXPECT_RESULT();
16381638
}
16391639
#endif
1640+
1641+
int test_dtls_timeout(void)
1642+
{
1643+
EXPECT_DECLS;
1644+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
1645+
size_t i;
1646+
struct {
1647+
method_provider client_meth;
1648+
method_provider server_meth;
1649+
} params[] = {
1650+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13)
1651+
{ wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method },
1652+
#endif
1653+
#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS)
1654+
{ wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method },
1655+
#endif
1656+
#if !defined(NO_OLD_TLS) && defined(WOLFSSL_DTLS)
1657+
{ wolfDTLSv1_client_method, wolfDTLSv1_server_method },
1658+
#endif
1659+
};
1660+
1661+
for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) {
1662+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
1663+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
1664+
struct test_memio_ctx test_ctx;
1665+
1666+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
1667+
1668+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
1669+
params[i].client_meth, params[i].server_meth), 0);
1670+
ExpectIntEQ(wolfSSL_dtls_set_timeout_max(ssl_c, 2), WOLFSSL_SUCCESS);
1671+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
1672+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
1673+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13)
1674+
/* will return 0 when not 1.3 */
1675+
if (wolfSSL_dtls13_use_quick_timeout(ssl_c))
1676+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
1677+
#endif
1678+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
1679+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
1680+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
1681+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
1682+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
1683+
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13)
1684+
/* will return 0 when not 1.3 */
1685+
if (wolfSSL_dtls13_use_quick_timeout(ssl_c))
1686+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
1687+
#endif
1688+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
1689+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
1690+
1691+
wolfSSL_free(ssl_s);
1692+
wolfSSL_free(ssl_c);
1693+
wolfSSL_CTX_free(ctx_s);
1694+
wolfSSL_CTX_free(ctx_c);
1695+
}
1696+
#endif
1697+
return EXPECT_RESULT();
1698+
}

tests/api/test_dtls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ int test_dtls_drop_client_ack(void);
4141
int test_dtls_bogus_finished_epoch_zero(void);
4242
int test_dtls_replay(void);
4343
int test_dtls_srtp(void);
44+
int test_dtls_timeout(void);
4445
#endif /* TESTS_API_DTLS_H */

0 commit comments

Comments
 (0)