From 73a406ee60db8f59b3abfb7cf50d310e89102d65 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 13 Sep 2024 13:44:29 +0200 Subject: [PATCH] Separate accepting TLS 1.3 middlebox compatibility from sending it The compile-time option MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE gates both support for interoperability with a peer that uses middlebox compatibility mode, and support for activating that mode ourselves. Change code that is only needed for interoperability to be guarded by MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE. As of this commit, MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE is always enabled: there is no way to disable it, and there are no tests with it disabled. Signed-off-by: Gilles Peskine --- library/ssl_misc.h | 7 +++++++ library/ssl_msg.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/library/ssl_misc.h b/library/ssl_misc.h index 47e56e8796..23d7b22070 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -65,6 +65,13 @@ /* Faked handshake message identity for HelloRetryRequest. */ #define MBEDTLS_SSL_TLS1_3_HS_HELLO_RETRY_REQUEST (-MBEDTLS_SSL_HS_SERVER_HELLO) +/* TLS 1.3: Interoperate with peers that support middlebox compatibility + * mode, but don't produce the relevant messages ourselves. + * + * This is always enabled (with effect only when TLS 1.3 is enabled). + */ +#define MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE + /* * Internal identity of handshake extensions */ diff --git a/library/ssl_msg.c b/library/ssl_msg.c index 2bdad848a9..86463bcb9c 100644 --- a/library/ssl_msg.c +++ b/library/ssl_msg.c @@ -5066,7 +5066,7 @@ int mbedtls_ssl_handle_message_type(mbedtls_ssl_context *ssl) #if defined(MBEDTLS_SSL_PROTO_TLS1_3) if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) { -#if defined(MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE) +#if defined(MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE) MBEDTLS_SSL_DEBUG_MSG(1, ("Ignore ChangeCipherSpec in TLS 1.3 compatibility mode")); return MBEDTLS_ERR_SSL_CONTINUE_PROCESSING; @@ -5074,7 +5074,7 @@ int mbedtls_ssl_handle_message_type(mbedtls_ssl_context *ssl) MBEDTLS_SSL_DEBUG_MSG(1, ("ChangeCipherSpec invalid in TLS 1.3 without compatibility mode")); return MBEDTLS_ERR_SSL_INVALID_RECORD; -#endif /* MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE */ +#endif /* MBEDTLS_SSL_TLS1_3_ACCEPT_COMPATIBILITY_MODE */ } #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ }