Skip to content

Commit f2532ca

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 b59d5c3 commit f2532ca

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36300,6 +36300,7 @@ TEST_CASE testCases[] = {
3630036300
TEST_DECL(test_tls_ems_downgrade),
3630136301
TEST_DECL(test_tls_ems_resumption_downgrade),
3630236302
TEST_DECL(test_tls12_chacha20_poly1305_bad_tag),
36303+
TEST_DECL(test_tls13_null_cipher_bad_hmac),
3630336304
TEST_DECL(test_wolfSSL_DisableExtendedMasterSecret),
3630436305
TEST_DECL(test_certificate_authorities_certificate_request),
3630536306
TEST_DECL(test_certificate_authorities_client_hello),

tests/api/test_tls_ext.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,71 @@ int test_tls12_chacha20_poly1305_bad_tag(void)
219219
}
220220

221221

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