@@ -2489,3 +2489,78 @@ int test_dtls_mtu_split_messages(void)
24892489 return TEST_SKIPPED ;
24902490#endif
24912491}
2492+
2493+ /* Test DTLS 1.3 minimum retransmission interval. This test calls
2494+ * wolfSSL_dtls_got_timeout() to simulate timeouts and verify that
2495+ * retransmissions are spaced at least DTLS13_MIN_RTX_INTERVAL apart.
2496+ */
2497+ int test_dtls13_min_rtx_interval (void )
2498+ {
2499+ EXPECT_DECLS ;
2500+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && \
2501+ defined(WOLFSSL_DTLS13 ) && !defined(DTLS13_MIN_RTX_INTERVAL ) && \
2502+ !defined(NO_ASN_TIME )
2503+ /* We don't want to test when DTLS13_MIN_RTX_INTERVAL is defined because
2504+ * it may be too low to trigger reliably in a test. The default value is
2505+ * 1 second which is sufficient for testing here. */
2506+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
2507+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
2508+ struct test_memio_ctx test_ctx ;
2509+ int c_msg_count = 0 ;
2510+
2511+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
2512+
2513+ /* Setup DTLS 1.3 contexts */
2514+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
2515+ wolfDTLSv1_3_client_method , wolfDTLSv1_3_server_method ), 0 );
2516+
2517+ /* CH0 */
2518+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
2519+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), SSL_ERROR_WANT_READ );
2520+
2521+ /* HRR */
2522+ ExpectIntEQ (wolfSSL_accept (ssl_s ), -1 );
2523+ ExpectIntEQ (wolfSSL_get_error (ssl_s , -1 ), SSL_ERROR_WANT_READ );
2524+
2525+ /* CH1 */
2526+ ExpectIntEQ (wolfSSL_connect (ssl_c ), -1 );
2527+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), SSL_ERROR_WANT_READ );
2528+
2529+ /* SH ... FINISHED */
2530+ ExpectIntEQ (wolfSSL_accept (ssl_s ), -1 );
2531+ ExpectIntEQ (wolfSSL_get_error (ssl_s , -1 ), SSL_ERROR_WANT_READ );
2532+
2533+ /* We should have SH ... FINISHED messages in the buffer */
2534+ ExpectIntGE (test_ctx .c_msg_count , 2 );
2535+
2536+ /* Drop everything */
2537+ test_memio_clear_buffer (& test_ctx , 1 );
2538+
2539+ /* First timeout. This one should trigger a retransmission */
2540+ if (wolfSSL_dtls13_use_quick_timeout (ssl_s ))
2541+ ExpectIntEQ (wolfSSL_dtls_got_timeout (ssl_s ), WOLFSSL_SUCCESS );
2542+ ExpectIntEQ (wolfSSL_dtls_got_timeout (ssl_s ), WOLFSSL_SUCCESS );
2543+ /* Save the message count to make sure no new messages are sent */
2544+ ExpectIntGE (c_msg_count = test_ctx .c_msg_count , 2 );
2545+
2546+ /* Second timeout. This one should not trigger a retransmission */
2547+ if (wolfSSL_dtls13_use_quick_timeout (ssl_s ))
2548+ ExpectIntEQ (wolfSSL_dtls_got_timeout (ssl_s ), WOLFSSL_SUCCESS );
2549+ ExpectIntEQ (wolfSSL_dtls_got_timeout (ssl_s ), WOLFSSL_SUCCESS );
2550+ /* This is the critical check. The message count should not increase
2551+ * after the second timeout. DTLS13_MIN_RTX_INTERVAL should have blocked
2552+ * retransmission here. */
2553+ ExpectIntEQ (c_msg_count , test_ctx .c_msg_count );
2554+
2555+ /* Now complete the handshake. We didn't clear the first retransmission
2556+ * so the handshake should proceed without issues. */
2557+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
2558+
2559+ /* Cleanup */
2560+ wolfSSL_free (ssl_c );
2561+ wolfSSL_CTX_free (ctx_c );
2562+ wolfSSL_free (ssl_s );
2563+ wolfSSL_CTX_free (ctx_s );
2564+ #endif
2565+ return EXPECT_RESULT ();
2566+ }
0 commit comments