Skip to content

Commit dff1d9a

Browse files
authored
Merge pull request wolfSSL#11646 from ducanhmit/fix-psk-trailing-data
Reject trailing data in TLS 1.3 ClientHello pre_shared_key extension
2 parents 81a405b + be5b775 commit dff1d9a

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎src/tls.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13121,6 +13121,9 @@ int TLSX_PreSharedKey_Parse_ClientHello(TLSX** extensions, const byte* input,
1312113121
}
1312213122
if (list != NULL || len != 0)
1312313123
return BUFFER_E;
13124+
/* No data allowed after OfferedPsks. */
13125+
if (idx != length)
13126+
return BUFFER_E;
1312413127

1312513128
return 0;
1312613129

‎tests/api/test_tls_msgtype.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,43 @@ int test_tls_msgtype_psk_ch_binder_gates(void)
21402140
ssl = NULL;
21412141
wolfSSL_CTX_free(ctx);
21422142
ctx = NULL;
2143+
2144+
/* Trailing "idx != length" gate: a complete, valid OfferedPsks followed
2145+
* by one extra byte inside the extension data must be rejected
2146+
* (RFC 8446 Section 4.2). */
2147+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
2148+
ExpectNotNull(ssl = wolfSSL_new(ctx));
2149+
{
2150+
Suites suites;
2151+
2152+
XMEMCPY(body, psk_ch_body, sizeof(psk_ch_body));
2153+
body[sizeof(psk_ch_body)] = 0xAA;
2154+
XMEMSET(&suites, 0, sizeof(suites));
2155+
len = build_ext_with_body(buf, TLSX_PRE_SHARED_KEY, body,
2156+
(word16)(sizeof(psk_ch_body) + 1));
2157+
ExpectIntEQ(TLSX_Parse(ssl, buf, len, client_hello, &suites),
2158+
WC_NO_ERR_TRACE(BUFFER_E));
2159+
}
2160+
wolfSSL_free(ssl);
2161+
ssl = NULL;
2162+
wolfSSL_CTX_free(ctx);
2163+
ctx = NULL;
2164+
2165+
/* Control: the same OfferedPsks without the trailing byte is accepted. */
2166+
ExpectNotNull(ctx = wolfSSL_CTX_new(wolfTLSv1_3_client_method()));
2167+
ExpectNotNull(ssl = wolfSSL_new(ctx));
2168+
{
2169+
Suites suites;
2170+
2171+
XMEMSET(&suites, 0, sizeof(suites));
2172+
len = build_ext_with_body(buf, TLSX_PRE_SHARED_KEY, psk_ch_body,
2173+
(word16)sizeof(psk_ch_body));
2174+
ExpectIntEQ(TLSX_Parse(ssl, buf, len, client_hello, &suites), 0);
2175+
}
2176+
wolfSSL_free(ssl);
2177+
ssl = NULL;
2178+
wolfSSL_CTX_free(ctx);
2179+
ctx = NULL;
21432180
#endif
21442181
return EXPECT_RESULT();
21452182
}

0 commit comments

Comments
 (0)