Skip to content

Commit 6430708

Browse files
committed
tests: add EMS resumption downgrade negative test (F-2915)
Covers the HandleResumeHistory check that RFC 7627 Section 5.3 requires: if the original session used Extended Master Secret, the server MUST abort when a resumption ClientHello is received without EMS. The new memio test performs a TLS 1.2 handshake with EMS, saves the session, disables EMS on a fresh client, resumes with the saved session, and asserts the server returns EXT_MASTER_SECRET_NEEDED_E.
1 parent caa6a0e commit 6430708

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36298,6 +36298,7 @@ TEST_CASE testCases[] = {
3629836298
TEST_DECL(test_wolfSSL_select_next_proto),
3629936299
#endif
3630036300
TEST_DECL(test_tls_ems_downgrade),
36301+
TEST_DECL(test_tls_ems_resumption_downgrade),
3630136302
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3630236303
TEST_DECL(test_certificate_authorities_certificate_request),
3630336304
TEST_DECL(test_certificate_authorities_client_hello),

tests/api/test_tls_ext.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,56 @@ int test_tls_ems_downgrade(void)
103103
}
104104

105105

106+
/* F-2915: resumption of an EMS session without EMS must abort with
107+
* EXT_MASTER_SECRET_NEEDED_E (RFC 7627 Section 5.3). */
108+
int test_tls_ems_resumption_downgrade(void)
109+
{
110+
EXPECT_DECLS;
111+
#if !defined(WOLFSSL_NO_TLS12) && defined(HAVE_EXTENDED_MASTER) && \
112+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && \
113+
!defined(NO_SESSION_CACHE)
114+
struct test_memio_ctx test_ctx;
115+
WOLFSSL_CTX *ctx_c = NULL;
116+
WOLFSSL_CTX *ctx_s = NULL;
117+
WOLFSSL *ssl_c = NULL;
118+
WOLFSSL *ssl_s = NULL;
119+
WOLFSSL_SESSION *session = NULL;
120+
121+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
122+
123+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
124+
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
125+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
126+
127+
ExpectNotNull(session = wolfSSL_get1_session(ssl_c));
128+
129+
wolfSSL_free(ssl_c);
130+
ssl_c = NULL;
131+
wolfSSL_free(ssl_s);
132+
ssl_s = NULL;
133+
test_memio_clear_buffer(&test_ctx, 0);
134+
test_memio_clear_buffer(&test_ctx, 1);
135+
136+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
137+
wolfTLSv1_2_client_method, wolfTLSv1_2_server_method), 0);
138+
ExpectIntEQ(wolfSSL_set_session(ssl_c, session), WOLFSSL_SUCCESS);
139+
/* Drop EMS from the resumption ClientHello to simulate a downgrade. */
140+
ExpectIntEQ(wolfSSL_DisableExtendedMasterSecret(ssl_c), WOLFSSL_SUCCESS);
141+
142+
ExpectIntNE(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
143+
ExpectIntEQ(wolfSSL_get_error(ssl_s, 0),
144+
WC_NO_ERR_TRACE(EXT_MASTER_SECRET_NEEDED_E));
145+
146+
wolfSSL_SESSION_free(session);
147+
wolfSSL_free(ssl_c);
148+
wolfSSL_free(ssl_s);
149+
wolfSSL_CTX_free(ctx_c);
150+
wolfSSL_CTX_free(ctx_s);
151+
#endif
152+
return EXPECT_RESULT();
153+
}
154+
155+
106156
int test_wolfSSL_DisableExtendedMasterSecret(void)
107157
{
108158
EXPECT_DECLS;

tests/api/test_tls_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define TESTS_API_TEST_TLS_EXT_H
2424

2525
int test_tls_ems_downgrade(void);
26+
int test_tls_ems_resumption_downgrade(void);
2627
int test_wolfSSL_DisableExtendedMasterSecret(void);
2728
int test_certificate_authorities_certificate_request(void);
2829
int test_certificate_authorities_client_hello(void);

0 commit comments

Comments
 (0)