Skip to content

Commit 2168fe9

Browse files
committed
ssl: narrow TLS 1.2 RSA-PSS handling and add interop coverage
Signed-off-by: Viktor Sokolovskiy <maokaman@gmail.com>
1 parent f75c033 commit 2168fe9

6 files changed

Lines changed: 85 additions & 81 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Bugfix
22
* Fix a TLS 1.2 regression that caused clients to reject valid
3-
ServerKeyExchange signatures using RSA-PSS signature scheme values.
3+
ServerKeyExchange signatures using RSA-PSS signature algorithms.
44
Fixes #10668.

library/ssl_misc.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,28 +2428,6 @@ static inline int mbedtls_ssl_get_pk_sigalg_and_md_alg_from_sig_alg(
24282428
static inline int mbedtls_ssl_tls12_sig_alg_is_supported(
24292429
const uint16_t sig_alg)
24302430
{
2431-
#if defined(PSA_WANT_ALG_RSA_PSS)
2432-
/* RFC 8446 Section 4.2.3 requires implementations that support RSA-PSS in
2433-
* TLS 1.3 to also accept rsa_pss_rsae_* in TLS 1.2.
2434-
*/
2435-
switch (sig_alg) {
2436-
#if defined(PSA_WANT_ALG_SHA_256)
2437-
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
2438-
return 1;
2439-
#endif
2440-
#if defined(PSA_WANT_ALG_SHA_384)
2441-
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
2442-
return 1;
2443-
#endif
2444-
#if defined(PSA_WANT_ALG_SHA_512)
2445-
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
2446-
return 1;
2447-
#endif
2448-
default:
2449-
break;
2450-
}
2451-
#endif /* PSA_WANT_ALG_RSA_PSS */
2452-
24532431
/* High byte is hash */
24542432
unsigned char hash = MBEDTLS_BYTE_1(sig_alg);
24552433
unsigned char sig = MBEDTLS_BYTE_0(sig_alg);

library/ssl_tls12_client.c

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mbedtls/platform.h"
1313

1414
#include "mbedtls/ssl.h"
15+
#include "ssl_debug_helpers.h"
1516
#include "ssl_client.h"
1617
#include "debug_internal.h"
1718
#include "mbedtls/error.h"
@@ -1742,32 +1743,73 @@ static int ssl_parse_signature_algorithm(mbedtls_ssl_context *ssl,
17421743
{
17431744
if (mbedtls_ssl_get_pk_sigalg_and_md_alg_from_sig_alg(sig_alg, pk_alg, md_alg) != 0) {
17441745
MBEDTLS_SSL_DEBUG_MSG(1,
1745-
("Server used unsupported value in SigAlg extension 0x%04x",
1746-
sig_alg));
1746+
("Server used unsupported %s signature algorithm",
1747+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
17471748
return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER;
17481749
}
17491750

17501751
/*
1751-
* mbedtls_ssl_get_pk_sigalg_and_md_alg_from_sig_alg() understands sig_alg code points across
1752-
* TLS versions. Make sure that the received sig_alg extension is valid in TLS 1.2.
1752+
* mbedtls_ssl_get_pk_sigalg_and_md_alg_from_sig_alg() understands
1753+
* signature algorithm code points from both TLS 1.2 and TLS 1.3. Make sure
1754+
* that the selected signature algorithm is acceptable when TLS 1.2 is
1755+
* negotiated.
1756+
*
1757+
* In TLS 1.2, RSA-PSS signature algorithms (rsa_pss_rsae_*) are not
1758+
* defined by RFC 5246. However, RFC 8446 Section 4.2.3 requires that
1759+
* implementations which advertise support for RSASSA-PSS must be
1760+
* prepared to accept such signatures even when TLS 1.2 is negotiated,
1761+
* provided they were offered in the signature_algorithms extension.
1762+
*
1763+
* Therefore, we allow rsa_pss_rsae_* here if:
1764+
* - the implementation supports them, and
1765+
* - they were offered in the signature_algorithms extension (checked by
1766+
* `mbedtls_ssl_sig_alg_is_offered()` below).
1767+
*
1768+
* If we were to add full support for rsa_pss_rsae_* signature algorithms
1769+
* in TLS 1.2 (not defined by RFC 5246; RFC 8446 requires implementations
1770+
* that advertise RSASSA-PSS to accept such signatures even when TLS 1.2
1771+
* is negotiated; in practice, several TLS implementations also offer and
1772+
* use these algorithms in TLS 1.2-only configurations), we should then
1773+
* integrate RSA-PSS into the TLS 1.2 signature algorithm support logic
1774+
* (`mbedtls_ssl_tls12_sig_alg_is_supported()`) instead of handling it as a
1775+
* special case here.
17531776
*/
17541777
if (!mbedtls_ssl_sig_alg_is_supported(ssl, sig_alg)) {
1755-
MBEDTLS_SSL_DEBUG_MSG(1,
1756-
("Server used unsupported value in SigAlg extension 0x%04x",
1757-
sig_alg));
1758-
return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER;
1778+
switch (sig_alg) {
1779+
#if defined(PSA_WANT_ALG_RSA_PSS)
1780+
#if defined(PSA_WANT_ALG_SHA_256)
1781+
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
1782+
break;
1783+
#endif
1784+
#if defined(PSA_WANT_ALG_SHA_384)
1785+
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
1786+
break;
1787+
#endif
1788+
#if defined(PSA_WANT_ALG_SHA_512)
1789+
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
1790+
break;
1791+
#endif
1792+
#endif /* PSA_WANT_ALG_RSA_PSS */
1793+
default:
1794+
MBEDTLS_SSL_DEBUG_MSG(1,
1795+
("Server used unsupported %s signature algorithm",
1796+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
1797+
return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER;
1798+
}
17591799
}
17601800

17611801
/*
17621802
* Check if the signature algorithm is acceptable
17631803
*/
17641804
if (!mbedtls_ssl_sig_alg_is_offered(ssl, sig_alg)) {
1765-
MBEDTLS_SSL_DEBUG_MSG(1, ("Server used SigAlg value 0x%04x that was not offered", sig_alg));
1805+
MBEDTLS_SSL_DEBUG_MSG(1,
1806+
("Server used the signature algorithm %s that was not offered",
1807+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
17661808
return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER;
17671809
}
17681810

1769-
MBEDTLS_SSL_DEBUG_MSG(2, ("Server used SignatureAlgorithm %d", sig_alg & 0x00FF));
1770-
MBEDTLS_SSL_DEBUG_MSG(2, ("Server used HashAlgorithm %d", sig_alg >> 8));
1811+
MBEDTLS_SSL_DEBUG_MSG(2, ("Server used the signature algorithm %s",
1812+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
17711813

17721814
return 0;
17731815
}

tests/ssl-opt.sh

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13938,39 +13938,55 @@ run_test "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->O" \
1393813938
-c "Protocol is TLSv1.2" \
1393913939
-c "HTTP/1.0 200 [Oo][Kk]"
1394013940

13941+
requires_gnutls_tls1_3
13942+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13943+
requires_config_enabled MBEDTLS_DEBUG_C
13944+
requires_config_enabled MBEDTLS_SSL_CLI_C
13945+
run_test "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->G" \
13946+
"$G_NEXT_SRV_NO_CERT --x509certfile $DATA_FILES_PATH/server2-sha256.crt --x509keyfile $DATA_FILES_PATH/server2.key
13947+
-d 4
13948+
--priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
13949+
"$P_CLI debug_level=4 crt_file=$DATA_FILES_PATH/server2-sha256.crt key_file=$DATA_FILES_PATH/server2.key
13950+
sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13951+
min_version=tls12 max_version=tls13 " \
13952+
0 \
13953+
-c "Protocol is TLSv1.2" \
13954+
-c "HTTP/1.0 200 [Oo][Kk]"
13955+
1394113956
requires_openssl_tls1_3_with_compatible_ephemeral
1394213957
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13958+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
1394313959
requires_config_enabled MBEDTLS_DEBUG_C
1394413960
requires_config_enabled MBEDTLS_SSL_CLI_C
1394513961
requires_config_enabled PSA_WANT_ALG_RSA_PSS
1394613962
requires_config_enabled PSA_WANT_ALG_SHA_256
13947-
run_test "TLS 1.2: OpenSSL chooses rsa_pss_rsae_sha256 for SKE, m->O" \
13963+
run_test "TLS 1.2: Server forces TLS 1.2 and rsa_pss_rsae_sha256, m->O" \
1394813964
"$O_NEXT_SRV_NO_CERT -cert $DATA_FILES_PATH/server2-sha256.crt -key $DATA_FILES_PATH/server2.key
13949-
-msg -tls1_2
13950-
-sigalgs rsa_pss_rsae_sha256 " \
13951-
"$P_CLI debug_level=4 auth_mode=none ca_file=none ca_path=none crt_file=none key_file=none
13952-
sig_algs=rsa_pss_rsae_sha256
13953-
min_version=tls12 max_version=tls12 " \
13965+
-tls1_2 -sigalgs rsa_pss_rsae_sha256 " \
13966+
"$P_CLI debug_level=3" \
1395413967
0 \
13968+
-c "sent signature scheme \\[804\\] rsa_pss_rsae_sha256" \
1395513969
-c "Perform .* computation of digest of ServerKeyExchange" \
13956-
-c "got signature scheme \\[804\\] rsa_pss_rsae_sha256" \
13957-
-c "Ciphersuite is TLS-ECDHE-RSA" \
13970+
-c "Server used the signature algorithm rsa_pss_rsae_sha256" \
1395813971
-c "Protocol is TLSv1.2" \
1395913972
-c "HTTP/1.0 200 [Oo][Kk]"
1396013973

13961-
1396213974
requires_gnutls_tls1_3
1396313975
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13976+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
1396413977
requires_config_enabled MBEDTLS_DEBUG_C
1396513978
requires_config_enabled MBEDTLS_SSL_CLI_C
13966-
run_test "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->G" \
13979+
requires_config_enabled PSA_WANT_ALG_RSA_PSS
13980+
requires_config_enabled PSA_WANT_ALG_SHA_256
13981+
run_test "TLS 1.2: Server forces TLS 1.2 and rsa_pss_rsae_sha256, m->G" \
1396713982
"$G_NEXT_SRV_NO_CERT --x509certfile $DATA_FILES_PATH/server2-sha256.crt --x509keyfile $DATA_FILES_PATH/server2.key
13968-
-d 4
13969-
--priority=NORMAL:-VERS-ALL:+VERS-TLS1.2" \
13970-
"$P_CLI debug_level=4 crt_file=$DATA_FILES_PATH/server2-sha256.crt key_file=$DATA_FILES_PATH/server2.key
13971-
sig_algs=rsa_pss_rsae_sha512,rsa_pkcs1_sha512
13972-
min_version=tls12 max_version=tls13 " \
13983+
--disable-client-cert
13984+
--priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:-SIGN-ALL:+SIGN-RSA-PSS-RSAE-SHA256" \
13985+
"$P_CLI debug_level=3" \
1397313986
0 \
13987+
-c "sent signature scheme \\[804\\] rsa_pss_rsae_sha256" \
13988+
-c "Perform .* computation of digest of ServerKeyExchange" \
13989+
-c "Server used the signature algorithm rsa_pss_rsae_sha256" \
1397413990
-c "Protocol is TLSv1.2" \
1397513991
-c "HTTP/1.0 200 [Oo][Kk]"
1397613992

tests/suites/test_suite_ssl.data

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,27 +3549,3 @@ send_invalid_sig_alg:MBEDTLS_SSL_SIG_ECDSA:MBEDTLS_SSL_HASH_SHA512:0
35493549
Negative Test: Server using sig_alg not offered by the client - ECDSA with SHA512
35503550
depends_on:MBEDTLS_CAN_HANDLE_ECDSA_TEST_KEY:MBEDTLS_CAN_HANDLE_ECDSA_CLIENT_TEST_KEY:PSA_WANT_ALG_SHA_512
35513551
send_invalid_sig_alg:MBEDTLS_SSL_SIG_ECDSA:MBEDTLS_SSL_HASH_SHA512:MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER
3552-
3553-
TLS 1.2 accepts rsa_pss_rsae_sha256 in signature_algorithm
3554-
depends_on:PSA_WANT_ALG_RSA_PSS:PSA_WANT_ALG_SHA_256
3555-
ssl_tls12_sig_alg_supported:MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:1
3556-
3557-
TLS 1.2 rejects rsa_pss_rsae_sha256 in signature_algorithm when RSA-PSS is disabled
3558-
depends_on:!PSA_WANT_ALG_RSA_PSS:PSA_WANT_ALG_SHA_256
3559-
ssl_tls12_sig_alg_supported:MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:0
3560-
3561-
TLS 1.2 accepts rsa_pss_rsae_sha384 in signature_algorithm
3562-
depends_on:PSA_WANT_ALG_RSA_PSS:PSA_WANT_ALG_SHA_384
3563-
ssl_tls12_sig_alg_supported:MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:1
3564-
3565-
TLS 1.2 rejects rsa_pss_rsae_sha384 in signature_algorithm when RSA-PSS is disabled
3566-
depends_on:!PSA_WANT_ALG_RSA_PSS:PSA_WANT_ALG_SHA_384
3567-
ssl_tls12_sig_alg_supported:MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:0
3568-
3569-
TLS 1.2 accepts rsa_pss_rsae_sha512 in signature_algorithm
3570-
depends_on:PSA_WANT_ALG_RSA_PSS:PSA_WANT_ALG_SHA_512
3571-
ssl_tls12_sig_alg_supported:MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:1
3572-
3573-
TLS 1.2 rejects rsa_pss_rsae_sha512 in signature_algorithm when RSA-PSS is disabled
3574-
depends_on:!PSA_WANT_ALG_RSA_PSS:PSA_WANT_ALG_SHA_512
3575-
ssl_tls12_sig_alg_supported:MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:0

tests/suites/test_suite_ssl.function

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5853,14 +5853,6 @@ exit:
58535853
}
58545854
/* END_CASE */
58555855

5856-
/* BEGIN_CASE depends_on:MBEDTLS_SSL_PROTO_TLS1_2:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
5857-
void ssl_tls12_sig_alg_supported(int sig_alg, int expected)
5858-
{
5859-
TEST_EQUAL(mbedtls_ssl_tls12_sig_alg_is_supported((uint16_t) sig_alg),
5860-
expected);
5861-
}
5862-
/* END_CASE */
5863-
58645856
/* BEGIN_CASE depends_on:MBEDTLS_SSL_KEYING_MATERIAL_EXPORT:MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED:PSA_WANT_ECC_SECP_R1_384:PSA_WANT_ALG_SHA_256 */
58655857
void ssl_tls_exporter_consistent_result(int proto, int exported_key_length, int use_context)
58665858
{

0 commit comments

Comments
 (0)