Skip to content

Commit 54d96d3

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 dc18b0b commit 54d96d3

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
@@ -36375,6 +36375,7 @@ TEST_CASE testCases[] = {
3637536375
TEST_DECL(test_tls13_null_cipher_bad_hmac),
3637636376
TEST_DECL(test_scr_verify_data_mismatch),
3637736377
TEST_DECL(test_tls13_hrr_cipher_suite_mismatch),
36378+
TEST_DECL(test_tls13_ticket_age_out_of_window),
3637836379
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3637936380
TEST_DECL(test_certificate_authorities_certificate_request),
3638036381
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
@@ -410,6 +410,69 @@ int test_tls13_hrr_cipher_suite_mismatch(void)
410410
}
411411

412412

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