Skip to content

Commit 2df02ac

Browse files
committed
tests: add default ticket key callback HMAC negative test (F-2922)
wolfSSL_TicketKeyCb is the built-in ticket callback registered by the OpenSSL-compat wolfSSL_CTX_set_tlsext_ticket_key_cb API. Its ConstantCompare of the ticket HMAC was never reached in any test, so a deletion of the check would silently accept forged tickets. New test sets up the compat callback, establishes a TLS 1.2 session, saves it, flips a byte of the encrypted ticket, and asserts the resumption attempt does not complete.
1 parent 1f1ad03 commit 2df02ac

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/api.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10433,6 +10433,72 @@ static int test_wolfSSL_SCR_check_enabled(void)
1043310433
return EXPECT_RESULT();
1043410434
}
1043510435

10436+
/* F-2922: wolfSSL_TicketKeyCb must reject a session ticket whose HMAC
10437+
* does not match its encrypted contents. */
10438+
static int test_wolfSSL_ticket_keycb_bad_hmac(void)
10439+
{
10440+
EXPECT_DECLS;
10441+
#if defined(HAVE_SESSION_TICKET) && !defined(WOLFSSL_NO_TLS12) && \
10442+
defined(OPENSSL_EXTRA) && defined(HAVE_AES_CBC) && \
10443+
defined(WOLFSSL_AES_256) && \
10444+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
10445+
!defined(WOLFSSL_NO_DEF_TICKET_ENC_CB)
10446+
struct test_memio_ctx test_ctx;
10447+
WOLFSSL_CTX *ctx_c = NULL;
10448+
WOLFSSL_CTX *ctx_s = NULL;
10449+
WOLFSSL *ssl_c = NULL;
10450+
WOLFSSL *ssl_s = NULL;
10451+
WOLFSSL_SESSION *session = NULL;
10452+
10453+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
10454+
10455+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
10456+
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
10457+
10458+
ExpectIntEQ(OpenSSLTicketInit(), 0);
10459+
ExpectIntEQ(wolfSSL_CTX_set_tlsext_ticket_key_cb(ctx_s,
10460+
myTicketEncCbOpenSSL), WOLFSSL_SUCCESS);
10461+
ExpectIntEQ(wolfSSL_UseSessionTicket(ssl_c), WOLFSSL_SUCCESS);
10462+
10463+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
10464+
ExpectNotNull(session = wolfSSL_get1_session(ssl_c));
10465+
ExpectIntGT(session->ticketLen, 0);
10466+
10467+
/* Corrupt a byte of the encrypted ticket so the server's HMAC
10468+
* verification rejects it. */
10469+
if (session != NULL && session->ticket != NULL && session->ticketLen > 0)
10470+
session->ticket[0] ^= 0xFF;
10471+
10472+
wolfSSL_free(ssl_c);
10473+
ssl_c = NULL;
10474+
wolfSSL_free(ssl_s);
10475+
ssl_s = NULL;
10476+
test_memio_clear_buffer(&test_ctx, 0);
10477+
test_memio_clear_buffer(&test_ctx, 1);
10478+
10479+
ExpectNotNull(ssl_c = wolfSSL_new(ctx_c));
10480+
ExpectNotNull(ssl_s = wolfSSL_new(ctx_s));
10481+
wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
10482+
wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
10483+
wolfSSL_SetIOReadCtx(ssl_s, &test_ctx);
10484+
wolfSSL_SetIOWriteCtx(ssl_s, &test_ctx);
10485+
ExpectIntEQ(wolfSSL_set_session(ssl_c, session), WOLFSSL_SUCCESS);
10486+
10487+
/* Corrupted ticket bytes fail the HMAC check in
10488+
* wolfSSL_TicketKeyCb; the handshake must not complete. */
10489+
ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
10490+
10491+
wolfSSL_SESSION_free(session);
10492+
wolfSSL_free(ssl_c);
10493+
wolfSSL_free(ssl_s);
10494+
wolfSSL_CTX_free(ctx_c);
10495+
wolfSSL_CTX_free(ctx_s);
10496+
OpenSSLTicketCleanup();
10497+
#endif
10498+
return EXPECT_RESULT();
10499+
}
10500+
10501+
1043610502
#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \
1043710503
!defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
1043810504
/* Called when writing. */
@@ -35913,6 +35979,7 @@ TEST_CASE testCases[] = {
3591335979
TEST_DECL(test_wolfSSL_wolfSSL_UseSecureRenegotiation),
3591435980
TEST_DECL(test_wolfSSL_SCR_Reconnect),
3591535981
TEST_DECL(test_wolfSSL_SCR_check_enabled),
35982+
TEST_DECL(test_wolfSSL_ticket_keycb_bad_hmac),
3591635983
TEST_DECL(test_tls_ext_duplicate),
3591735984
TEST_DECL(test_tls_bad_legacy_version),
3591835985
#if defined(WOLFSSL_TLS13) && defined(HAVE_ECH)

0 commit comments

Comments
 (0)