Skip to content

Commit 3af60ff

Browse files
Check for duplicate extensions in client hello when HAVE_TLS_EXTENSIONS is not set - fix #9377
1 parent 9c1526c commit 3af60ff

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/internal.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37869,7 +37869,6 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3786937869
return ret;
3787037870
}
3787137871

37872-
3787337872
/* handle processing of client_hello (1) */
3787437873
int DoClientHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3787537874
word32 helloSz)
@@ -38310,6 +38309,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3831038309
/* auto populate extensions supported unless user defined */
3831138310
if ((ret = TLSX_PopulateExtensions(ssl, 1)) != 0)
3831238311
goto out;
38312+
#else
38313+
word64 extensions_seen = 0u;
3831338314
#endif
3831438315

3831538316
if ((i - begin) + OPAQUE16_LEN > helloSz) {
@@ -38363,6 +38364,18 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3836338364
ato16(&input[i], &extSz);
3836438365
i += OPAQUE16_LEN;
3836538366

38367+
if (extId < (sizeof(extensions_seen) * 8u))
38368+
{
38369+
word64 mask = 1u << extId;
38370+
if ((extensions_seen & mask) != 0u)
38371+
{
38372+
WOLFSSL_MSG("DoClientHello: duplicate extension found");
38373+
ret = DUPLICATE_TLS_EXT_E;
38374+
goto out;
38375+
}
38376+
extensions_seen |= mask;
38377+
}
38378+
3836638379
if (OPAQUE16_LEN + OPAQUE16_LEN + extSz > totalExtSz) {
3836738380
ret = BUFFER_ERROR;
3836838381
goto out;

tests/api.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12977,10 +12977,10 @@ static int test_tls_bad_legacy_version(void)
1297712977
#if defined(WOLFSSL_TLS13) && !defined(WOLFSSL_ALLOW_BAD_TLS_LEGACY_VERSION)
1297812978
#if !defined(NO_WOLFSSL_SERVER) && !defined(NO_TLS) && \
1297912979
!defined(NO_FILESYSTEM) && (!defined(NO_RSA) || defined(HAVE_ECC))
12980-
/* This is exactly the same as the buffer in test_tls_ext_duplicate() except
12981-
* the 11th byte is set to 0x04. That change means the legacy protocol
12982-
* version field is invalid. That will be caught before the dulplicate
12983-
* signature algorithms extension. */
12980+
/* This buffer (prior to Extensions) is exactly the same as the buffer in
12981+
* test_tls_ext_duplicate() except the 11th byte is set to 0x04. That
12982+
* change means the legacy protocol version field is invalid. That will be
12983+
* caught before the dulplicate signature algorithms extension. */
1298412984
const unsigned char clientHelloBadLegacyVersion[] = {
1298512985
0x16, 0x03, 0x03, 0x00, 0x6a, 0x01, 0x00, 0x00,
1298612986
0x66, 0x03, 0x04, 0xf4, 0x65, 0xbd, 0x22, 0xfe,
@@ -12993,9 +12993,9 @@ static int test_tls_bad_legacy_version(void)
1299312993
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1299412994
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x13, 0x01,
1299512995
0x00, 0x9e, 0x01, 0x00,
12996-
/* Extensions - duplicate signature algorithms. */
12996+
/* Extensions */
1299712997
0x00, 0x19, 0x00, 0x0d,
12998-
0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x0d,
12998+
0x00, 0x04, 0x00, 0x02, 0x04, 0x01, 0x00, 0x15,
1299912999
0x00, 0x04, 0x00, 0x02, 0x04, 0x01,
1300013000
/* Supported Versions extension for TLS 1.3. */
1300113001
0x00, 0x2b,

0 commit comments

Comments
 (0)