Skip to content

Commit ae9ccba

Browse files
committed
tests: add SCR verify_data mismatch test (F-2913, F-2914)
Cover both branches of TLSX_SecureRenegotiation_Parse's ConstantCompare against the cached Finished verify_data: a single memio test loops over client-side and server-side corruption, renegotiates, and asserts the offending peer surfaces SECURE_RENEGOTIATION_E.
1 parent 755b3ed commit ae9ccba

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36301,6 +36301,7 @@ TEST_CASE testCases[] = {
3630136301
TEST_DECL(test_tls_ems_resumption_downgrade),
3630236302
TEST_DECL(test_tls12_chacha20_poly1305_bad_tag),
3630336303
TEST_DECL(test_tls13_null_cipher_bad_hmac),
36304+
TEST_DECL(test_scr_verify_data_mismatch),
3630436305
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3630536306
TEST_DECL(test_certificate_authorities_certificate_request),
3630636307
TEST_DECL(test_certificate_authorities_client_hello),

tests/api/test_tls_ext.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,72 @@ int test_tls13_null_cipher_bad_hmac(void)
284284
}
285285

286286

287+
/* F-2913 and F-2914: the TLSX_SecureRenegotiation_Parse
288+
* ConstantCompare against the cached Finished verify_data must reject
289+
* a mismatch on both the client and server sides. */
290+
int test_scr_verify_data_mismatch(void)
291+
{
292+
EXPECT_DECLS;
293+
#if defined(HAVE_SECURE_RENEGOTIATION) && !defined(WOLFSSL_NO_TLS12) && \
294+
defined(BUILD_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) && \
295+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
296+
int side;
297+
298+
for (side = 0; side < 2; side++) {
299+
struct test_memio_ctx test_ctx;
300+
WOLFSSL_CTX *ctx_c = NULL;
301+
WOLFSSL_CTX *ctx_s = NULL;
302+
WOLFSSL *ssl_c = NULL;
303+
WOLFSSL *ssl_s = NULL;
304+
WOLFSSL *failing;
305+
byte data;
306+
int ret;
307+
308+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
309+
test_ctx.c_ciphers = test_ctx.s_ciphers =
310+
"ECDHE-RSA-AES128-GCM-SHA256";
311+
312+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c,
313+
&ssl_s, wolfTLSv1_2_client_method,
314+
wolfTLSv1_2_server_method), 0);
315+
ExpectIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx_c),
316+
WOLFSSL_SUCCESS);
317+
ExpectIntEQ(wolfSSL_CTX_UseSecureRenegotiation(ctx_s),
318+
WOLFSSL_SUCCESS);
319+
ExpectIntEQ(wolfSSL_UseSecureRenegotiation(ssl_c), WOLFSSL_SUCCESS);
320+
ExpectIntEQ(wolfSSL_UseSecureRenegotiation(ssl_s), WOLFSSL_SUCCESS);
321+
322+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
323+
324+
/* side 0: corrupt the client's copy; side 1: corrupt the
325+
* server's copy. */
326+
if (side == 0) {
327+
if (ssl_c != NULL && ssl_c->secure_renegotiation != NULL)
328+
ssl_c->secure_renegotiation->server_verify_data[0] ^= 0xFF;
329+
failing = ssl_c;
330+
}
331+
else {
332+
if (ssl_s != NULL && ssl_s->secure_renegotiation != NULL)
333+
ssl_s->secure_renegotiation->client_verify_data[0] ^= 0xFF;
334+
failing = ssl_s;
335+
}
336+
337+
ret = wolfSSL_Rehandshake(ssl_c);
338+
(void)ret;
339+
(void)wolfSSL_read(ssl_s, &data, 1);
340+
(void)wolfSSL_read(ssl_c, &data, 1);
341+
ExpectIntEQ(wolfSSL_get_error(failing, 0),
342+
WC_NO_ERR_TRACE(SECURE_RENEGOTIATION_E));
343+
344+
wolfSSL_free(ssl_c);
345+
wolfSSL_free(ssl_s);
346+
wolfSSL_CTX_free(ctx_c);
347+
wolfSSL_CTX_free(ctx_s);
348+
}
349+
#endif
350+
return EXPECT_RESULT();
351+
}
352+
287353
int test_wolfSSL_DisableExtendedMasterSecret(void)
288354
{
289355
EXPECT_DECLS;

tests/api/test_tls_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ int test_tls_ems_downgrade(void);
2626
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);
29+
int test_scr_verify_data_mismatch(void);
2930
int test_wolfSSL_DisableExtendedMasterSecret(void);
3031
int test_certificate_authorities_certificate_request(void);
3132
int test_certificate_authorities_client_hello(void);

0 commit comments

Comments
 (0)