Skip to content

Commit 467f16f

Browse files
authored
Merge pull request #9913 from julek-wolfssl/fenrir/365
Enforce null compression in compression_methods list
2 parents a8686f6 + 68a1f6f commit 467f16f

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

src/internal.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38067,6 +38067,15 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
3806738067
}
3806838068
}
3806938069

38070+
if (!matchNo) {
38071+
WOLFSSL_MSG("Compression list missing null");
38072+
#ifdef WOLFSSL_EXTRA_ALERTS
38073+
SendAlert(ssl, alert_fatal, illegal_parameter);
38074+
#endif
38075+
ret = COMPRESSION_ERROR;
38076+
goto out;
38077+
}
38078+
3807038079
if (ssl->options.usingCompression == 0 && matchNo) {
3807138080
WOLFSSL_MSG("Matched No Compression");
3807238081
} else if (ssl->options.usingCompression && matchZlib) {

tests/api/test_tls.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,60 @@ int test_tls12_bad_cv_sig_alg(void)
666666
return EXPECT_RESULT();
667667
}
668668

669+
int test_tls12_no_null_compression(void)
670+
{
671+
EXPECT_DECLS;
672+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
673+
/* ClientHello with compression list missing the required null method (RFC
674+
* 5246 7.4.1.2: the list MUST include the null compression method). */
675+
const byte badClientHello[] = {
676+
/* record header */
677+
0x16, 0x03, 0x03, 0x00, 0x2d,
678+
/* handshake header: ClientHello, length 41 */
679+
0x01, 0x00, 0x00, 0x29,
680+
/* client version: TLS 1.2 */
681+
0x03, 0x03,
682+
/* random: 32 bytes */
683+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
684+
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
685+
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
686+
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
687+
/* session id length: 0 */
688+
0x00,
689+
/* cipher suites length: 2, TLS_RSA_WITH_AES_128_CBC_SHA */
690+
0x00, 0x02, 0x00, 0x2f,
691+
/* compression methods: 1 entry, ZLIB only (null is absent) */
692+
0x01, 0xdd,
693+
};
694+
WOLFSSL_CTX *ctx_s = NULL;
695+
WOLFSSL *ssl_s = NULL;
696+
struct test_memio_ctx test_ctx;
697+
698+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
699+
ExpectIntEQ(test_memio_inject_message(&test_ctx, 0,
700+
(const char*)badClientHello, sizeof(badClientHello)), 0);
701+
ExpectIntEQ(test_memio_setup(&test_ctx, NULL, &ctx_s, NULL, &ssl_s,
702+
NULL, wolfTLSv1_2_server_method), 0);
703+
ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_FATAL_ERROR);
704+
ExpectIntEQ(wolfSSL_get_error(ssl_s, WOLFSSL_FATAL_ERROR),
705+
WC_NO_ERR_TRACE(COMPRESSION_ERROR));
706+
#ifdef WOLFSSL_EXTRA_ALERTS
707+
{
708+
const byte illegalParamAlert[] = {
709+
0x15, /* alert content type */
710+
0x03, 0x03, /* version: TLS 1.2 */
711+
0x00, 0x02, /* length: 2 */
712+
0x02, /* level: fatal */
713+
0x2f, /* description: illegal_parameter (47) */
714+
};
715+
ExpectIntEQ(test_ctx.c_len, (int)sizeof(illegalParamAlert));
716+
ExpectBufEQ(test_ctx.c_buff, illegalParamAlert,
717+
sizeof(illegalParamAlert));
718+
}
719+
#endif
720+
wolfSSL_free(ssl_s);
721+
wolfSSL_CTX_free(ctx_s);
722+
#endif
723+
return EXPECT_RESULT();
724+
}
725+

tests/api/test_tls.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int test_tls12_curve_intersection(void);
2929
int test_tls13_curve_intersection(void);
3030
int test_tls_certreq_order(void);
3131
int test_tls12_bad_cv_sig_alg(void);
32+
int test_tls12_no_null_compression(void);
3233

3334
#define TEST_TLS_DECLS \
3435
TEST_DECL_GROUP("tls", test_utils_memio_move_message), \
@@ -37,6 +38,7 @@ int test_tls12_bad_cv_sig_alg(void);
3738
TEST_DECL_GROUP("tls", test_tls12_curve_intersection), \
3839
TEST_DECL_GROUP("tls", test_tls13_curve_intersection), \
3940
TEST_DECL_GROUP("tls", test_tls_certreq_order), \
40-
TEST_DECL_GROUP("tls", test_tls12_bad_cv_sig_alg)
41+
TEST_DECL_GROUP("tls", test_tls12_bad_cv_sig_alg), \
42+
TEST_DECL_GROUP("tls", test_tls12_no_null_compression)
4143

4244
#endif /* TESTS_API_TEST_TLS_H */

0 commit comments

Comments
 (0)