Skip to content

Commit fda5a1e

Browse files
committed
tests: add HRR cipher-suite mismatch negative test (F-2126)
DoTls13ClientHello enforces RFC 8446 Section 4.1.4 by comparing the cipher suite in the second ClientHello to the hrrCipherSuite cached on the server from the HelloRetryRequest. No existing test covers the mismatch branch, so a deletion of the check would silently allow a client to switch cipher suite between CH1 and CH2. Drive a partial handshake until the server has emitted the HRR, then flip the cached hrrCipherSuite on the server; processing CH2 must surface INVALID_PARAMETER.
1 parent 2df02ac commit fda5a1e

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35971,6 +35971,7 @@ TEST_CASE testCases[] = {
3597135971
TEST_DECL(test_tls12_chacha20_poly1305_bad_tag),
3597235972
TEST_DECL(test_tls13_null_cipher_bad_hmac),
3597335973
TEST_DECL(test_scr_verify_data_mismatch),
35974+
TEST_DECL(test_tls13_hrr_cipher_suite_mismatch),
3597435975
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3597535976
TEST_DECL(test_certificate_authorities_certificate_request),
3597635977
TEST_DECL(test_certificate_authorities_client_hello),

tests/api/test_tls_ext.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,66 @@ int test_scr_verify_data_mismatch(void)
348348
return EXPECT_RESULT();
349349
}
350350

351+
/* F-2126: DoTls13ClientHello must reject a second ClientHello whose
352+
* cipher suite does not match the server's HelloRetryRequest. The
353+
* client offers two suites in CH1 and only a different one in CH2. */
354+
int test_tls13_hrr_cipher_suite_mismatch(void)
355+
{
356+
EXPECT_DECLS;
357+
#if defined(WOLFSSL_TLS13) && \
358+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
359+
!defined(NO_WOLFSSL_CLIENT) && !defined(NO_WOLFSSL_SERVER) && \
360+
defined(BUILD_TLS_AES_128_GCM_SHA256) && \
361+
defined(BUILD_TLS_AES_256_GCM_SHA384)
362+
struct test_memio_ctx test_ctx;
363+
WOLFSSL_CTX *ctx_c = NULL;
364+
WOLFSSL_CTX *ctx_s = NULL;
365+
WOLFSSL *ssl_c = NULL;
366+
WOLFSSL *ssl_s = NULL;
367+
int ret;
368+
369+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
370+
/* Both suites supported on both ends; server prefers the first
371+
* offered suite, which will be the one committed in the HRR. */
372+
test_ctx.c_ciphers = test_ctx.s_ciphers =
373+
"TLS13-AES128-GCM-SHA256:TLS13-AES256-GCM-SHA384";
374+
375+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
376+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
377+
/* Force HRR by withholding key_share entries in CH1. */
378+
ExpectIntEQ(wolfSSL_NoKeyShares(ssl_c), WOLFSSL_SUCCESS);
379+
380+
/* CH1 / HRR */
381+
ExpectIntEQ(wolfSSL_connect(ssl_c), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
382+
ExpectIntEQ(wolfSSL_get_error(ssl_c, 0), WOLFSSL_ERROR_WANT_READ);
383+
ExpectIntEQ(wolfSSL_accept(ssl_s), WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR));
384+
ExpectIntEQ(wolfSSL_get_error(ssl_s, 0), WOLFSSL_ERROR_WANT_READ);
385+
386+
/* Restrict the client to a different suite than the one the
387+
* server committed to in the HRR, so CH2 offers only that. */
388+
ExpectIntEQ(wolfSSL_set_cipher_list(ssl_c, "TLS13-AES256-GCM-SHA384"),
389+
WOLFSSL_SUCCESS);
390+
391+
/* CH2 */
392+
(void)wolfSSL_connect(ssl_c);
393+
(void)wolfSSL_accept(ssl_s);
394+
(void)wolfSSL_connect(ssl_c);
395+
/* The cipher-suite mismatch is caught server-side; the server's
396+
* alert reaches the client, so either peer can surface it. */
397+
ret = wolfSSL_get_error(ssl_s, 0);
398+
if (ret != WC_NO_ERR_TRACE(INVALID_PARAMETER))
399+
ret = wolfSSL_get_error(ssl_c, 0);
400+
ExpectIntEQ(ret, WC_NO_ERR_TRACE(INVALID_PARAMETER));
401+
402+
wolfSSL_free(ssl_c);
403+
wolfSSL_free(ssl_s);
404+
wolfSSL_CTX_free(ctx_c);
405+
wolfSSL_CTX_free(ctx_s);
406+
#endif
407+
return EXPECT_RESULT();
408+
}
409+
410+
351411
int test_wolfSSL_DisableExtendedMasterSecret(void)
352412
{
353413
EXPECT_DECLS;

tests/api/test_tls_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int test_tls_ems_resumption_downgrade(void);
2727
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);
30+
int test_tls13_hrr_cipher_suite_mismatch(void);
3031
int test_wolfSSL_DisableExtendedMasterSecret(void);
3132
int test_certificate_authorities_certificate_request(void);
3233
int test_certificate_authorities_client_hello(void);

0 commit comments

Comments
 (0)