From a8b4291836b788d509bd00cd2436e5cbd363544a Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Wed, 8 Nov 2023 11:10:47 +0800 Subject: [PATCH 01/25] tls13: add generic function to write Record Size Limit ext Signed-off-by: Yanray Wang --- library/ssl_misc.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/ssl_misc.h b/library/ssl_misc.h index a8afd429cf..62b212d722 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -2710,6 +2710,13 @@ MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, const unsigned char *buf, const unsigned char *end); + +MBEDTLS_CHECK_RETURN_CRITICAL +int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl, + uint16_t record_size_limit, + unsigned char *buf, + const unsigned char *end, + size_t *out_len); #endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */ #if defined(MBEDTLS_SSL_ALPN) From faf70bdf9d314e52fd8b3e7d92a922316cac05c5 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Thu, 7 Dec 2023 10:03:32 +0800 Subject: [PATCH 02/25] ssl_tls13_generic: check value of RecordSizeLimit in helper function Signed-off-by: Yanray Wang --- library/ssl_tls13_generic.c | 67 +++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/library/ssl_tls13_generic.c b/library/ssl_tls13_generic.c index ecfaf8a1a9..0befe3bba3 100644 --- a/library/ssl_tls13_generic.c +++ b/library/ssl_tls13_generic.c @@ -1698,6 +1698,27 @@ int mbedtls_ssl_tls13_check_received_extension( } #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) +/* RFC 8449, section 4: + * + * Endpoints MUST NOT send a "record_size_limit" extension with a value + * smaller than 64. An endpoint MUST treat receipt of a smaller value + * as a fatal error and generate an "illegal_parameter" alert. + */ +static int mbedtls_ssl_is_record_size_limit_valid(mbedtls_ssl_context *ssl, + uint16_t record_size_limit) +{ + if (record_size_limit < MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN) { + MBEDTLS_SSL_DEBUG_MSG(1, ("Invalid record size limit : %u Bytes", + record_size_limit)); + MBEDTLS_SSL_PEND_FATAL_ALERT( + MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER, + MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER; + } + + return 0; +} + /* RFC 8449, section 4: * * The ExtensionData of the "record_size_limit" extension is @@ -1709,6 +1730,7 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, const unsigned char *buf, const unsigned char *end) { + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; const unsigned char *p = buf; uint16_t record_size_limit; const size_t extension_data_len = end - buf; @@ -1731,17 +1753,9 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG(2, ("RecordSizeLimit: %u Bytes", record_size_limit)); - /* RFC 8449, section 4: - * - * Endpoints MUST NOT send a "record_size_limit" extension with a value - * smaller than 64. An endpoint MUST treat receipt of a smaller value - * as a fatal error and generate an "illegal_parameter" alert. - */ - if (record_size_limit < MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN) { - MBEDTLS_SSL_PEND_FATAL_ALERT( - MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER, - MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER); - return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER; + ret = mbedtls_ssl_is_record_size_limit_valid(ssl, record_size_limit); + if (ret != 0) { + return ret; } ssl->session_negotiate->record_size_limit = record_size_limit; @@ -1749,6 +1763,37 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, return 0; } +MBEDTLS_CHECK_RETURN_CRITICAL +int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl, + uint16_t record_size_limit, + unsigned char *buf, + const unsigned char *end, + size_t *out_len) +{ + int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; + unsigned char *p = buf; + *out_len = 0; + + ret = mbedtls_ssl_is_record_size_limit_valid(ssl, record_size_limit); + if (ret != 0) { + return ret; + } + + MBEDTLS_SSL_CHK_BUF_PTR(p, end, 6); + + MBEDTLS_PUT_UINT16_BE(MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT, p, 0); + MBEDTLS_PUT_UINT16_BE(MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH, p, 2); + MBEDTLS_PUT_UINT16_BE(record_size_limit, p, 4); + + *out_len = 6; + + MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %u Bytes", record_size_limit)); + + mbedtls_ssl_tls13_set_hs_sent_ext_mask(ssl, MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT); + + return 0; +} + #endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */ #endif /* MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_PROTO_TLS1_3 */ From 42017cd4c9dacef74a82618a1d1b8afbfbfe35a9 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Wed, 8 Nov 2023 11:15:23 +0800 Subject: [PATCH 03/25] tls13: cli: write Record Size Limit ext in ClientHello - add the support in library - update corresponding test case Signed-off-by: Yanray Wang --- library/ssl_tls13_client.c | 9 +++++++++ tests/ssl-opt.sh | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/library/ssl_tls13_client.c b/library/ssl_tls13_client.c index 342ec5242e..0d132227c0 100644 --- a/library/ssl_tls13_client.c +++ b/library/ssl_tls13_client.c @@ -1160,6 +1160,15 @@ int mbedtls_ssl_tls13_write_client_hello_exts(mbedtls_ssl_context *ssl, } p += ext_len; +#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) + ret = mbedtls_ssl_tls13_write_record_size_limit_ext( + ssl, MBEDTLS_SSL_IN_CONTENT_LEN, p, end, &ext_len); + if (ret != 0) { + return ret; + } + p += ext_len; +#endif + #if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_EPHEMERAL_ENABLED) if (mbedtls_ssl_conf_tls13_some_ephemeral_enabled(ssl)) { ret = ssl_tls13_write_key_share_ext(ssl, p, end, &ext_len); diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 92b3e171c6..1cd01dc0c2 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -4856,10 +4856,13 @@ run_test "Record Size Limit: TLS 1.3: Client-side parsing and debug output" \ "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert -d 4" \ "$P_CLI debug_level=4 force_version=tls13" \ 0 \ - -s "Preparing extension (Record Size Limit/28) for 'encrypted extensions'" -# The P_CLI can not yet send the Record Size Limit extension. Thus, the G_NEXT_SRV does not send -# a response in its EncryptedExtensions record. -# -c "RecordSizeLimit: 16385 Bytes" + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "found record_size_limit extension" \ + -c "RecordSizeLimit: 16385 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension received." \ + -s "Parsing extension 'Record Size Limit/28' (2 bytes)" \ + -s "record_size_limit 16384 negotiated" # In the following (9) tests, --recordsize is the value used by the G_NEXT_CLI (3.7.2) to configure the # maximum record size using "https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-size". From 47d294694355b2544f8a2647c3fcfae5b77ac8fc Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 3 Jan 2024 17:31:52 +0000 Subject: [PATCH 04/25] tls13: server: write Record Size Limit ext in EncryptedExtensions - add the support in library - update corresponding test cases. Signed-off-by: Yanray Wang Signed-off-by: Waleed Elmelegy --- library/ssl_tls13_server.c | 9 +++++++++ tests/ssl-opt.sh | 24 ++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/library/ssl_tls13_server.c b/library/ssl_tls13_server.c index a7c266b528..c9fddda1ee 100644 --- a/library/ssl_tls13_server.c +++ b/library/ssl_tls13_server.c @@ -2530,6 +2530,15 @@ static int ssl_tls13_write_encrypted_extensions_body(mbedtls_ssl_context *ssl, } #endif /* MBEDTLS_SSL_EARLY_DATA */ +#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) + ret = mbedtls_ssl_tls13_write_record_size_limit_ext( + ssl, MBEDTLS_SSL_IN_CONTENT_LEN, p, end, &output_len); + if (ret != 0) { + return ret; + } + p += output_len; +#endif + extensions_len = (p - p_extensions_len) - 2; MBEDTLS_PUT_UINT16_BE(extensions_len, p_extensions_len, 0); diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 1cd01dc0c2..89243e4a29 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -4843,7 +4843,6 @@ run_test "Record Size Limit: TLS 1.3: Server-side parsing and debug output" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4" \ 0 \ -s "RecordSizeLimit: 16385 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 16383" \ -s "bytes written in 1 fragments" @@ -4857,10 +4856,7 @@ run_test "Record Size Limit: TLS 1.3: Client-side parsing and debug output" \ "$P_CLI debug_level=4 force_version=tls13" \ 0 \ -c "Sent RecordSizeLimit: 16384 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ - -c "found record_size_limit extension" \ -c "RecordSizeLimit: 16385 Bytes" \ - -c "EncryptedExtensions: record_size_limit(28) extension received." \ -s "Parsing extension 'Record Size Limit/28' (2 bytes)" \ -s "record_size_limit 16384 negotiated" @@ -4937,8 +4933,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=512" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \ 0 \ - -s "RecordSizeLimit: 1024 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 1023" \ -s "512 bytes written in 1 fragments" @@ -4951,8 +4947,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=1536" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \ 0 \ - -s "RecordSizeLimit: 1024 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 1023" \ -s "1536 bytes written in 2 fragments" @@ -4965,8 +4961,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=2560" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \ 0 \ - -s "RecordSizeLimit: 1024 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 1023" \ -s "2560 bytes written in 3 fragments" @@ -4979,8 +4975,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=2048" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \ 0 \ - -s "RecordSizeLimit: 4096 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 4095" \ -s "2048 bytes written in 1 fragments" @@ -4993,8 +4989,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=6144" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \ 0 \ - -s "RecordSizeLimit: 4096 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 4095" \ -s "6144 bytes written in 2 fragments" From 598ea09dd5b142a0743c4a9b8ab7a3a9b6a9a813 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 3 Jan 2024 17:34:03 +0000 Subject: [PATCH 05/25] TLS1.3: SRV/CLI: add support for sending Record Size Limit extension Signed-off-by: Yanray Wang Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 89243e4a29..e45a165df8 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -5003,11 +5003,33 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=10240" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \ 0 \ - -s "RecordSizeLimit: 4096 Bytes" \ - -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 4095" \ -s "10240 bytes written in 3 fragments" +# TODO: For time being, we send fixed value of RecordSizeLimit defined by +# MBEDTLS_SSL_IN_CONTENT_LEN. Once we support variable buffer length of +# RecordSizeLimit, we need to modify value of RecordSizeLimit in below test. +requires_config_enabled MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_CLI_C +requires_config_enabled MBEDTLS_SSL_SRV_C +run_test "Record Size Limit: TLS 1.3 m->m: both peer comply with record size limit (16384)" \ + "$P_SRV debug_level=4 force_version=tls13" \ + "$P_CLI debug_level=4 force_version=tls13" \ + 0 \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 16383" \ + -s "RecordSizeLimit: 16384 Bytes" \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ + -s "Maximum outgoing record payload length is 16383" \ + -s "Maximum incoming record payload length is 16384" + # Tests for renegotiation # Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION From 148dfb64575dab43a26fe66677d2b7f98d22f049 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Thu, 4 Jan 2024 18:02:35 +0000 Subject: [PATCH 06/25] Change record size limit writing function Signed-off-by: Waleed Elmelegy --- library/ssl_misc.h | 1 - library/ssl_tls13_client.c | 2 +- library/ssl_tls13_generic.c | 12 ++++-------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/library/ssl_misc.h b/library/ssl_misc.h index 62b212d722..7195d63432 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -2713,7 +2713,6 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl, - uint16_t record_size_limit, unsigned char *buf, const unsigned char *end, size_t *out_len); diff --git a/library/ssl_tls13_client.c b/library/ssl_tls13_client.c index 0d132227c0..2a8081ddac 100644 --- a/library/ssl_tls13_client.c +++ b/library/ssl_tls13_client.c @@ -1162,7 +1162,7 @@ int mbedtls_ssl_tls13_write_client_hello_exts(mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) ret = mbedtls_ssl_tls13_write_record_size_limit_ext( - ssl, MBEDTLS_SSL_IN_CONTENT_LEN, p, end, &ext_len); + ssl, p, end, &ext_len); if (ret != 0) { return ret; } diff --git a/library/ssl_tls13_generic.c b/library/ssl_tls13_generic.c index 0befe3bba3..ad2b7f6729 100644 --- a/library/ssl_tls13_generic.c +++ b/library/ssl_tls13_generic.c @@ -1765,29 +1765,25 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl, - uint16_t record_size_limit, unsigned char *buf, const unsigned char *end, size_t *out_len) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; unsigned char *p = buf; *out_len = 0; - ret = mbedtls_ssl_is_record_size_limit_valid(ssl, record_size_limit); - if (ret != 0) { - return ret; - } + MBEDTLS_STATIC_ASSERT(MBEDTLS_SSL_IN_CONTENT_LEN >= MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN, + "MBEDTLS_SSL_IN_CONTENT_LEN is less than the minimum record size limit"); MBEDTLS_SSL_CHK_BUF_PTR(p, end, 6); MBEDTLS_PUT_UINT16_BE(MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT, p, 0); MBEDTLS_PUT_UINT16_BE(MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH, p, 2); - MBEDTLS_PUT_UINT16_BE(record_size_limit, p, 4); + MBEDTLS_PUT_UINT16_BE(MBEDTLS_SSL_IN_CONTENT_LEN, p, 4); *out_len = 6; - MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %u Bytes", record_size_limit)); + MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %u Bytes", MBEDTLS_SSL_IN_CONTENT_LEN)); mbedtls_ssl_tls13_set_hs_sent_ext_mask(ssl, MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT); From d2fc90e024b055e023c412fac6a1377229396eff Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Thu, 4 Jan 2024 18:04:53 +0000 Subject: [PATCH 07/25] Stop sending record size limit extension if it's not sent from client Signed-off-by: Waleed Elmelegy --- library/ssl_tls13_server.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/library/ssl_tls13_server.c b/library/ssl_tls13_server.c index c9fddda1ee..36d1c059f5 100644 --- a/library/ssl_tls13_server.c +++ b/library/ssl_tls13_server.c @@ -2500,6 +2500,9 @@ static int ssl_tls13_write_encrypted_extensions_body(mbedtls_ssl_context *ssl, size_t extensions_len = 0; unsigned char *p_extensions_len; size_t output_len; +#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) + uint32_t record_size_extension_mask; +#endif *out_len = 0; @@ -2531,12 +2534,15 @@ static int ssl_tls13_write_encrypted_extensions_body(mbedtls_ssl_context *ssl, #endif /* MBEDTLS_SSL_EARLY_DATA */ #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) - ret = mbedtls_ssl_tls13_write_record_size_limit_ext( - ssl, MBEDTLS_SSL_IN_CONTENT_LEN, p, end, &output_len); - if (ret != 0) { - return ret; + record_size_extension_mask = mbedtls_ssl_get_extension_mask(MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT); + if (ssl->handshake->received_extensions | record_size_extension_mask) { + ret = mbedtls_ssl_tls13_write_record_size_limit_ext( + ssl, p, end, &output_len); + if (ret != 0) { + return ret; + } + p += output_len; } - p += output_len; #endif extensions_len = (p - p_extensions_len) - 2; From e1ac98d8887872ccc8a5034a5e237f74965f3a47 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Fri, 5 Jan 2024 18:10:12 +0000 Subject: [PATCH 08/25] remove mbedtls_ssl_is_record_size_limit_valid function Signed-off-by: Waleed Elmelegy --- library/ssl_tls13_generic.c | 46 +++++++++++++++---------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/library/ssl_tls13_generic.c b/library/ssl_tls13_generic.c index ad2b7f6729..0afedbc356 100644 --- a/library/ssl_tls13_generic.c +++ b/library/ssl_tls13_generic.c @@ -1698,26 +1698,6 @@ int mbedtls_ssl_tls13_check_received_extension( } #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) -/* RFC 8449, section 4: - * - * Endpoints MUST NOT send a "record_size_limit" extension with a value - * smaller than 64. An endpoint MUST treat receipt of a smaller value - * as a fatal error and generate an "illegal_parameter" alert. - */ -static int mbedtls_ssl_is_record_size_limit_valid(mbedtls_ssl_context *ssl, - uint16_t record_size_limit) -{ - if (record_size_limit < MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN) { - MBEDTLS_SSL_DEBUG_MSG(1, ("Invalid record size limit : %u Bytes", - record_size_limit)); - MBEDTLS_SSL_PEND_FATAL_ALERT( - MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER, - MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER); - return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER; - } - - return 0; -} /* RFC 8449, section 4: * @@ -1730,7 +1710,6 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, const unsigned char *buf, const unsigned char *end) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; const unsigned char *p = buf; uint16_t record_size_limit; const size_t extension_data_len = end - buf; @@ -1753,9 +1732,19 @@ int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl, MBEDTLS_SSL_DEBUG_MSG(2, ("RecordSizeLimit: %u Bytes", record_size_limit)); - ret = mbedtls_ssl_is_record_size_limit_valid(ssl, record_size_limit); - if (ret != 0) { - return ret; + /* RFC 8449, section 4: + * + * Endpoints MUST NOT send a "record_size_limit" extension with a value + * smaller than 64. An endpoint MUST treat receipt of a smaller value + * as a fatal error and generate an "illegal_parameter" alert. + */ + if (record_size_limit < MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN) { + MBEDTLS_SSL_DEBUG_MSG(1, ("Invalid record size limit : %u Bytes", + record_size_limit)); + MBEDTLS_SSL_PEND_FATAL_ALERT( + MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER, + MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER); + return MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER; } ssl->session_negotiate->record_size_limit = record_size_limit; @@ -1773,17 +1762,20 @@ int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl, *out_len = 0; MBEDTLS_STATIC_ASSERT(MBEDTLS_SSL_IN_CONTENT_LEN >= MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN, - "MBEDTLS_SSL_IN_CONTENT_LEN is less than the minimum record size limit"); + "MBEDTLS_SSL_IN_CONTENT_LEN is less than the " + "minimum record size limit"); MBEDTLS_SSL_CHK_BUF_PTR(p, end, 6); MBEDTLS_PUT_UINT16_BE(MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT, p, 0); - MBEDTLS_PUT_UINT16_BE(MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH, p, 2); + MBEDTLS_PUT_UINT16_BE(MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH, + p, 2); MBEDTLS_PUT_UINT16_BE(MBEDTLS_SSL_IN_CONTENT_LEN, p, 4); *out_len = 6; - MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %u Bytes", MBEDTLS_SSL_IN_CONTENT_LEN)); + MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %u Bytes", + MBEDTLS_SSL_IN_CONTENT_LEN)); mbedtls_ssl_tls13_set_hs_sent_ext_mask(ssl, MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT); From fbe42743eb37c0d8b846b6127144643400288fa4 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Fri, 5 Jan 2024 18:11:10 +0000 Subject: [PATCH 09/25] Fix issue in checking in writing extensions Fix issue in checking if server received record size limit extension. Signed-off-by: Waleed Elmelegy --- library/ssl_tls13_server.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/ssl_tls13_server.c b/library/ssl_tls13_server.c index 36d1c059f5..227d287af5 100644 --- a/library/ssl_tls13_server.c +++ b/library/ssl_tls13_server.c @@ -2500,9 +2500,6 @@ static int ssl_tls13_write_encrypted_extensions_body(mbedtls_ssl_context *ssl, size_t extensions_len = 0; unsigned char *p_extensions_len; size_t output_len; -#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) - uint32_t record_size_extension_mask; -#endif *out_len = 0; @@ -2534,8 +2531,7 @@ static int ssl_tls13_write_encrypted_extensions_body(mbedtls_ssl_context *ssl, #endif /* MBEDTLS_SSL_EARLY_DATA */ #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) - record_size_extension_mask = mbedtls_ssl_get_extension_mask(MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT); - if (ssl->handshake->received_extensions | record_size_extension_mask) { + if (ssl->handshake->received_extensions & MBEDTLS_SSL_EXT_MASK(RECORD_SIZE_LIMIT)) { ret = mbedtls_ssl_tls13_write_record_size_limit_ext( ssl, p, end, &output_len); if (ret != 0) { From 3a37756496f89937214d600d5f2b7b8ccd95ed07 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Fri, 5 Jan 2024 18:13:42 +0000 Subject: [PATCH 10/25] Improve record size limit tests Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index e45a165df8..f47cc8ef6e 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -4843,6 +4843,7 @@ run_test "Record Size Limit: TLS 1.3: Server-side parsing and debug output" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4" \ 0 \ -s "RecordSizeLimit: 16385 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 16383" \ -s "bytes written in 1 fragments" @@ -4856,6 +4857,9 @@ run_test "Record Size Limit: TLS 1.3: Client-side parsing and debug output" \ "$P_CLI debug_level=4 force_version=tls13" \ 0 \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "found record_size_limit extension" \ + -c "EncryptedExtensions: record_size_limit(28) extension received." \ -c "RecordSizeLimit: 16385 Bytes" \ -s "Parsing extension 'Record Size Limit/28' (2 bytes)" \ -s "record_size_limit 16384 negotiated" @@ -4933,6 +4937,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=512" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \ 0 \ + -s "RecordSizeLimit: 1024 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Sent RecordSizeLimit: 16384 Bytes" \ -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 1023" \ @@ -4947,6 +4953,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=1536" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \ 0 \ + -s "RecordSizeLimit: 1024 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Sent RecordSizeLimit: 16384 Bytes" \ -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 1023" \ @@ -4961,6 +4969,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=2560" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 1023" \ 0 \ + -s "RecordSizeLimit: 1024 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Sent RecordSizeLimit: 16384 Bytes" \ -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 1023" \ @@ -4975,6 +4985,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=2048" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \ 0 \ + -s "RecordSizeLimit: 4096 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Sent RecordSizeLimit: 16384 Bytes" \ -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 4095" \ @@ -4989,6 +5001,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=6144" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \ 0 \ + -s "RecordSizeLimit: 4096 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Sent RecordSizeLimit: 16384 Bytes" \ -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 4095" \ @@ -5003,6 +5017,8 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 response_size=10240" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4 --recordsize 4095" \ 0 \ + -s "RecordSizeLimit: 4096 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ -s "Sent RecordSizeLimit: 16384 Bytes" \ -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 4095" \ @@ -5011,23 +5027,20 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit # TODO: For time being, we send fixed value of RecordSizeLimit defined by # MBEDTLS_SSL_IN_CONTENT_LEN. Once we support variable buffer length of # RecordSizeLimit, we need to modify value of RecordSizeLimit in below test. -requires_config_enabled MBEDTLS_DEBUG_C -requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3 +requires_config_value_equals "MBEDTLS_SSL_IN_CONTENT_LEN" 16384 +requires_all_configs_enabled MBEDTLS_SSL_CLI_C MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT -requires_config_enabled MBEDTLS_SSL_CLI_C -requires_config_enabled MBEDTLS_SSL_SRV_C -run_test "Record Size Limit: TLS 1.3 m->m: both peer comply with record size limit (16384)" \ +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3 m->m: both peer comply with record size limit (default)" \ "$P_SRV debug_level=4 force_version=tls13" \ - "$P_CLI debug_level=4 force_version=tls13" \ + "$P_CLI debug_level=4" \ 0 \ - -c "Sent RecordSizeLimit: 16384 Bytes" \ - -c "RecordSizeLimit: 16384 Bytes" \ - -c "EncryptedExtensions: record_size_limit(28) extension exists." \ - -c "Maximum outgoing record payload length is 16383" \ - -s "RecordSizeLimit: 16384 Bytes" \ - -s "Sent RecordSizeLimit: 16384 Bytes" \ - -s "EncryptedExtensions: record_size_limit(28) extension exists." \ - -s "Maximum outgoing record payload length is 16383" \ + -c "Sent RecordSizeLimit: $MAX_IN_LEN Bytes" \ + -c "RecordSizeLimit: $MAX_IN_LEN Bytes" \ + -c "Maximum outgoing record payload length is 16383" \ + -s "RecordSizeLimit: $MAX_IN_LEN Bytes" \ + -s "Sent RecordSizeLimit: $MAX_IN_LEN Bytes" \ + -s "Maximum outgoing record payload length is 16383" \ -s "Maximum incoming record payload length is 16384" # Tests for renegotiation From 2a2462e8f93d290220cd63956fb1ada69646dc1f Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Fri, 5 Jan 2024 18:58:46 +0000 Subject: [PATCH 11/25] Add Changlog entry for record size extension Signed-off-by: Waleed Elmelegy --- ChangeLog.d/add-record-size-limit-extension-support.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ChangeLog.d/add-record-size-limit-extension-support.txt diff --git a/ChangeLog.d/add-record-size-limit-extension-support.txt b/ChangeLog.d/add-record-size-limit-extension-support.txt new file mode 100644 index 0000000000..ca1a7c268d --- /dev/null +++ b/ChangeLog.d/add-record-size-limit-extension-support.txt @@ -0,0 +1,2 @@ +Features + * Add support for sending and receiving Record Size Limit extension. From 9457e67afd58b5e3deb67dbceb9662c34daeff41 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Mon, 8 Jan 2024 15:40:12 +0000 Subject: [PATCH 12/25] update record size limit tests to be more consistent Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index f47cc8ef6e..12605f5b01 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -4836,8 +4836,9 @@ run_test "Max fragment length: DTLS client, larger message" \ requires_gnutls_tls1_3 requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_SRV_C MBEDTLS_DEBUG_C requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT -requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED run_test "Record Size Limit: TLS 1.3: Server-side parsing and debug output" \ "$P_SRV debug_level=3 force_version=tls13" \ "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3 -V -d 4" \ @@ -4849,20 +4850,17 @@ run_test "Record Size Limit: TLS 1.3: Server-side parsing and debug output" \ requires_gnutls_tls1_3 requires_gnutls_record_size_limit -requires_gnutls_next_disable_tls13_compat +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT -requires_config_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED run_test "Record Size Limit: TLS 1.3: Client-side parsing and debug output" \ - "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL:%DISABLE_TLS13_COMPAT_MODE --disable-client-cert -d 4" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL --disable-client-cert -d 4" \ "$P_CLI debug_level=4 force_version=tls13" \ 0 \ -c "Sent RecordSizeLimit: 16384 Bytes" \ -c "ClientHello: record_size_limit(28) extension exists." \ - -c "found record_size_limit extension" \ -c "EncryptedExtensions: record_size_limit(28) extension received." \ -c "RecordSizeLimit: 16385 Bytes" \ - -s "Parsing extension 'Record Size Limit/28' (2 bytes)" \ - -s "record_size_limit 16384 negotiated" # In the following (9) tests, --recordsize is the value used by the G_NEXT_CLI (3.7.2) to configure the # maximum record size using "https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-size". @@ -4889,10 +4887,13 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit "$P_SRV debug_level=3 force_version=tls13 tls13_kex_modes=psk \ psk_list=Client_identity,6162636465666768696a6b6c6d6e6f70 \ response_size=256" \ - "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK --recordsize 512 \ - --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \ + "$G_NEXT_CLI localhost --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+PSK --recordsize 512 \ + --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \ 0 \ -s "RecordSizeLimit: 513 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 511" \ -s "256 bytes written in 1 fragments" @@ -4909,6 +4910,9 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \ 0 \ -s "RecordSizeLimit: 513 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 511" \ -s "768 bytes written in 2 fragments" @@ -4925,6 +4929,9 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit --pskusername Client_identity --pskkey=6162636465666768696a6b6c6d6e6f70" \ 0 \ -s "RecordSizeLimit: 513 Bytes" \ + -s "ClientHello: record_size_limit(28) extension exists." \ + -s "Sent RecordSizeLimit: 16384 Bytes" \ + -s "EncryptedExtensions: record_size_limit(28) extension exists." \ -s "Maximum outgoing record payload length is 511" \ -s "1280 bytes written in 3 fragments" From f501790ff20bf3896fff6299fd1f889106fab047 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Tue, 9 Jan 2024 14:18:34 +0000 Subject: [PATCH 13/25] Improve comments across record size limit changes Signed-off-by: Waleed Elmelegy --- library/ssl_misc.h | 1 + library/ssl_tls.c | 18 +++++++++--------- tests/ssl-opt.sh | 20 ++++++++++++-------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/library/ssl_misc.h b/library/ssl_misc.h index 7195d63432..2e621be89d 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -2704,6 +2704,7 @@ int mbedtls_ssl_parse_server_name_ext(mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) #define MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH (2) +/* This value is defined by RFC 8449 */ #define MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN (64) MBEDTLS_CHECK_RETURN_CRITICAL diff --git a/library/ssl_tls.c b/library/ssl_tls.c index f92e40ac72..517af785a6 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -3521,15 +3521,15 @@ int mbedtls_ssl_get_max_out_record_payload(const mbedtls_ssl_context *ssl) if (ssl->transform_out != NULL && ssl->transform_out->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) { - /* RFC 8449, section 4: - * - * This value [record_size_limit] is the length of the plaintext - * of a protected record. - * The value includes the content type and padding added in TLS 1.3 - * (that is, the complete length of TLSInnerPlaintext). - * - * Thus, round down to a multiple of MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY - * and subtract 1 (for the content type that will be added later) + /* + * In TLS 1.3 case, when records are protected, `max_len` as computed + * above is the maximum length of the TLSInnerPlaintext structure that + * along the plaintext payload contains the inner content type (one byte) + * and some zero padding. Given the algorithm used for padding + * in mbedtls_ssl_encrypt_buf(), compute the maximum length for + * the plaintext payload. Round down to a multiple of + * MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY and + * subtract 1. */ max_len = ((max_len / MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY) * MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY) - 1; diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 12605f5b01..30e6a725a5 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -4862,16 +4862,18 @@ run_test "Record Size Limit: TLS 1.3: Client-side parsing and debug output" \ -c "EncryptedExtensions: record_size_limit(28) extension received." \ -c "RecordSizeLimit: 16385 Bytes" \ -# In the following (9) tests, --recordsize is the value used by the G_NEXT_CLI (3.7.2) to configure the -# maximum record size using "https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-size". -# There is currently a lower limit of 512, caused by this function not respecting the -# "%ALLOW_SMALL_RECORDS" priority string and not using the more recent function -# https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-recv-size. +# In the following tests, --recordsize is the value used by the G_NEXT_CLI (3.7.2) to configure the +# maximum record size using gnutls_record_set_max_size() +# (https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-size). +# There is currently a lower limit of 512, caused by gnutls_record_set_max_size() +# not respecting the "%ALLOW_SMALL_RECORDS" priority string and not using the +# more recent function gnutls_record_set_max_recv_size() +# (https://gnutls.org/reference/gnutls-gnutls.html#gnutls-record-set-max-recv-size). # There is currently an upper limit of 4096, caused by the cli arg parser: # https://gitlab.com/gnutls/gnutls/-/blob/3.7.2/src/cli-args.def#L395. -# Thus, these tests are currently limit to that value range. -# Moreover, the value sent in the extension is expected to be larger by one compared -# to the value passed on the cli: +# Thus, these tests are currently limited to the value range 512-4096. +# Also, the value sent in the extension will be one larger than the value +# set at the command line: # https://gitlab.com/gnutls/gnutls/-/blob/3.7.2/lib/ext/record_size_limit.c#L142 # Currently test certificates being used do not fit in 513 record size limit @@ -5050,6 +5052,8 @@ run_test "Record Size Limit: TLS 1.3 m->m: both peer comply with record size -s "Maximum outgoing record payload length is 16383" \ -s "Maximum incoming record payload length is 16384" +# End of Record size limit tests + # Tests for renegotiation # Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION From 2fa99b2ddd5581f922a85555d84352cc291ff8d9 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Tue, 9 Jan 2024 17:15:03 +0000 Subject: [PATCH 14/25] Add tests for client complying with record size limit Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 145 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 30e6a725a5..a0811a4289 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -5033,6 +5033,150 @@ run_test "Record Size Limit: TLS 1.3: Server complies with record size limit -s "Maximum outgoing record payload length is 4095" \ -s "10240 bytes written in 3 fragments" +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (513), 1 fragment" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=256" \ + 0 \ + -c "RecordSizeLimit: 513 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 511" \ + -c "256 bytes written in 1 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (513), 2 fragments" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=768" \ + 0 \ + -c "RecordSizeLimit: 513 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 511" \ + -c "768 bytes written in 2 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (513), 3 fragments" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=1280" \ + 0 \ + -c "RecordSizeLimit: 513 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 511" \ + -c "1280 bytes written in 3 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (1024), 1 fragment" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=512" \ + 0 \ + -c "RecordSizeLimit: 1024 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 1023" \ + -c "512 bytes written in 1 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (1024), 2 fragments" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=1536" \ + 0 \ + -c "RecordSizeLimit: 1024 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 1023" \ + -c "1536 bytes written in 2 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (1024), 3 fragments" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=2560" \ + 0 \ + -c "RecordSizeLimit: 1024 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 1023" \ + -c "2560 bytes written in 3 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (4096), 1 fragment" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=2048" \ + 0 \ + -c "RecordSizeLimit: 4096 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 4095" \ + -c "2048 bytes written in 1 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (4096), 2 fragments" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=6144" \ + 0 \ + -c "RecordSizeLimit: 4096 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 4095" \ + -c "6144 bytes written in 2 fragments" + +requires_gnutls_tls1_3 +requires_gnutls_record_size_limit +requires_all_configs_enabled MBEDTLS_SSL_TLS1_3_COMPATIBILITY_MODE MBEDTLS_SSL_CLI_C MBEDTLS_DEBUG_C +requires_config_enabled MBEDTLS_SSL_RECORD_SIZE_LIMIT +requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED +run_test "Record Size Limit: TLS 1.3: Client complies with record size limit (4096), 3 fragments" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \ + "$P_CLI debug_level=4 force_version=tls13 request_size=10240" \ + 0 \ + -c "RecordSizeLimit: 4096 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "EncryptedExtensions: record_size_limit(28) extension exists." \ + -c "Maximum outgoing record payload length is 4095" \ + -c "10240 bytes written in 3 fragments" + # TODO: For time being, we send fixed value of RecordSizeLimit defined by # MBEDTLS_SSL_IN_CONTENT_LEN. Once we support variable buffer length of # RecordSizeLimit, we need to modify value of RecordSizeLimit in below test. @@ -5046,7 +5190,6 @@ run_test "Record Size Limit: TLS 1.3 m->m: both peer comply with record size 0 \ -c "Sent RecordSizeLimit: $MAX_IN_LEN Bytes" \ -c "RecordSizeLimit: $MAX_IN_LEN Bytes" \ - -c "Maximum outgoing record payload length is 16383" \ -s "RecordSizeLimit: $MAX_IN_LEN Bytes" \ -s "Sent RecordSizeLimit: $MAX_IN_LEN Bytes" \ -s "Maximum outgoing record payload length is 16383" \ From e840263f76c830e17d09a1d8f4d4e5ab8b1644d1 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Tue, 9 Jan 2024 17:21:20 +0000 Subject: [PATCH 15/25] Move record size limit testing to tls13 component Signed-off-by: Waleed Elmelegy --- tests/scripts/all.sh | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index f1b9cc23a6..1ab7e5833a 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -5645,6 +5645,7 @@ support_build_armcc () { component_test_tls13_only () { msg "build: default config with MBEDTLS_SSL_PROTO_TLS1_3, without MBEDTLS_SSL_PROTO_TLS1_2" scripts/config.py set MBEDTLS_SSL_EARLY_DATA + scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'" msg "test: TLS 1.3 only, all key exchange modes enabled" @@ -5807,18 +5808,6 @@ component_test_tls13_no_compatibility_mode () { tests/ssl-opt.sh } -component_test_tls13_only_record_size_limit () { - msg "build: TLS 1.3 only from default, record size limit extension enabled" - scripts/config.py set MBEDTLS_SSL_RECORD_SIZE_LIMIT - make CFLAGS="'-DMBEDTLS_USER_CONFIG_FILE=\"../tests/configs/tls13-only.h\"'" - - msg "test_suite_ssl: TLS 1.3 only, record size limit extension enabled" - cd tests; ./test_suite_ssl; cd .. - - msg "ssl-opt.sh: (TLS 1.3 only, record size limit extension enabled)" - tests/ssl-opt.sh -} - component_build_mingw () { msg "build: Windows cross build - mingw64, make (Link Library)" # ~ 30s make CC=i686-w64-mingw32-gcc AR=i686-w64-mingw32-ar LD=i686-w64-minggw32-ld CFLAGS='-Werror -Wall -Wextra -maes -msse2 -mpclmul' WINDOWS_BUILD=1 lib programs From f37c70746b1c6645564b68ee52eb5e1fb55e232d Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Tue, 9 Jan 2024 17:22:46 +0000 Subject: [PATCH 16/25] Add MBEDTLS_SSL_RECORD_SIZE_LIMIT to full config Signed-off-by: Waleed Elmelegy --- scripts/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/config.py b/scripts/config.py index d5fb85e52d..ab0e5ea6e8 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -207,7 +207,6 @@ EXCLUDE_FROM_FULL = frozenset([ 'MBEDTLS_SHA256_USE_ARMV8_A_CRYPTO_ONLY', # interacts with *_USE_ARMV8_A_CRYPTO_IF_PRESENT 'MBEDTLS_SHA512_USE_A64_CRYPTO_ONLY', # interacts with *_USE_A64_CRYPTO_IF_PRESENT 'MBEDTLS_SHA256_USE_A64_CRYPTO_IF_PRESENT', # setting *_USE_ARMV8_A_CRYPTO is sufficient - 'MBEDTLS_SSL_RECORD_SIZE_LIMIT', # in development, currently breaks other tests 'MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN', # build dependency (clang+memsan) 'MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND', # build dependency (valgrind headers) 'MBEDTLS_X509_REMOVE_INFO', # removes a feature From 7ae74b74cc8001cb83f61885893b05685966b933 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Tue, 9 Jan 2024 21:51:05 +0000 Subject: [PATCH 17/25] Make sure record size limit is not configured without TLS 1.3 Signed-off-by: Waleed Elmelegy --- tests/scripts/all.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index 1ab7e5833a..cf8d920c53 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1335,6 +1335,7 @@ component_test_no_ctr_drbg_classic () { scripts/config.py unset MBEDTLS_CTR_DRBG_C scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . make @@ -1381,6 +1382,7 @@ component_test_no_hmac_drbg_classic () { scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . make @@ -1434,6 +1436,7 @@ component_test_psa_external_rng_no_drbg_classic () { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG scripts/config.py unset MBEDTLS_ENTROPY_C scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED @@ -2436,6 +2439,7 @@ component_test_no_use_psa_crypto_full_cmake_asan() { scripts/config.py unset MBEDTLS_PSA_CRYPTO_C scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C @@ -3360,6 +3364,7 @@ build_and_test_psa_want_key_pair_partial() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in # crypto_config.h so we just disable the one we don't want. @@ -3958,6 +3963,7 @@ component_build_psa_accel_alg_ecdh() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py unset MBEDTLS_ECDH_C scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED @@ -3974,6 +3980,7 @@ component_build_psa_accel_alg_hmac() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT # Need to define the correct symbol and include the test driver header path in order to build with the test driver make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include" LDFLAGS="$ASAN_CFLAGS" } @@ -3984,9 +3991,11 @@ component_build_psa_accel_alg_hkdf() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py unset MBEDTLS_HKDF_C # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT # Need to define the correct symbol and include the test driver header path in order to build with the test driver make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include" LDFLAGS="$ASAN_CFLAGS" } @@ -3997,6 +4006,7 @@ component_build_psa_accel_alg_md5() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224 @@ -4016,6 +4026,7 @@ component_build_psa_accel_alg_ripemd160() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224 @@ -4035,6 +4046,7 @@ component_build_psa_accel_alg_sha1() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224 @@ -4054,6 +4066,7 @@ component_build_psa_accel_alg_sha224() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4070,6 +4083,7 @@ component_build_psa_accel_alg_sha256() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4086,6 +4100,7 @@ component_build_psa_accel_alg_sha384() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4104,6 +4119,7 @@ component_build_psa_accel_alg_sha512() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4123,6 +4139,7 @@ component_build_psa_accel_alg_rsa_pkcs1v15_crypt() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP @@ -4137,6 +4154,7 @@ component_build_psa_accel_alg_rsa_pkcs1v15_sign() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP @@ -4151,6 +4169,7 @@ component_build_psa_accel_alg_rsa_oaep() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN @@ -4165,6 +4184,7 @@ component_build_psa_accel_alg_rsa_pss() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN @@ -4179,6 +4199,7 @@ component_build_psa_accel_key_type_rsa_key_pair() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1 @@ -4194,6 +4215,7 @@ component_build_psa_accel_key_type_rsa_public_key() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 + scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1 # Need to define the correct symbol and include the test driver header path in order to build with the test driver From a3bfdea82b55710bd1a1ff7ae6ebeecc3bc44634 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 10 Jan 2024 15:30:46 +0000 Subject: [PATCH 18/25] Revert "Make sure record size limit is not configured without TLS 1.3" This reverts commit 52cac7a3e6782bbf46a76158c9034afad53981a7. Signed-off-by: Waleed Elmelegy --- tests/scripts/all.sh | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index cf8d920c53..1ab7e5833a 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -1335,7 +1335,6 @@ component_test_no_ctr_drbg_classic () { scripts/config.py unset MBEDTLS_CTR_DRBG_C scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . make @@ -1382,7 +1381,6 @@ component_test_no_hmac_drbg_classic () { scripts/config.py unset MBEDTLS_ECDSA_DETERMINISTIC # requires HMAC_DRBG scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT CC=$ASAN_CC cmake -D CMAKE_BUILD_TYPE:String=Asan . make @@ -1436,7 +1434,6 @@ component_test_psa_external_rng_no_drbg_classic () { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py set MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG scripts/config.py unset MBEDTLS_ENTROPY_C scripts/config.py unset MBEDTLS_ENTROPY_NV_SEED @@ -2439,7 +2436,6 @@ component_test_no_use_psa_crypto_full_cmake_asan() { scripts/config.py unset MBEDTLS_PSA_CRYPTO_C scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py unset MBEDTLS_PSA_ITS_FILE_C scripts/config.py unset MBEDTLS_PSA_CRYPTO_SE_C scripts/config.py unset MBEDTLS_PSA_CRYPTO_STORAGE_C @@ -3364,7 +3360,6 @@ build_and_test_psa_want_key_pair_partial() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT # All the PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy are enabled by default in # crypto_config.h so we just disable the one we don't want. @@ -3963,7 +3958,6 @@ component_build_psa_accel_alg_ecdh() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py unset MBEDTLS_ECDH_C scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED scripts/config.py unset MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED @@ -3980,7 +3974,6 @@ component_build_psa_accel_alg_hmac() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT # Need to define the correct symbol and include the test driver header path in order to build with the test driver make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HMAC -I../tests/include" LDFLAGS="$ASAN_CFLAGS" } @@ -3991,11 +3984,9 @@ component_build_psa_accel_alg_hkdf() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py unset MBEDTLS_HKDF_C # Make sure to unset TLS1_3 since it requires HKDF_C and will not build properly without it. scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT # Need to define the correct symbol and include the test driver header path in order to build with the test driver make CC=$ASAN_CC CFLAGS="$ASAN_CFLAGS -DPSA_CRYPTO_DRIVER_TEST -DMBEDTLS_PSA_ACCEL_ALG_HKDF -I../tests/include" LDFLAGS="$ASAN_CFLAGS" } @@ -4006,7 +3997,6 @@ component_build_psa_accel_alg_md5() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224 @@ -4026,7 +4016,6 @@ component_build_psa_accel_alg_ripemd160() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224 @@ -4046,7 +4035,6 @@ component_build_psa_accel_alg_sha1() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_224 @@ -4066,7 +4054,6 @@ component_build_psa_accel_alg_sha224() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4083,7 +4070,6 @@ component_build_psa_accel_alg_sha256() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4100,7 +4086,6 @@ component_build_psa_accel_alg_sha384() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4119,7 +4104,6 @@ component_build_psa_accel_alg_sha512() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_MD5 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RIPEMD160 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_SHA_1 @@ -4139,7 +4123,6 @@ component_build_psa_accel_alg_rsa_pkcs1v15_crypt() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_CRYPT 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP @@ -4154,7 +4137,6 @@ component_build_psa_accel_alg_rsa_pkcs1v15_sign() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PKCS1V15_SIGN 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_OAEP @@ -4169,7 +4151,6 @@ component_build_psa_accel_alg_rsa_oaep() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_OAEP 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN @@ -4184,7 +4165,6 @@ component_build_psa_accel_alg_rsa_pss() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1 scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_CRYPT scripts/config.py -f "$CRYPTO_CONFIG_H" unset PSA_WANT_ALG_RSA_PKCS1V15_SIGN @@ -4199,7 +4179,6 @@ component_build_psa_accel_key_type_rsa_key_pair() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC 1 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT 1 @@ -4215,7 +4194,6 @@ component_build_psa_accel_key_type_rsa_public_key() { scripts/config.py full scripts/config.py unset MBEDTLS_USE_PSA_CRYPTO scripts/config.py unset MBEDTLS_SSL_PROTO_TLS1_3 - scripts/config.py unset MBEDTLS_SSL_RECORD_SIZE_LIMIT scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_ALG_RSA_PSS 1 scripts/config.py -f "$CRYPTO_CONFIG_H" set PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY 1 # Need to define the correct symbol and include the test driver header path in order to build with the test driver From 09561a75750d4924b5c06eb8cedee32433455369 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 10 Jan 2024 16:13:53 +0000 Subject: [PATCH 19/25] Add MBEDTLS_SSL_RECORD_SIZE_LIMIT to config_adjust_ssl.h Signed-off-by: Waleed Elmelegy --- include/mbedtls/config_adjust_ssl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mbedtls/config_adjust_ssl.h b/include/mbedtls/config_adjust_ssl.h index 8415f3e5f5..5dd331c765 100644 --- a/include/mbedtls/config_adjust_ssl.h +++ b/include/mbedtls/config_adjust_ssl.h @@ -65,6 +65,7 @@ #undef MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED #undef MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL_ENABLED #undef MBEDTLS_SSL_EARLY_DATA +#undef MBEDTLS_SSL_RECORD_SIZE_LIMIT #endif #if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \ From 1487760b550c9cd87168ffa4ce464e8e80d94992 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 10 Jan 2024 16:15:08 +0000 Subject: [PATCH 20/25] Change order of checking of record size limit client tests Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index a0811a4289..10d75a77f2 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -5042,9 +5042,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \ "$P_CLI debug_level=4 force_version=tls13 request_size=256" \ 0 \ - -c "RecordSizeLimit: 513 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 513 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 511" \ -c "256 bytes written in 1 fragments" @@ -5058,9 +5058,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \ "$P_CLI debug_level=4 force_version=tls13 request_size=768" \ 0 \ - -c "RecordSizeLimit: 513 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 513 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 511" \ -c "768 bytes written in 2 fragments" @@ -5074,9 +5074,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --disable-client-cert --recordsize 512" \ "$P_CLI debug_level=4 force_version=tls13 request_size=1280" \ 0 \ - -c "RecordSizeLimit: 513 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 513 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 511" \ -c "1280 bytes written in 3 fragments" @@ -5090,9 +5090,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \ "$P_CLI debug_level=4 force_version=tls13 request_size=512" \ 0 \ - -c "RecordSizeLimit: 1024 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 1024 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 1023" \ -c "512 bytes written in 1 fragments" @@ -5106,9 +5106,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \ "$P_CLI debug_level=4 force_version=tls13 request_size=1536" \ 0 \ - -c "RecordSizeLimit: 1024 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 1024 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 1023" \ -c "1536 bytes written in 2 fragments" @@ -5122,9 +5122,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 1023" \ "$P_CLI debug_level=4 force_version=tls13 request_size=2560" \ 0 \ - -c "RecordSizeLimit: 1024 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 1024 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 1023" \ -c "2560 bytes written in 3 fragments" @@ -5138,9 +5138,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \ "$P_CLI debug_level=4 force_version=tls13 request_size=2048" \ 0 \ - -c "RecordSizeLimit: 4096 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 4096 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 4095" \ -c "2048 bytes written in 1 fragments" @@ -5154,9 +5154,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \ "$P_CLI debug_level=4 force_version=tls13 request_size=6144" \ 0 \ - -c "RecordSizeLimit: 4096 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 4096 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 4095" \ -c "6144 bytes written in 2 fragments" @@ -5170,9 +5170,9 @@ run_test "Record Size Limit: TLS 1.3: Client complies with record size limit "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.3:+CIPHER-ALL -d 4 --recordsize 4095" \ "$P_CLI debug_level=4 force_version=tls13 request_size=10240" \ 0 \ - -c "RecordSizeLimit: 4096 Bytes" \ - -c "ClientHello: record_size_limit(28) extension exists." \ -c "Sent RecordSizeLimit: 16384 Bytes" \ + -c "ClientHello: record_size_limit(28) extension exists." \ + -c "RecordSizeLimit: 4096 Bytes" \ -c "EncryptedExtensions: record_size_limit(28) extension exists." \ -c "Maximum outgoing record payload length is 4095" \ -c "10240 bytes written in 3 fragments" From 3ff472441a704aa15aa55cf57d16c3e1b63062ab Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 10 Jan 2024 16:15:52 +0000 Subject: [PATCH 21/25] Fix warning in ssl_tls13_generic.c Signed-off-by: Waleed Elmelegy --- library/ssl_tls13_generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/ssl_tls13_generic.c b/library/ssl_tls13_generic.c index 0afedbc356..47fa65c188 100644 --- a/library/ssl_tls13_generic.c +++ b/library/ssl_tls13_generic.c @@ -1774,7 +1774,7 @@ int mbedtls_ssl_tls13_write_record_size_limit_ext(mbedtls_ssl_context *ssl, *out_len = 6; - MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %u Bytes", + MBEDTLS_SSL_DEBUG_MSG(2, ("Sent RecordSizeLimit: %d Bytes", MBEDTLS_SSL_IN_CONTENT_LEN)); mbedtls_ssl_tls13_set_hs_sent_ext_mask(ssl, MBEDTLS_TLS_EXT_RECORD_SIZE_LIMIT); From e83be5f639311adcd8bead731786cdaa49d920d3 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Wed, 10 Jan 2024 23:39:54 +0000 Subject: [PATCH 22/25] Change renegotiation tests to work with TLS 1.2 only Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 10d75a77f2..5f0daaa1e7 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -5530,7 +5530,7 @@ requires_config_enabled MBEDTLS_SSL_RENEGOTIATION requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renegotiation: gnutls server strict, client-initiated" \ "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \ - "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \ + "$P_CLI force_version=tls12 debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \ 0 \ -c "client hello, adding renegotiation extension" \ -c "found renegotiation extension" \ @@ -5649,7 +5649,7 @@ requires_gnutls requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renego ext: gnutls server strict, client default" \ "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \ - "$P_CLI debug_level=3" \ + "$P_CLI force_version=tls12 debug_level=3" \ 0 \ -c "found renegotiation extension" \ -C "error" \ From 85ddd43656b420d1812aaa1c68c8bc280193c209 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Thu, 11 Jan 2024 11:07:57 +0000 Subject: [PATCH 23/25] Improve record size limit changelog wording Signed-off-by: Waleed Elmelegy --- ChangeLog.d/add-record-size-limit-extension-support.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog.d/add-record-size-limit-extension-support.txt b/ChangeLog.d/add-record-size-limit-extension-support.txt index ca1a7c268d..bc954003ab 100644 --- a/ChangeLog.d/add-record-size-limit-extension-support.txt +++ b/ChangeLog.d/add-record-size-limit-extension-support.txt @@ -1,2 +1,5 @@ Features - * Add support for sending and receiving Record Size Limit extension. + * Add support for Record Size Limit extension as defined by RFC 8449 + and configured with MBEDTLS_SSL_RECORD_SIZE_LIMIT. + Application data sent and received will be fragmented according to + Record size limits negotiated during handshake. From 4b09dcd19c68c24a07bd81be88606e665f7ddfeb Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Fri, 12 Jan 2024 10:50:25 +0000 Subject: [PATCH 24/25] Change renegotiation test to use G_NEXT_SRV Change renegotiation test to use G_NEXT_SRV to avoid problems when sending TLS 1.3 extensions since we exceed the extension limit in G_SRV. Signed-off-by: Waleed Elmelegy --- tests/ssl-opt.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 5f0daaa1e7..e5637e3e55 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -5199,6 +5199,10 @@ run_test "Record Size Limit: TLS 1.3 m->m: both peer comply with record size # Tests for renegotiation +# G_NEXT_SRV is used in renegotiation tests becuase of the increased +# extensions limit since we exceed the limit in G_SRV when we send +# TLS 1.3 extensions in the initial handshake. + # Renegotiation SCSV always added, regardless of SSL_RENEGOTIATION run_test "Renegotiation: none, for reference" \ "$P_SRV debug_level=3 exchanges=2 auth_mode=optional" \ @@ -5529,8 +5533,8 @@ requires_gnutls requires_config_enabled MBEDTLS_SSL_RENEGOTIATION requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renegotiation: gnutls server strict, client-initiated" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \ - "$P_CLI force_version=tls12 debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \ + "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \ 0 \ -c "client hello, adding renegotiation extension" \ -c "found renegotiation extension" \ @@ -5543,7 +5547,7 @@ requires_gnutls requires_config_enabled MBEDTLS_SSL_RENEGOTIATION requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renegotiation: gnutls server unsafe, client-initiated default" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1" \ 1 \ -c "client hello, adding renegotiation extension" \ @@ -5557,7 +5561,7 @@ requires_gnutls requires_config_enabled MBEDTLS_SSL_RENEGOTIATION requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renegotiation: gnutls server unsafe, client-inititated no legacy" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \ allow_legacy=0" \ 1 \ @@ -5572,7 +5576,7 @@ requires_gnutls requires_config_enabled MBEDTLS_SSL_RENEGOTIATION requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renegotiation: gnutls server unsafe, client-inititated legacy" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ "$P_CLI debug_level=3 exchanges=1 renegotiation=1 renegotiate=1 \ allow_legacy=1" \ 0 \ @@ -5633,7 +5637,7 @@ requires_gnutls requires_config_enabled MBEDTLS_SSL_RENEGOTIATION requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renegotiation: DTLS, gnutls server, client-initiated" \ - "$G_SRV -u --mtu 4096" \ + "$G_NEXT_SRV -u --mtu 4096" \ "$P_CLI debug_level=3 dtls=1 exchanges=1 renegotiation=1 renegotiate=1" \ 0 \ -c "client hello, adding renegotiation extension" \ @@ -5648,8 +5652,8 @@ run_test "Renegotiation: DTLS, gnutls server, client-initiated" \ requires_gnutls requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renego ext: gnutls server strict, client default" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \ - "$P_CLI force_version=tls12 debug_level=3" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%SAFE_RENEGOTIATION" \ + "$P_CLI debug_level=3" \ 0 \ -c "found renegotiation extension" \ -C "error" \ @@ -5658,7 +5662,7 @@ run_test "Renego ext: gnutls server strict, client default" \ requires_gnutls requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renego ext: gnutls server unsafe, client default" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ "$P_CLI debug_level=3" \ 0 \ -C "found renegotiation extension" \ @@ -5668,7 +5672,7 @@ run_test "Renego ext: gnutls server unsafe, client default" \ requires_gnutls requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2 run_test "Renego ext: gnutls server unsafe, client break legacy" \ - "$G_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ + "$G_NEXT_SRV --priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:%DISABLE_SAFE_RENEGOTIATION" \ "$P_CLI debug_level=3 allow_legacy=-1" \ 1 \ -C "found renegotiation extension" \ From f0ccf467139a023b4fb7edabc21339ac49057c19 Mon Sep 17 00:00:00 2001 From: Waleed Elmelegy Date: Fri, 12 Jan 2024 10:52:45 +0000 Subject: [PATCH 25/25] Add minor cosmetic changes to record size limit changelog and comments Signed-off-by: Waleed Elmelegy --- ChangeLog.d/add-record-size-limit-extension-support.txt | 2 +- library/ssl_misc.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ChangeLog.d/add-record-size-limit-extension-support.txt b/ChangeLog.d/add-record-size-limit-extension-support.txt index bc954003ab..3562b85044 100644 --- a/ChangeLog.d/add-record-size-limit-extension-support.txt +++ b/ChangeLog.d/add-record-size-limit-extension-support.txt @@ -1,5 +1,5 @@ Features - * Add support for Record Size Limit extension as defined by RFC 8449 + * Add support for record size limit extension as defined by RFC 8449 and configured with MBEDTLS_SSL_RECORD_SIZE_LIMIT. Application data sent and received will be fragmented according to Record size limits negotiated during handshake. diff --git a/library/ssl_misc.h b/library/ssl_misc.h index 2e621be89d..b0cdd5d789 100644 --- a/library/ssl_misc.h +++ b/library/ssl_misc.h @@ -2704,8 +2704,7 @@ int mbedtls_ssl_parse_server_name_ext(mbedtls_ssl_context *ssl, #if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT) #define MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH (2) -/* This value is defined by RFC 8449 */ -#define MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN (64) +#define MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN (64) /* As defined in RFC 8449 */ MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl,