Skip to content

Commit f9990f3

Browse files
Merge pull request #10704 from Maokaman1/fix/tls12-rsa-pss-sigalgs-4.1
Backport 4.1: ssl: accept TLS 1.2 rsa_pss_rsae signature algorithms
2 parents e589739 + 4302c8d commit f9990f3

3 files changed

Lines changed: 98 additions & 11 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Bugfix
2+
* Fix a TLS 1.2 regression that caused clients to reject valid
3+
ServerKeyExchange signatures using RSA-PSS signature algorithms.
4+
Fixes #10668.

library/ssl_tls12_client.c

Lines changed: 57 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,77 @@ 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+
#endif
1783+
#if defined(PSA_WANT_ALG_SHA_384)
1784+
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
1785+
#endif
1786+
#if defined(PSA_WANT_ALG_SHA_512)
1787+
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
1788+
#endif
1789+
#if defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA_384) || defined(PSA_WANT_ALG_SHA_512)
1790+
MBEDTLS_SSL_DEBUG_MSG(3,
1791+
(
1792+
"Accepting TLS 1.2 RSA-PSS signature algorithm %s via compatibility exception",
1793+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
1794+
break;
1795+
#endif
1796+
#endif /* PSA_WANT_ALG_RSA_PSS */
1797+
default:
1798+
MBEDTLS_SSL_DEBUG_MSG(1,
1799+
("Server used unsupported %s signature algorithm",
1800+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
1801+
return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER;
1802+
}
17591803
}
17601804

17611805
/*
17621806
* Check if the signature algorithm is acceptable
17631807
*/
17641808
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));
1809+
MBEDTLS_SSL_DEBUG_MSG(1,
1810+
("Server used the signature algorithm %s that was not offered",
1811+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
17661812
return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER;
17671813
}
17681814

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));
1815+
MBEDTLS_SSL_DEBUG_MSG(2, ("Server used the signature algorithm %s",
1816+
mbedtls_ssl_sig_alg_to_str(sig_alg)));
17711817

17721818
return 0;
17731819
}

tests/ssl-opt.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13954,6 +13954,43 @@ run_test "TLS 1.2: Check rsa_pss_rsae compatibility issue, m->G" \
1395413954
-c "Protocol is TLSv1.2" \
1395513955
-c "HTTP/1.0 200 [Oo][Kk]"
1395613956

13957+
requires_openssl_tls1_3_with_compatible_ephemeral
13958+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13959+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
13960+
requires_config_enabled MBEDTLS_DEBUG_C
13961+
requires_config_enabled MBEDTLS_SSL_CLI_C
13962+
requires_config_enabled PSA_WANT_ALG_RSA_PSS
13963+
requires_config_enabled PSA_WANT_ALG_SHA_256
13964+
run_test "TLS 1.2: Server forces TLS 1.2 and rsa_pss_rsae_sha256, m->O" \
13965+
"$O_NEXT_SRV_NO_CERT -cert $DATA_FILES_PATH/server2-sha256.crt -key $DATA_FILES_PATH/server2.key
13966+
-tls1_2 -sigalgs rsa_pss_rsae_sha256 " \
13967+
"$P_CLI debug_level=3" \
13968+
0 \
13969+
-c "sent signature scheme \\[804\\] rsa_pss_rsae_sha256" \
13970+
-c "Perform .* computation of digest of ServerKeyExchange" \
13971+
-c "Server used the signature algorithm rsa_pss_rsae_sha256" \
13972+
-c "Protocol is TLSv1.2" \
13973+
-c "HTTP/1.0 200 [Oo][Kk]"
13974+
13975+
requires_gnutls_tls1_3
13976+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_2
13977+
requires_config_enabled MBEDTLS_SSL_PROTO_TLS1_3
13978+
requires_config_enabled MBEDTLS_DEBUG_C
13979+
requires_config_enabled MBEDTLS_SSL_CLI_C
13980+
requires_config_enabled PSA_WANT_ALG_RSA_PSS
13981+
requires_config_enabled PSA_WANT_ALG_SHA_256
13982+
run_test "TLS 1.2: Server forces TLS 1.2 and rsa_pss_rsae_sha256, m->G" \
13983+
"$G_NEXT_SRV_NO_CERT --x509certfile $DATA_FILES_PATH/server2-sha256.crt --x509keyfile $DATA_FILES_PATH/server2.key
13984+
--disable-client-cert
13985+
--priority=NORMAL:-VERS-ALL:+VERS-TLS1.2:-SIGN-ALL:+SIGN-RSA-PSS-RSAE-SHA256" \
13986+
"$P_CLI debug_level=3" \
13987+
0 \
13988+
-c "sent signature scheme \\[804\\] rsa_pss_rsae_sha256" \
13989+
-c "Perform .* computation of digest of ServerKeyExchange" \
13990+
-c "Server used the signature algorithm rsa_pss_rsae_sha256" \
13991+
-c "Protocol is TLSv1.2" \
13992+
-c "HTTP/1.0 200 [Oo][Kk]"
13993+
1395713994
requires_config_enabled MBEDTLS_SSL_SRV_C
1395813995
requires_config_enabled MBEDTLS_DEBUG_C
1395913996
requires_config_enabled MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED

0 commit comments

Comments
 (0)