|
|
4f0b43 |
# HG changeset patch
|
|
|
4f0b43 |
# User Daiki Ueno <dueno@redhat.com>
|
|
|
4f0b43 |
# Date 1594360877 -7200
|
|
|
4f0b43 |
# Fri Jul 10 08:01:17 2020 +0200
|
|
|
4f0b43 |
# Node ID df1d2695e115ed9e6f7e8df6ad4d7be2c9bc77d8
|
|
|
4f0b43 |
# Parent de661583d46713c9b4873a904dda3a8ba4a61976
|
|
|
4f0b43 |
Bug 1646324, advertise rsa_pkcs1_* schemes in CH and CR for certs, r=mt
|
|
|
4f0b43 |
|
|
|
4f0b43 |
Summary:
|
|
|
4f0b43 |
In TLS 1.3, unless "signature_algorithms_cert" is advertised, the
|
|
|
4f0b43 |
"signature_algorithms" extension is used as an indication of supported
|
|
|
4f0b43 |
algorithms for signatures on certificates. While rsa_pkcs1_*
|
|
|
4f0b43 |
signatures schemes cannot be used for signing handshake messages, they
|
|
|
4f0b43 |
should be advertised if the peer wants to to support certificates
|
|
|
4f0b43 |
signed with RSA PKCS#1.
|
|
|
4f0b43 |
|
|
|
4f0b43 |
This adds a flag to ssl3_EncodeSigAlgs() and ssl3_FilterSigAlgs() to
|
|
|
4f0b43 |
preserve rsa_pkcs1_* schemes in the output.
|
|
|
4f0b43 |
|
|
|
4f0b43 |
Reviewers: mt
|
|
|
4f0b43 |
|
|
|
4f0b43 |
Reviewed By: mt
|
|
|
4f0b43 |
|
|
|
4f0b43 |
Bug #: 1646324
|
|
|
4f0b43 |
|
|
|
4f0b43 |
Differential Revision: https://phabricator.services.mozilla.com/D80881
|
|
|
4f0b43 |
|
|
|
4f0b43 |
diff -r de661583d467 -r df1d2695e115 gtests/ssl_gtest/ssl_auth_unittest.cc
|
|
|
4f0b43 |
--- a/gtests/ssl_gtest/ssl_auth_unittest.cc Thu Jul 09 22:45:27 2020 +0000
|
|
|
4f0b43 |
+++ b/gtests/ssl_gtest/ssl_auth_unittest.cc Fri Jul 10 08:01:17 2020 +0200
|
|
|
4f0b43 |
@@ -1591,6 +1591,47 @@
|
|
|
4f0b43 |
capture->extension());
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
|
|
|
4f0b43 |
+TEST_P(TlsConnectTls13, Tls13RsaPkcs1IsAdvertisedClient) {
|
|
|
4f0b43 |
+ EnsureTlsSetup();
|
|
|
4f0b43 |
+ static const SSLSignatureScheme kSchemes[] = {ssl_sig_rsa_pkcs1_sha256,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pss_rsae_sha256};
|
|
|
4f0b43 |
+ client_->SetSignatureSchemes(kSchemes, PR_ARRAY_SIZE(kSchemes));
|
|
|
4f0b43 |
+ auto capture =
|
|
|
4f0b43 |
+ MakeTlsFilter<TlsExtensionCapture>(client_, ssl_signature_algorithms_xtn);
|
|
|
4f0b43 |
+ Connect();
|
|
|
4f0b43 |
+ // We should only have the one signature algorithm advertised.
|
|
|
4f0b43 |
+ static const uint8_t kExpectedExt[] = {0,
|
|
|
4f0b43 |
+ 4,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pss_rsae_sha256 >> 8,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pss_rsae_sha256 & 0xff,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pkcs1_sha256 >> 8,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pkcs1_sha256 & 0xff};
|
|
|
4f0b43 |
+ ASSERT_EQ(DataBuffer(kExpectedExt, sizeof(kExpectedExt)),
|
|
|
4f0b43 |
+ capture->extension());
|
|
|
4f0b43 |
+}
|
|
|
4f0b43 |
+
|
|
|
4f0b43 |
+TEST_P(TlsConnectTls13, Tls13RsaPkcs1IsAdvertisedServer) {
|
|
|
4f0b43 |
+ EnsureTlsSetup();
|
|
|
4f0b43 |
+ static const SSLSignatureScheme kSchemes[] = {ssl_sig_rsa_pkcs1_sha256,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pss_rsae_sha256};
|
|
|
4f0b43 |
+ server_->SetSignatureSchemes(kSchemes, PR_ARRAY_SIZE(kSchemes));
|
|
|
4f0b43 |
+ auto capture = MakeTlsFilter<TlsExtensionCapture>(
|
|
|
4f0b43 |
+ server_, ssl_signature_algorithms_xtn, true);
|
|
|
4f0b43 |
+ capture->SetHandshakeTypes({kTlsHandshakeCertificateRequest});
|
|
|
4f0b43 |
+ capture->EnableDecryption();
|
|
|
4f0b43 |
+ server_->RequestClientAuth(false); // So we get a CertificateRequest.
|
|
|
4f0b43 |
+ Connect();
|
|
|
4f0b43 |
+ // We should only have the one signature algorithm advertised.
|
|
|
4f0b43 |
+ static const uint8_t kExpectedExt[] = {0,
|
|
|
4f0b43 |
+ 4,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pss_rsae_sha256 >> 8,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pss_rsae_sha256 & 0xff,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pkcs1_sha256 >> 8,
|
|
|
4f0b43 |
+ ssl_sig_rsa_pkcs1_sha256 & 0xff};
|
|
|
4f0b43 |
+ ASSERT_EQ(DataBuffer(kExpectedExt, sizeof(kExpectedExt)),
|
|
|
4f0b43 |
+ capture->extension());
|
|
|
4f0b43 |
+}
|
|
|
4f0b43 |
+
|
|
|
4f0b43 |
// variant, version, certificate, auth type, signature scheme
|
|
|
4f0b43 |
typedef std::tuple
|
|
|
4f0b43 |
SSLSignatureScheme>
|
|
|
4f0b43 |
diff -r de661583d467 -r df1d2695e115 lib/ssl/ssl3con.c
|
|
|
4f0b43 |
--- a/lib/ssl/ssl3con.c Thu Jul 09 22:45:27 2020 +0000
|
|
|
4f0b43 |
+++ b/lib/ssl/ssl3con.c Fri Jul 10 08:01:17 2020 +0200
|
|
|
4f0b43 |
@@ -784,15 +784,19 @@
|
|
|
4f0b43 |
* Both by policy and by having a token that supports it. */
|
|
|
4f0b43 |
static PRBool
|
|
|
4f0b43 |
ssl_SignatureSchemeAccepted(PRUint16 minVersion,
|
|
|
4f0b43 |
- SSLSignatureScheme scheme)
|
|
|
4f0b43 |
+ SSLSignatureScheme scheme,
|
|
|
4f0b43 |
+ PRBool forCert)
|
|
|
4f0b43 |
{
|
|
|
4f0b43 |
/* Disable RSA-PSS schemes if there are no tokens to verify them. */
|
|
|
4f0b43 |
if (ssl_IsRsaPssSignatureScheme(scheme)) {
|
|
|
4f0b43 |
if (!PK11_TokenExists(auth_alg_defs[ssl_auth_rsa_pss])) {
|
|
|
4f0b43 |
return PR_FALSE;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
- } else if (ssl_IsRsaPkcs1SignatureScheme(scheme)) {
|
|
|
4f0b43 |
- /* Disable PKCS#1 signatures if we are limited to TLS 1.3. */
|
|
|
4f0b43 |
+ } else if (!forCert && ssl_IsRsaPkcs1SignatureScheme(scheme)) {
|
|
|
4f0b43 |
+ /* Disable PKCS#1 signatures if we are limited to TLS 1.3.
|
|
|
4f0b43 |
+ * We still need to advertise PKCS#1 signatures in CH and CR
|
|
|
4f0b43 |
+ * for certificate signatures.
|
|
|
4f0b43 |
+ */
|
|
|
4f0b43 |
if (minVersion >= SSL_LIBRARY_VERSION_TLS_1_3) {
|
|
|
4f0b43 |
return PR_FALSE;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
@@ -851,7 +855,8 @@
|
|
|
4f0b43 |
/* Ensure that there is a signature scheme that can be accepted.*/
|
|
|
4f0b43 |
for (unsigned int i = 0; i < ss->ssl3.signatureSchemeCount; ++i) {
|
|
|
4f0b43 |
if (ssl_SignatureSchemeAccepted(ss->vrange.min,
|
|
|
4f0b43 |
- ss->ssl3.signatureSchemes[i])) {
|
|
|
4f0b43 |
+ ss->ssl3.signatureSchemes[i],
|
|
|
4f0b43 |
+ PR_FALSE /* forCert */)) {
|
|
|
4f0b43 |
return SECSuccess;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
@@ -880,7 +885,7 @@
|
|
|
4f0b43 |
PRBool acceptable = authType == schemeAuthType ||
|
|
|
4f0b43 |
(schemeAuthType == ssl_auth_rsa_pss &&
|
|
|
4f0b43 |
authType == ssl_auth_rsa_sign);
|
|
|
4f0b43 |
- if (acceptable && ssl_SignatureSchemeAccepted(ss->version, scheme)) {
|
|
|
4f0b43 |
+ if (acceptable && ssl_SignatureSchemeAccepted(ss->version, scheme, PR_FALSE /* forCert */)) {
|
|
|
4f0b43 |
return PR_TRUE;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
@@ -9803,12 +9808,13 @@
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
|
|
|
4f0b43 |
SECStatus
|
|
|
4f0b43 |
-ssl3_EncodeSigAlgs(const sslSocket *ss, PRUint16 minVersion, sslBuffer *buf)
|
|
|
4f0b43 |
+ssl3_EncodeSigAlgs(const sslSocket *ss, PRUint16 minVersion, PRBool forCert,
|
|
|
4f0b43 |
+ sslBuffer *buf)
|
|
|
4f0b43 |
{
|
|
|
4f0b43 |
SSLSignatureScheme filtered[MAX_SIGNATURE_SCHEMES] = { 0 };
|
|
|
4f0b43 |
unsigned int filteredCount = 0;
|
|
|
4f0b43 |
|
|
|
4f0b43 |
- SECStatus rv = ssl3_FilterSigAlgs(ss, minVersion, PR_FALSE,
|
|
|
4f0b43 |
+ SECStatus rv = ssl3_FilterSigAlgs(ss, minVersion, PR_FALSE, forCert,
|
|
|
4f0b43 |
PR_ARRAY_SIZE(filtered),
|
|
|
4f0b43 |
filtered, &filteredCount);
|
|
|
4f0b43 |
if (rv != SECSuccess) {
|
|
|
4f0b43 |
@@ -9843,8 +9849,21 @@
|
|
|
4f0b43 |
return sslBuffer_InsertLength(buf, lengthOffset, 2);
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
|
|
|
4f0b43 |
+/*
|
|
|
4f0b43 |
+ * In TLS 1.3 we are permitted to advertise support for PKCS#1
|
|
|
4f0b43 |
+ * schemes. This doesn't affect the signatures in TLS itself, just
|
|
|
4f0b43 |
+ * those on certificates. Not advertising PKCS#1 signatures creates a
|
|
|
4f0b43 |
+ * serious compatibility risk as it excludes many certificate chains
|
|
|
4f0b43 |
+ * that include PKCS#1. Hence, forCert is used to enable advertising
|
|
|
4f0b43 |
+ * PKCS#1 support. Note that we include these in signature_algorithms
|
|
|
4f0b43 |
+ * because we don't yet support signature_algorithms_cert. TLS 1.3
|
|
|
4f0b43 |
+ * requires that PKCS#1 schemes are placed last in the list if they
|
|
|
4f0b43 |
+ * are present. This sorting can be removed once we support
|
|
|
4f0b43 |
+ * signature_algorithms_cert.
|
|
|
4f0b43 |
+ */
|
|
|
4f0b43 |
SECStatus
|
|
|
4f0b43 |
ssl3_FilterSigAlgs(const sslSocket *ss, PRUint16 minVersion, PRBool disableRsae,
|
|
|
4f0b43 |
+ PRBool forCert,
|
|
|
4f0b43 |
unsigned int maxSchemes, SSLSignatureScheme *filteredSchemes,
|
|
|
4f0b43 |
unsigned int *numFilteredSchemes)
|
|
|
4f0b43 |
{
|
|
|
4f0b43 |
@@ -9856,15 +9875,32 @@
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
|
|
|
4f0b43 |
*numFilteredSchemes = 0;
|
|
|
4f0b43 |
+ PRBool allowUnsortedPkcs1 = forCert && minVersion < SSL_LIBRARY_VERSION_TLS_1_3;
|
|
|
4f0b43 |
for (unsigned int i = 0; i < ss->ssl3.signatureSchemeCount; ++i) {
|
|
|
4f0b43 |
if (disableRsae && ssl_IsRsaeSignatureScheme(ss->ssl3.signatureSchemes[i])) {
|
|
|
4f0b43 |
continue;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
if (ssl_SignatureSchemeAccepted(minVersion,
|
|
|
4f0b43 |
- ss->ssl3.signatureSchemes[i])) {
|
|
|
4f0b43 |
+ ss->ssl3.signatureSchemes[i],
|
|
|
4f0b43 |
+ allowUnsortedPkcs1)) {
|
|
|
4f0b43 |
filteredSchemes[(*numFilteredSchemes)++] = ss->ssl3.signatureSchemes[i];
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
+ if (forCert && !allowUnsortedPkcs1) {
|
|
|
4f0b43 |
+ for (unsigned int i = 0; i < ss->ssl3.signatureSchemeCount; ++i) {
|
|
|
4f0b43 |
+ if (disableRsae && ssl_IsRsaeSignatureScheme(ss->ssl3.signatureSchemes[i])) {
|
|
|
4f0b43 |
+ continue;
|
|
|
4f0b43 |
+ }
|
|
|
4f0b43 |
+ if (!ssl_SignatureSchemeAccepted(minVersion,
|
|
|
4f0b43 |
+ ss->ssl3.signatureSchemes[i],
|
|
|
4f0b43 |
+ PR_FALSE) &&
|
|
|
4f0b43 |
+ ssl_SignatureSchemeAccepted(minVersion,
|
|
|
4f0b43 |
+ ss->ssl3.signatureSchemes[i],
|
|
|
4f0b43 |
+ PR_TRUE)) {
|
|
|
4f0b43 |
+ filteredSchemes[(*numFilteredSchemes)++] = ss->ssl3.signatureSchemes[i];
|
|
|
4f0b43 |
+ }
|
|
|
4f0b43 |
+ }
|
|
|
4f0b43 |
+ }
|
|
|
4f0b43 |
return SECSuccess;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
|
|
|
4f0b43 |
@@ -9901,7 +9937,7 @@
|
|
|
4f0b43 |
|
|
|
4f0b43 |
length = 1 + certTypesLength + 2 + calen;
|
|
|
4f0b43 |
if (isTLS12) {
|
|
|
4f0b43 |
- rv = ssl3_EncodeSigAlgs(ss, ss->version, &sigAlgsBuf);
|
|
|
4f0b43 |
+ rv = ssl3_EncodeSigAlgs(ss, ss->version, PR_TRUE /* forCert */, &sigAlgsBuf);
|
|
|
4f0b43 |
if (rv != SECSuccess) {
|
|
|
4f0b43 |
return rv;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
diff -r de661583d467 -r df1d2695e115 lib/ssl/ssl3exthandle.c
|
|
|
4f0b43 |
--- a/lib/ssl/ssl3exthandle.c Thu Jul 09 22:45:27 2020 +0000
|
|
|
4f0b43 |
+++ b/lib/ssl/ssl3exthandle.c Fri Jul 10 08:01:17 2020 +0200
|
|
|
4f0b43 |
@@ -1652,7 +1652,7 @@
|
|
|
4f0b43 |
minVersion = ss->vrange.min; /* ClientHello */
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
|
|
|
4f0b43 |
- SECStatus rv = ssl3_EncodeSigAlgs(ss, minVersion, buf);
|
|
|
4f0b43 |
+ SECStatus rv = ssl3_EncodeSigAlgs(ss, minVersion, PR_TRUE /* forCert */, buf);
|
|
|
4f0b43 |
if (rv != SECSuccess) {
|
|
|
4f0b43 |
return SECFailure;
|
|
|
4f0b43 |
}
|
|
|
4f0b43 |
diff -r de661583d467 -r df1d2695e115 lib/ssl/sslimpl.h
|
|
|
4f0b43 |
--- a/lib/ssl/sslimpl.h Thu Jul 09 22:45:27 2020 +0000
|
|
|
4f0b43 |
+++ b/lib/ssl/sslimpl.h Fri Jul 10 08:01:17 2020 +0200
|
|
|
4f0b43 |
@@ -1688,12 +1688,12 @@
|
|
|
4f0b43 |
SECStatus ssl3_AuthCertificate(sslSocket *ss);
|
|
|
4f0b43 |
SECStatus ssl_ReadCertificateStatus(sslSocket *ss, PRUint8 *b,
|
|
|
4f0b43 |
PRUint32 length);
|
|
|
4f0b43 |
-SECStatus ssl3_EncodeSigAlgs(const sslSocket *ss, PRUint16 minVersion,
|
|
|
4f0b43 |
+SECStatus ssl3_EncodeSigAlgs(const sslSocket *ss, PRUint16 minVersion, PRBool forCert,
|
|
|
4f0b43 |
sslBuffer *buf);
|
|
|
4f0b43 |
SECStatus ssl3_EncodeFilteredSigAlgs(const sslSocket *ss,
|
|
|
4f0b43 |
const SSLSignatureScheme *schemes,
|
|
|
4f0b43 |
PRUint32 numSchemes, sslBuffer *buf);
|
|
|
4f0b43 |
-SECStatus ssl3_FilterSigAlgs(const sslSocket *ss, PRUint16 minVersion, PRBool disableRsae,
|
|
|
4f0b43 |
+SECStatus ssl3_FilterSigAlgs(const sslSocket *ss, PRUint16 minVersion, PRBool disableRsae, PRBool forCert,
|
|
|
4f0b43 |
unsigned int maxSchemes, SSLSignatureScheme *filteredSchemes,
|
|
|
4f0b43 |
unsigned int *numFilteredSchemes);
|
|
|
4f0b43 |
SECStatus ssl_GetCertificateRequestCAs(const sslSocket *ss,
|
|
|
4f0b43 |
diff -r de661583d467 -r df1d2695e115 lib/ssl/tls13exthandle.c
|
|
|
4f0b43 |
--- a/lib/ssl/tls13exthandle.c Thu Jul 09 22:45:27 2020 +0000
|
|
|
4f0b43 |
+++ b/lib/ssl/tls13exthandle.c Fri Jul 10 08:01:17 2020 +0200
|
|
|
4f0b43 |
@@ -1519,7 +1519,8 @@
|
|
|
4f0b43 |
SSLSignatureScheme filtered[MAX_SIGNATURE_SCHEMES] = { 0 };
|
|
|
4f0b43 |
unsigned int filteredCount = 0;
|
|
|
4f0b43 |
SECStatus rv = ssl3_FilterSigAlgs(ss, ss->vrange.max,
|
|
|
4f0b43 |
- PR_TRUE,
|
|
|
4f0b43 |
+ PR_TRUE /* disableRsae */,
|
|
|
4f0b43 |
+ PR_FALSE /* forCert */,
|
|
|
4f0b43 |
MAX_SIGNATURE_SCHEMES,
|
|
|
4f0b43 |
filtered,
|
|
|
4f0b43 |
&filteredCount);
|