Skip to content

Commit 7fcb100

Browse files
author
Andy Shaw
committed
Ignore expired certificate during certificate validation
OpenSSL has a bug when validating a chain with two certificates. If a certificate exists twice (which is a valid use case for renewed CAs), and the first one it hits is expired (which depends on the order on data structure internal to OpenSSL), it will fail to validate the chain. This is only a bandaid fix, which trades improved chain validation for error reporting accuracy. However given that reissuing of CA certs is a real problem that is only getting worse, this fix is needed. See also: https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html#WARNINGS [ChangeLog][QtNetwork][QSslSocket] Added a workaround to an OpenSSL problem that may cause errors when the trust store contains two certificates of the issuing CA, one of which is expired. Task-number: QTBUG-38896 (cherry picked and adapted from qtbase/0065b55da42b8c6ee0095264b5275fb708887c9d) Change-Id: I2515d79a442bec96734ea88ea850e6e8c2123a6c Reviewed-by: Richard J. Moore <[email protected]>
1 parent 8032b17 commit 7fcb100

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/network/ssl/qsslsocket_openssl.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,26 +350,19 @@ bool QSslSocketBackendPrivate::initSslContext()
350350
}
351351

352352
// Add all our CAs to this store.
353-
QList<QSslCertificate> expiredCerts;
354353
foreach (const QSslCertificate &caCertificate, q->caCertificates()) {
355-
// add expired certs later, so that the
356-
// valid ones are used before the expired ones
357-
if (! caCertificate.isValid()) {
358-
expiredCerts.append(caCertificate);
359-
} else {
360-
q_X509_STORE_add_cert(ctx->cert_store, (X509 *)caCertificate.handle());
361-
}
362-
}
363-
364-
bool addExpiredCerts = true;
365-
#if defined(Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED == MAC_OS_X_VERSION_10_5)
366-
//On Leopard SSL does not work if we add the expired certificates.
367-
if (QSysInfo::MacintoshVersion == QSysInfo::MV_10_5)
368-
addExpiredCerts = false;
369-
#endif
370-
// now add the expired certs
371-
if (addExpiredCerts) {
372-
foreach (const QSslCertificate &caCertificate, expiredCerts) {
354+
// From https://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html:
355+
//
356+
// If several CA certificates matching the name, key identifier, and
357+
// serial number condition are available, only the first one will be
358+
// examined. This may lead to unexpected results if the same CA
359+
// certificate is available with different expiration dates. If a
360+
// ``certificate expired'' verification error occurs, no other
361+
// certificate will be searched. Make sure to not have expired
362+
// certificates mixed with valid ones.
363+
//
364+
// See also: QSslContext::fromConfiguration()
365+
if (caCertificate.expiryDate() >= QDateTime::currentDateTime()) {
373366
q_X509_STORE_add_cert(ctx->cert_store, (X509 *)caCertificate.handle());
374367
}
375368
}

0 commit comments

Comments
 (0)