Skip to content

Commit 47ea569

Browse files
committed
tests: add TLS 1.3 ticket age out-of-window test (F-1824)
DoClientTicketCheck's ticket-age bounds (-1000 ms low bound and MAX_TICKET_AGE_DIFF*1000+1000 ms high bound) were never exercised by any integration test, so mutations of the constants went undetected. Establish a TLS 1.3 session, read the NewSessionTicket, then shift the client's cached ageAdd by well over 1 second so the server's unobfuscated diff falls outside the valid window on resumption. The server must reject the PSK — session_reused stays 0.
1 parent bb7d00d commit 47ea569

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35972,6 +35972,7 @@ TEST_CASE testCases[] = {
3597235972
TEST_DECL(test_tls13_null_cipher_bad_hmac),
3597335973
TEST_DECL(test_scr_verify_data_mismatch),
3597435974
TEST_DECL(test_tls13_hrr_cipher_suite_mismatch),
35975+
TEST_DECL(test_tls13_ticket_age_out_of_window),
3597535976
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3597635977
TEST_DECL(test_certificate_authorities_certificate_request),
3597735978
TEST_DECL(test_certificate_authorities_client_hello),

tests/api/test_tls_ext.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,69 @@ int test_tls13_hrr_cipher_suite_mismatch(void)
408408
}
409409

410410

411+
/* F-1824: DoClientTicketCheck must reject a PSK whose obfuscated age
412+
* falls outside the [-1000, MAX_TICKET_AGE_DIFF*1000+1000] ms window. */
413+
int test_tls13_ticket_age_out_of_window(void)
414+
{
415+
EXPECT_DECLS;
416+
#if defined(WOLFSSL_TLS13) && defined(HAVE_SESSION_TICKET) && \
417+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
418+
!defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
419+
struct test_memio_ctx test_ctx;
420+
WOLFSSL_CTX *ctx_c = NULL;
421+
WOLFSSL_CTX *ctx_s = NULL;
422+
WOLFSSL *ssl_c = NULL;
423+
WOLFSSL *ssl_s = NULL;
424+
WOLFSSL_SESSION *session = NULL;
425+
byte tmp;
426+
427+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
428+
429+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
430+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
431+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
432+
433+
/* Pump post-handshake reads so the NewSessionTicket reaches the
434+
* client. */
435+
(void)wolfSSL_read(ssl_c, &tmp, sizeof(tmp));
436+
(void)wolfSSL_read(ssl_s, &tmp, sizeof(tmp));
437+
(void)wolfSSL_read(ssl_c, &tmp, sizeof(tmp));
438+
439+
ExpectNotNull(session = wolfSSL_get1_session(ssl_c));
440+
441+
/* Flip the high bit to push the unobfuscated age out of window. */
442+
if (session != NULL)
443+
session->ticketAdd ^= 0x80000000U;
444+
445+
wolfSSL_free(ssl_c);
446+
ssl_c = NULL;
447+
wolfSSL_free(ssl_s);
448+
ssl_s = NULL;
449+
test_memio_clear_buffer(&test_ctx, 0);
450+
test_memio_clear_buffer(&test_ctx, 1);
451+
452+
ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
453+
ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
454+
wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
455+
wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
456+
wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
457+
wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
458+
ExpectIntEQ(wolfSSL_set_session(ssl_c, session), WOLFSSL_SUCCESS);
459+
460+
/* PSK rejected, full handshake must still succeed. */
461+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
462+
ExpectIntEQ(wolfSSL_session_reused(ssl_s), 0);
463+
464+
wolfSSL_SESSION_free(session);
465+
wolfSSL_free(ssl_c);
466+
wolfSSL_free(ssl_s);
467+
wolfSSL_CTX_free(ctx_c);
468+
wolfSSL_CTX_free(ctx_s);
469+
#endif
470+
return EXPECT_RESULT();
471+
}
472+
473+
411474
int test_wolfSSL_DisableExtendedMasterSecret(void)
412475
{
413476
EXPECT_DECLS;

tests/api/test_tls_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ int test_tls12_chacha20_poly1305_bad_tag(void);
2828
int test_tls13_null_cipher_bad_hmac(void);
2929
int test_scr_verify_data_mismatch(void);
3030
int test_tls13_hrr_cipher_suite_mismatch(void);
31+
int test_tls13_ticket_age_out_of_window(void);
3132
int test_wolfSSL_DisableExtendedMasterSecret(void);
3233
int test_certificate_authorities_certificate_request(void);
3334
int test_certificate_authorities_client_hello(void);

0 commit comments

Comments
 (0)