Skip to content

Commit 6914f08

Browse files
authored
Merge pull request #9391 from holtrop/check-dup-extensions-fix
Check for duplicate extensions in client hello when HAVE_TLS_EXTENSIONS is not set - fix #9377
2 parents 4c273a6 + 798b16d commit 6914f08

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

.github/workflows/os-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
'--enable-coding=no',
6464
'--enable-dtls --enable-dtls13 --enable-ocspstapling --enable-ocspstapling2
6565
--enable-cert-setup-cb --enable-sessioncerts',
66+
'--disable-sni --disable-ecc --disable-tls13 --disable-secure-renegotiation-info',
6667
]
6768
name: make check
6869
if: github.repository_owner == 'wolfssl'

src/internal.c

Lines changed: 13 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+
word32 extensions_seen = 0U;
3831338314
#endif
3831438315

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

38367+
if (extId < (word16)(sizeof(extensions_seen) * 8U)) {
38368+
word32 mask = 1U << extId;
38369+
if ((extensions_seen & mask) != 0U) {
38370+
WOLFSSL_MSG(
38371+
"DoClientHello: duplicate extension found");
38372+
ret = DUPLICATE_TLS_EXT_E;
38373+
goto out;
38374+
}
38375+
extensions_seen |= mask;
38376+
}
38377+
3836638378
if (OPAQUE16_LEN + OPAQUE16_LEN + extSz > totalExtSz) {
3836738379
ret = BUFFER_ERROR;
3836838380
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)