|
12 | 12 | #include "mbedtls/platform.h" |
13 | 13 |
|
14 | 14 | #include "mbedtls/ssl.h" |
| 15 | +#include "ssl_debug_helpers.h" |
15 | 16 | #include "ssl_client.h" |
16 | 17 | #include "debug_internal.h" |
17 | 18 | #include "mbedtls/error.h" |
@@ -1742,32 +1743,73 @@ static int ssl_parse_signature_algorithm(mbedtls_ssl_context *ssl, |
1742 | 1743 | { |
1743 | 1744 | if (mbedtls_ssl_get_pk_sigalg_and_md_alg_from_sig_alg(sig_alg, pk_alg, md_alg) != 0) { |
1744 | 1745 | 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))); |
1747 | 1748 | return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER; |
1748 | 1749 | } |
1749 | 1750 |
|
1750 | 1751 | /* |
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. |
1753 | 1776 | */ |
1754 | 1777 | 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 | + } |
1759 | 1799 | } |
1760 | 1800 |
|
1761 | 1801 | /* |
1762 | 1802 | * Check if the signature algorithm is acceptable |
1763 | 1803 | */ |
1764 | 1804 | 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))); |
1766 | 1808 | return MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER; |
1767 | 1809 | } |
1768 | 1810 |
|
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))); |
1771 | 1813 |
|
1772 | 1814 | return 0; |
1773 | 1815 | } |
|
0 commit comments