Skip to content

Commit eb1fff3

Browse files
Merge pull request #7141 from julek-wolfssl/zd/17249
EarlySanityCheckMsgReceived: version_negotiated should always be checked
2 parents f2a76a0 + f6ef146 commit eb1fff3

2 files changed

Lines changed: 52 additions & 10 deletions

File tree

src/internal.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10997,18 +10997,11 @@ int EarlySanityCheckMsgReceived(WOLFSSL* ssl, byte type, word32 msgSz)
1099710997
{
1099810998
int ret = 0;
1099910999
#ifndef WOLFSSL_DISABLE_EARLY_SANITY_CHECKS
11000-
byte version_negotiated = 0;
11001-
11002-
WOLFSSL_ENTER("EarlySanityCheckMsgReceived");
11003-
11004-
#ifdef WOLFSSL_DTLS
1100511000
/* Version has only been negotiated after we either send or process a
1100611001
* ServerHello message */
11007-
if (ssl->options.dtls)
11008-
version_negotiated = ssl->options.serverState >= SERVER_HELLO_COMPLETE;
11009-
else
11010-
#endif
11011-
version_negotiated = 1;
11002+
byte version_negotiated = ssl->options.serverState >= SERVER_HELLO_COMPLETE;
11003+
11004+
WOLFSSL_ENTER("EarlySanityCheckMsgReceived");
1101211005

1101311006
if (version_negotiated)
1101411007
ret = MsgCheckEncryption(ssl, type, ssl->keys.decryptedCur == 1);

tests/api.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69187,6 +69187,54 @@ static int test_self_signed_stapling(void)
6918769187
return EXPECT_RESULT();
6918869188
}
6918969189

69190+
static int test_tls_multi_handshakes_one_record(void)
69191+
{
69192+
EXPECT_DECLS;
69193+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && !defined(WOLFSSL_NO_TLS12)
69194+
struct test_memio_ctx test_ctx;
69195+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
69196+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
69197+
int newRecIdx = RECORD_HEADER_SZ;
69198+
int idx = 0;
69199+
69200+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
69201+
69202+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
69203+
wolfTLS_client_method, wolfTLSv1_2_server_method), 0);
69204+
69205+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
69206+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
69207+
ExpectIntEQ(wolfSSL_accept(ssl_s), -1);
69208+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
69209+
69210+
/* Combine server handshake msgs into one record */
69211+
while (idx < test_ctx.c_len) {
69212+
word16 recLen;
69213+
69214+
ato16(((RecordLayerHeader*)(test_ctx.c_buff + idx))->length, &recLen);
69215+
idx += RECORD_HEADER_SZ;
69216+
69217+
XMEMMOVE(test_ctx.c_buff + newRecIdx, test_ctx.c_buff + idx,
69218+
(size_t)recLen);
69219+
69220+
newRecIdx += recLen;
69221+
idx += recLen;
69222+
}
69223+
c16toa(newRecIdx - RECORD_HEADER_SZ,
69224+
((RecordLayerHeader*)test_ctx.c_buff)->length);
69225+
test_ctx.c_len = newRecIdx;
69226+
69227+
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
69228+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
69229+
69230+
wolfSSL_free(ssl_c);
69231+
wolfSSL_free(ssl_s);
69232+
wolfSSL_CTX_free(ctx_c);
69233+
wolfSSL_CTX_free(ctx_s);
69234+
#endif
69235+
return EXPECT_RESULT();
69236+
}
69237+
6919069238
/*----------------------------------------------------------------------------*
6919169239
| Main
6919269240
*----------------------------------------------------------------------------*/
@@ -70489,6 +70537,7 @@ TEST_CASE testCases[] = {
7048970537
TEST_DECL(test_dtls_empty_keyshare_with_cookie),
7049070538
TEST_DECL(test_tls13_pq_groups),
7049170539
TEST_DECL(test_tls13_early_data),
70540+
TEST_DECL(test_tls_multi_handshakes_one_record),
7049270541
/* This test needs to stay at the end to clean up any caches allocated. */
7049370542
TEST_DECL(test_wolfSSL_Cleanup)
7049470543
};

0 commit comments

Comments
 (0)