749a63c
From 04e074e8d7c097295505e63565abdc7ca2b49f7b Mon Sep 17 00:00:00 2001
749a63c
From: Peter Hartmann <peter.hartmann@nokia.com>
749a63c
Date: Thu, 24 Mar 2011 14:42:22 +0100
749a63c
Subject: [PATCH] QSslCertificate: report fraudulent certificates as invalid
749a63c
749a63c
There are some fraudulent certificates in the wild that are not valid;
749a63c
this patch introduces a blacklist of serial numbers of those
749a63c
certificates.
749a63c
749a63c
Reviewed-by: Richard J. Moore
749a63c
Reviewed-by: Markus Goetz
749a63c
Task-number: QTBUG-18338
749a63c
749a63c
diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp
749a63c
index 618ac79..a5cdf01 100644
749a63c
--- a/src/network/ssl/qsslcertificate.cpp
749a63c
+++ b/src/network/ssl/qsslcertificate.cpp
749a63c
@@ -219,17 +219,19 @@ bool QSslCertificate::isNull() const
749a63c
     Returns true if this certificate is valid; otherwise returns
749a63c
     false.
749a63c
 
749a63c
-    Note: Currently, this function only checks that the current
749a63c
+    Note: Currently, this function checks that the current
749a63c
     data-time is within the date-time range during which the
749a63c
-    certificate is considered valid. No other checks are
749a63c
-    currently performed.
749a63c
+    certificate is considered valid, and checks that the
749a63c
+    certificate is not in a blacklist of fraudulent certificates.
749a63c
 
749a63c
     \sa isNull()
749a63c
 */
749a63c
 bool QSslCertificate::isValid() const
749a63c
 {
749a63c
     const QDateTime currentTime = QDateTime::currentDateTime();
749a63c
-    return currentTime >= d->notValidBefore && currentTime <= d->notValidAfter;
749a63c
+    return currentTime >= d->notValidBefore &&
749a63c
+            currentTime <= d->notValidAfter &&
749a63c
+            ! QSslCertificatePrivate::isBlacklisted(*this);
749a63c
 }
749a63c
 
749a63c
 /*!
749a63c
@@ -798,6 +800,30 @@ QList<QSslCertificate> QSslCertificatePrivate::certificatesFromDer(const QByteAr
749a63c
     return certificates;
749a63c
 }
749a63c
 
749a63c
+// These certificates are known to be fraudulent and were created during the comodo
749a63c
+// compromise. See http://www.comodo.com/Comodo-Fraud-Incident-2011-03-23.html
749a63c
+static const char *certificate_blacklist[] = {
749a63c
+    "04:7e:cb:e9:fc:a5:5f:7b:d0:9e:ae:36:e1:0c:ae:1e",
749a63c
+    "f5:c8:6a:f3:61:62:f1:3a:64:f5:4f:6d:c9:58:7c:06",
749a63c
+    "d7:55:8f:da:f5:f1:10:5b:b2:13:28:2b:70:77:29:a3",
749a63c
+    "39:2a:43:4f:0e:07:df:1f:8a:a3:05:de:34:e0:c2:29",
749a63c
+    "3e:75:ce:d4:6b:69:30:21:21:88:30:ae:86:a8:2a:71",
749a63c
+    "e9:02:8b:95:78:e4:15:dc:1a:71:0a:2b:88:15:44:47",
749a63c
+    "92:39:d5:34:8f:40:d1:69:5a:74:54:70:e1:f2:3f:43",
749a63c
+    "b0:b7:13:3e:d0:96:f9:b5:6f:ae:91:c8:74:bd:3a:c0",
749a63c
+    "d8:f3:5f:4e:b7:87:2b:2d:ab:06:92:e3:15:38:2f:b0",
749a63c
+    0
749a63c
+};
749a63c
+
749a63c
+bool QSslCertificatePrivate::isBlacklisted(const QSslCertificate &certificate)
749a63c
+{
749a63c
+    for (int a = 0; certificate_blacklist[a] != 0; a++) {
749a63c
+        if (certificate.serialNumber() == certificate_blacklist[a])
749a63c
+            return true;
749a63c
+    }
749a63c
+    return false;
749a63c
+}
749a63c
+
749a63c
 #ifndef QT_NO_DEBUG_STREAM
749a63c
 QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
749a63c
 {
749a63c
diff --git a/src/network/ssl/qsslcertificate_p.h b/src/network/ssl/qsslcertificate_p.h
749a63c
index cdceb0f..1ce33d3 100644
749a63c
--- a/src/network/ssl/qsslcertificate_p.h
749a63c
+++ b/src/network/ssl/qsslcertificate_p.h
749a63c
@@ -96,6 +96,7 @@ public:
749a63c
     static QSslCertificate QSslCertificate_from_X509(X509 *x509);
749a63c
     static QList<QSslCertificate> certificatesFromPem(const QByteArray &pem, int count = -1);
749a63c
     static QList<QSslCertificate> certificatesFromDer(const QByteArray &der, int count = -1);
749a63c
+    static bool isBlacklisted(const QSslCertificate &certificate);
749a63c
 
749a63c
     friend class QSslSocketBackendPrivate;
749a63c