Skip to content

Commit 7b95db0

Browse files
Also handle alerts for alternate DoTls13ServerHello call path.
Fix incorrect illegal_parameter alert for missing supported_versions. This is a missing extension rather than an extra/unexpected extension.
1 parent 8ce29c7 commit 7b95db0

3 files changed

Lines changed: 19 additions & 22 deletions

File tree

src/internal.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33142,7 +33142,17 @@ static void MakePSKPreMasterSecret(Arrays* arrays, byte use_psk_key)
3314233142
#ifdef WOLFSSL_TLS13
3314333143
if (IsAtLeastTLSv1_3(pv)) {
3314433144
byte type = server_hello;
33145-
return DoTls13ServerHello(ssl, input, inOutIdx, helloSz, &type);
33145+
ret = DoTls13ServerHello(ssl, input, inOutIdx, helloSz, &type);
33146+
if (ret != 0 &&
33147+
ssl->alert_history.last_tx.level != alert_fatal) {
33148+
int alertType = TranslateErrorToAlert(ret);
33149+
if (alertType != invalid_alert) {
33150+
if (SendAlert(ssl, alert_fatal, alertType) ==
33151+
WC_NO_ERR_TRACE(SOCKET_ERROR_E))
33152+
ret = SOCKET_ERROR_E;
33153+
}
33154+
}
33155+
return ret;
3314633156
}
3314733157
#endif
3314833158

src/tls13.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5659,21 +5659,6 @@ int DoTls13ServerHello(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
56595659
WOLFSSL_ERROR_VERBOSE(VERSION_ERROR);
56605660
return VERSION_ERROR;
56615661
}
5662-
5663-
if (args->extMsgType == hello_retry_request) {
5664-
/* The HelloRetryRequest sentinel Random is reserved for TLS 1.3
5665-
* (RFC 8446 4.1.3), but supported_versions (which an HRR MUST
5666-
* carry, 4.1.4/4.2.1) is absent, so the message is malformed.
5667-
* Reject before the downgrade reparses the remaining extensions
5668-
* as a TLS 1.2 server_hello, where a recognized-but-not-
5669-
* permitted extension (e.g. server_name) would wrongly yield an
5670-
* unsupported_extension alert. illegal_parameter (via
5671-
* EXT_NOT_ALLOWED) is chosen over missing_extension per the
5672-
* RFC 8446 4.2 rule for such extensions. */
5673-
WOLFSSL_MSG("HelloRetryRequest without supported_versions");
5674-
WOLFSSL_ERROR_VERBOSE(EXT_NOT_ALLOWED);
5675-
return EXT_NOT_ALLOWED;
5676-
}
56775662
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || \
56785663
defined(WOLFSSL_WPAS_SMALL)
56795664
/* Check if client has disabled TLS 1.2 */

tests/api/test_tls13.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6446,16 +6446,18 @@ int test_tls13_hrr_recognized_ext_downgrade(void)
64466446
ExpectIntEQ(test_memio_inject_message(&test_ctx, 1,
64476447
(const char *)hrr_sni_no_sv, sizeof(hrr_sni_no_sv)), 0);
64486448

6449-
/* Handshake must fail with EXT_NOT_ALLOWED (server_name is not permitted in
6450-
* a HelloRetryRequest), not UNSUPPORTED_EXTENSION. */
6449+
/* Handshake must fail because the mandatory supported_versions extension
6450+
* is absent from the HelloRetryRequest. The HRR is rejected before the
6451+
* downgrade reparses the remaining (server_name) extension, so the result
6452+
* is the missing mandatory extension (INCOMPLETE_DATA). */
64516453
ExpectIntEQ(wolfSSL_connect(ssl_c), -1);
64526454
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1),
6453-
WC_NO_ERR_TRACE(EXT_NOT_ALLOWED));
6455+
WC_NO_ERR_TRACE(INCOMPLETE_DATA));
64546456

6455-
/* RFC 8446 Sec. 4.2: the client MUST abort with illegal_parameter (47),
6456-
* not unsupported_extension (110). */
6457+
/* RFC 8446 Sec. 4.1.4/4.2: a mandatory-but-absent extension MUST abort with
6458+
* a missing_extension (109) alert. */
64576459
ExpectIntEQ(wolfSSL_get_alert_history(ssl_c, &h), WOLFSSL_SUCCESS);
6458-
ExpectIntEQ(h.last_tx.code, illegal_parameter);
6460+
ExpectIntEQ(h.last_tx.code, missing_extension);
64596461
ExpectIntEQ(h.last_tx.level, alert_fatal);
64606462

64616463
wolfSSL_free(ssl_c);

0 commit comments

Comments
 (0)