Skip to content

Commit 821ebe7

Browse files
committed
tests: add TLS 1.3 null cipher HMAC negative test (F-2916)
Tls13IntegrityOnly_Decrypt was completely untouched by existing tests, so any mutation of its ConstantCompare would pass CI. Add a memio TLS 1.3 handshake over TLS13-SHA256-SHA256 (integrity-only NULL cipher), then corrupt the final byte of the next record body via an IORecv wrapper and assert the server surfaces DECRYPT_ERROR.
1 parent 5df717e commit 821ebe7

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35903,6 +35903,7 @@ TEST_CASE testCases[] = {
3590335903
TEST_DECL(test_tls_ems_downgrade),
3590435904
TEST_DECL(test_tls_ems_resumption_downgrade),
3590535905
TEST_DECL(test_tls12_chacha20_poly1305_bad_tag),
35906+
TEST_DECL(test_tls13_null_cipher_bad_hmac),
3590635907
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3590735908
TEST_DECL(test_certificate_authorities_certificate_request),
3590835909
TEST_DECL(test_certificate_authorities_client_hello),

tests/api/test_tls_ext.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,70 @@ int test_tls12_chacha20_poly1305_bad_tag(void)
218218
}
219219

220220

221+
#if defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER) && \
222+
defined(BUILD_TLS_SHA256_SHA256) && \
223+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
224+
static int test_tls13_null_bad_hmac_trigger = 0;
225+
226+
static int test_tls13_null_bad_hmac_io_recv(WOLFSSL* ssl, char* buf, int sz,
227+
void* ctx)
228+
{
229+
int ret = test_memio_read_cb(ssl, buf, sz, ctx);
230+
/* Flip the final byte of the record body so the HMAC tag no longer
231+
* matches in Tls13IntegrityOnly_Decrypt. */
232+
if (test_tls13_null_bad_hmac_trigger && ret > 5) {
233+
buf[ret - 1] ^= 0xFF;
234+
test_tls13_null_bad_hmac_trigger = 0;
235+
}
236+
return ret;
237+
}
238+
#endif
239+
240+
/* F-2916: TLS 1.3 integrity-only decryption must surface DECRYPT_ERROR
241+
* when the HMAC tag is corrupted. */
242+
int test_tls13_null_cipher_bad_hmac(void)
243+
{
244+
EXPECT_DECLS;
245+
#if defined(WOLFSSL_TLS13) && defined(HAVE_NULL_CIPHER) && \
246+
defined(BUILD_TLS_SHA256_SHA256) && \
247+
defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES)
248+
struct test_memio_ctx test_ctx;
249+
WOLFSSL_CTX *ctx_c = NULL;
250+
WOLFSSL_CTX *ctx_s = NULL;
251+
WOLFSSL *ssl_c = NULL;
252+
WOLFSSL *ssl_s = NULL;
253+
const char msg[] = "integrity only";
254+
char recvBuf[32];
255+
int ret;
256+
257+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
258+
test_ctx.c_ciphers = test_ctx.s_ciphers = "TLS13-SHA256-SHA256";
259+
260+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
261+
wolfTLSv1_3_client_method, wolfTLSv1_3_server_method), 0);
262+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
263+
264+
wolfSSL_SSLSetIORecv(ssl_s, test_tls13_null_bad_hmac_io_recv);
265+
266+
ExpectIntEQ(wolfSSL_write(ssl_c, msg, (int)XSTRLEN(msg)),
267+
(int)XSTRLEN(msg));
268+
269+
test_tls13_null_bad_hmac_trigger = 1;
270+
ret = wolfSSL_read(ssl_s, recvBuf, sizeof(recvBuf));
271+
ExpectIntLE(ret, 0);
272+
ExpectIntEQ(wolfSSL_get_error(ssl_s, ret),
273+
WC_NO_ERR_TRACE(DECRYPT_ERROR));
274+
275+
test_tls13_null_bad_hmac_trigger = 0;
276+
wolfSSL_free(ssl_c);
277+
wolfSSL_free(ssl_s);
278+
wolfSSL_CTX_free(ctx_c);
279+
wolfSSL_CTX_free(ctx_s);
280+
#endif
281+
return EXPECT_RESULT();
282+
}
283+
284+
221285
int test_wolfSSL_DisableExtendedMasterSecret(void)
222286
{
223287
EXPECT_DECLS;

tests/api/test_tls_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
int test_tls_ems_downgrade(void);
2626
int test_tls_ems_resumption_downgrade(void);
2727
int test_tls12_chacha20_poly1305_bad_tag(void);
28+
int test_tls13_null_cipher_bad_hmac(void);
2829
int test_wolfSSL_DisableExtendedMasterSecret(void);
2930
int test_certificate_authorities_certificate_request(void);
3031
int test_certificate_authorities_client_hello(void);

0 commit comments

Comments
 (0)