Skip to content

Commit d7d8d14

Browse files
committed
TLS: wrong TLS version in alert after ClientHello
Ignore protocol version being less than expected when received directly after ClientHello. Protocol version negotiation hasn't taken place and a lower version can be sent to cover minimum supported protocol version.
1 parent c822303 commit d7d8d14

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/internal.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11456,7 +11456,20 @@ static int GetRecordHeader(WOLFSSL* ssl, word32* inOutIdx,
1145611456
}
1145711457
}
1145811458
#endif /* WOLFSSL_DTLS13 */
11459-
else {
11459+
/* Don't care about protocol version being lower than expected on alerts
11460+
* sent back before version negotitation. */
11461+
else if (!(ssl->options.side == WOLFSSL_CLIENT_END &&
11462+
ssl->options.connectState == CLIENT_HELLO_SENT &&
11463+
rh->type == alert &&
11464+
rh->pvMajor == ssl->version.major &&
11465+
#ifdef WOLFSSL_DTLS
11466+
((ssl->options.dtls && rh->pvMinor == DTLS_MINOR) ||
11467+
(!ssl->options.dtls &&
11468+
rh->pvMinor < ssl->version.minor))
11469+
#else
11470+
rh->pvMinor < ssl->version.minor
11471+
#endif
11472+
)) {
1146011473
WOLFSSL_MSG("SSL version error");
1146111474
WOLFSSL_ERROR_VERBOSE(VERSION_ERROR);
1146211475
return VERSION_ERROR; /* only use requested version */

tests/api.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70460,6 +70460,34 @@ static int test_dtls_no_extensions(void)
7046070460
return EXPECT_RESULT();
7046170461
}
7046270462

70463+
static int test_tls_alert_no_server_hello(void)
70464+
{
70465+
EXPECT_DECLS;
70466+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
70467+
WOLFSSL *ssl_c = NULL;
70468+
WOLFSSL_CTX *ctx_c = NULL;
70469+
struct test_memio_ctx test_ctx;
70470+
unsigned char alert_msg[] = { 0x15, 0x03, 0x01, 0x00, 0x02, 0x02, 0x28 };
70471+
70472+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
70473+
ssl_c = NULL;
70474+
ctx_c = NULL;
70475+
70476+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, NULL, &ssl_c, NULL,
70477+
wolfTLSv1_2_client_method, NULL), 0);
70478+
70479+
XMEMCPY(test_ctx.c_buff, alert_msg, sizeof(alert_msg));
70480+
test_ctx.c_len = sizeof(alert_msg);
70481+
70482+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
70483+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), FATAL_ERROR);
70484+
70485+
wolfSSL_free(ssl_c);
70486+
wolfSSL_CTX_free(ctx_c);
70487+
#endif
70488+
return EXPECT_RESULT();
70489+
}
70490+
7046370491
static int test_TLSX_CA_NAMES_bad_extension(void)
7046470492
{
7046570493
EXPECT_DECLS;
@@ -74037,6 +74065,7 @@ TEST_CASE testCases[] = {
7403774065
TEST_DECL(test_dtls_ipv6_check),
7403874066
TEST_DECL(test_wolfSSL_SCR_after_resumption),
7403974067
TEST_DECL(test_dtls_no_extensions),
74068+
TEST_DECL(test_tls_alert_no_server_hello),
7404074069
TEST_DECL(test_TLSX_CA_NAMES_bad_extension),
7404174070
TEST_DECL(test_dtls_1_0_hvr_downgrade),
7404274071
TEST_DECL(test_session_ticket_no_id),

0 commit comments

Comments
 (0)