diff --git a/src/internal.c b/src/internal.c index 153a746fb..2397e5b00 100644 --- a/src/internal.c +++ b/src/internal.c @@ -22799,7 +22799,12 @@ default: return ZERO_RETURN; } #endif /* WOLFSSL_EARLY_DATA */ - + if (ret == 0 || + ret == WC_NO_ERR_TRACE(WC_PENDING_E)) { + /* Reset timeout as we have received a valid + * DTLS handshake message */ + ssl->dtls_timeout = ssl->dtls_timeout_init; + } } #endif /* WOLFSSL_DTLS13 */ } diff --git a/tests/api.c b/tests/api.c index 252e16182..58957793a 100644 --- a/tests/api.c +++ b/tests/api.c @@ -51407,6 +51407,7 @@ TEST_DECL(test_wc_RsaPSS_DigitalSignVerify), TEST_DECL(test_dtls_bogus_finished_epoch_zero), TEST_DECL(test_dtls_replay), TEST_DECL(test_dtls_srtp), + TEST_DECL(test_dtls_timeout), TEST_DECL(test_dtls13_ack_order), TEST_DECL(test_dtls_version_checking), TEST_DECL(test_ocsp_status_callback), diff --git a/tests/api/test_dtls.c b/tests/api/test_dtls.c index 9d7d2b0f2..1287a2c8f 100644 --- a/tests/api/test_dtls.c +++ b/tests/api/test_dtls.c @@ -1637,3 +1637,62 @@ int test_dtls_srtp(void) return EXPECT_RESULT(); } #endif + +int test_dtls_timeout(void) +{ + EXPECT_DECLS; +#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS) + size_t i; + struct { + method_provider client_meth; + method_provider server_meth; + } params[] = { +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + { wolfDTLSv1_3_client_method, wolfDTLSv1_3_server_method }, +#endif +#if !defined(WOLFSSL_NO_TLS12) && defined(WOLFSSL_DTLS) + { wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method }, +#endif +#if !defined(NO_OLD_TLS) && defined(WOLFSSL_DTLS) + { wolfDTLSv1_client_method, wolfDTLSv1_server_method }, +#endif + }; + + for (i = 0; i < XELEM_CNT(params) && !EXPECT_FAIL(); i++) { + WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL; + WOLFSSL *ssl_c = NULL, *ssl_s = NULL; + struct test_memio_ctx test_ctx; + + XMEMSET(&test_ctx, 0, sizeof(test_ctx)); + + ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s, + params[i].client_meth, params[i].server_meth), 0); + ExpectIntEQ(wolfSSL_dtls_set_timeout_max(ssl_c, 2), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + /* will return 0 when not 1.3 */ + if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); +#endif + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ); + ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1); + ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ); +#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_DTLS13) + /* will return 0 when not 1.3 */ + if (wolfSSL_dtls13_use_quick_timeout(ssl_c)) + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); +#endif + ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS); + ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0); + + wolfSSL_free(ssl_s); + wolfSSL_free(ssl_c); + wolfSSL_CTX_free(ctx_s); + wolfSSL_CTX_free(ctx_c); + } +#endif + return EXPECT_RESULT(); +} diff --git a/tests/api/test_dtls.h b/tests/api/test_dtls.h index caff1a19b..2532e472e 100644 --- a/tests/api/test_dtls.h +++ b/tests/api/test_dtls.h @@ -41,4 +41,5 @@ int test_dtls_drop_client_ack(void); int test_dtls_bogus_finished_epoch_zero(void); int test_dtls_replay(void); int test_dtls_srtp(void); +int test_dtls_timeout(void); #endif /* TESTS_API_DTLS_H */