| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslcertificate.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | - | |||||||
| 10 | - | |||||||
| 11 | - | |||||||
| 12 | - | |||||||
| 13 | QSslCertificate::QSslCertificate(QIODevice *device, QSsl::EncodingFormat format) | - | ||||||
| 14 | : d(new QSslCertificatePrivate) | - | ||||||
| 15 | { | - | ||||||
| 16 | QSslSocketPrivate::ensureInitialized(); | - | ||||||
| 17 | if (device) | - | ||||||
| 18 | d->init(device->readAll(), format); | - | ||||||
| 19 | } | - | ||||||
| 20 | - | |||||||
| 21 | - | |||||||
| 22 | - | |||||||
| 23 | - | |||||||
| 24 | - | |||||||
| 25 | - | |||||||
| 26 | - | |||||||
| 27 | QSslCertificate::QSslCertificate(const QByteArray &data, QSsl::EncodingFormat format) | - | ||||||
| 28 | : d(new QSslCertificatePrivate) | - | ||||||
| 29 | { | - | ||||||
| 30 | QSslSocketPrivate::ensureInitialized(); | - | ||||||
| 31 | d->init(data, format); | - | ||||||
| 32 | } | - | ||||||
| 33 | - | |||||||
| 34 | - | |||||||
| 35 | - | |||||||
| 36 | - | |||||||
| 37 | QSslCertificate::QSslCertificate(const QSslCertificate &other) : d(other.d) | - | ||||||
| 38 | { | - | ||||||
| 39 | } | - | ||||||
| 40 | - | |||||||
| 41 | - | |||||||
| 42 | - | |||||||
| 43 | - | |||||||
| 44 | QSslCertificate::~QSslCertificate() | - | ||||||
| 45 | { | - | ||||||
| 46 | } | - | ||||||
| 47 | - | |||||||
| 48 | - | |||||||
| 49 | - | |||||||
| 50 | - | |||||||
| 51 | - | |||||||
| 52 | QSslCertificate &QSslCertificate::operator=(const QSslCertificate &other) | - | ||||||
| 53 | { | - | ||||||
| 54 | d = other.d; | - | ||||||
| 55 | return *this; | - | ||||||
| 56 | } | - | ||||||
| 57 | bool QSslCertificate::isBlacklisted() const | - | ||||||
| 58 | { | - | ||||||
| 59 | return QSslCertificatePrivate::isBlacklisted(*this); | - | ||||||
| 60 | } | - | ||||||
| 61 | void QSslCertificate::clear() | - | ||||||
| 62 | { | - | ||||||
| 63 | if (isNull()) | - | ||||||
| 64 | return; | - | ||||||
| 65 | d = new QSslCertificatePrivate; | - | ||||||
| 66 | } | - | ||||||
| 67 | QByteArray QSslCertificate::digest(QCryptographicHash::Algorithm algorithm) const | - | ||||||
| 68 | { | - | ||||||
| 69 | return QCryptographicHash::hash(toDer(), algorithm); | - | ||||||
| 70 | } | - | ||||||
| 71 | QList<QSslCertificate> QSslCertificate::fromPath(const QString &path, | - | ||||||
| 72 | QSsl::EncodingFormat format, | - | ||||||
| 73 | QRegExp::PatternSyntax syntax) | - | ||||||
| 74 | { | - | ||||||
| 75 | - | |||||||
| 76 | - | |||||||
| 77 | - | |||||||
| 78 | QString sourcePath = QDir::fromNativeSeparators(path); | - | ||||||
| 79 | - | |||||||
| 80 | - | |||||||
| 81 | QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(QLatin1Char('/'))); | - | ||||||
| 82 | - | |||||||
| 83 | - | |||||||
| 84 | int pos = -1; | - | ||||||
| 85 |     if (syntax == QRegExp::Wildcard
  | 22-9845 | ||||||
| 86 |         pos = pathPrefix.indexOf(QRegExp(QLatin1String("[*?[]"))); executed 22 times by 1 test:  pos = pathPrefix.indexOf(QRegExp(QLatin1String("[*?[]")));Executed by: 
  | 22 | ||||||
| 87 |     else if (syntax != QRegExp::FixedString
  | 16-9829 | ||||||
| 88 |         pos = sourcePath.indexOf(QRegExp(QLatin1String("[\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]"))); executed 16 times by 1 test:  pos = sourcePath.indexOf(QRegExp(QLatin1String("[\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]")));Executed by: 
  | 16 | ||||||
| 89 |     if (pos != -1
  | 20-9847 | ||||||
| 90 | - | |||||||
| 91 | pathPrefix = pathPrefix.left(pos); | - | ||||||
| 92 | if (const int lastIndexOfSlash = pathPrefix.containslastIndexOf(QLatin1Char('/'))))); | - | ||||||
| 93 |         if (lastIndexOfSlash != -1
  | 0-20 | ||||||
| 94 |             pathPrefix = pathPrefix.left(pathPrefix.lastIndexOf(QLatin1Char('/')));lastIndexOfSlash); never executed:  pathPrefix = pathPrefix.left(lastIndexOfSlash); | 0 | ||||||
| 95 | else | - | ||||||
| 96 |             pathPrefix.clear(); executed 20 times by 1 test:  pathPrefix.clear();Executed by: 
  | 20 | ||||||
| 97 | } else { | - | ||||||
| 98 | - | |||||||
| 99 |         if (QFileInfo(sourcePath).isFile()
  | 138-9709 | ||||||
| 100 | QFile file(sourcePath); | - | ||||||
| 101 | QIODevice::OpenMode openMode = QIODevice::ReadOnly; | - | ||||||
| 102 |             if (format == QSsl::Pem
  | 2-9707 | ||||||
| 103 |                 openMode |= QIODevice::Text; executed 9707 times by 4 tests:  openMode |= QIODevice::Text;Executed by: 
  | 9707 | ||||||
| 104 |             if (file.open(openMode)
  | 0-9709 | ||||||
| 105 |                 return executed 9709 times by 4 tests:   QSslCertificate::fromData(file.readAll(), format);return QSslCertificate::fromData(file.readAll(), format);Executed by: 
 executed 9709 times by 4 tests:  return QSslCertificate::fromData(file.readAll(), format);Executed by: 
  | 9709 | ||||||
| 106 |             return never executed:   QList<QSslCertificate>();return QList<QSslCertificate>();never executed:  return QList<QSslCertificate>(); | 0 | ||||||
| 107 | } | - | ||||||
| 108 |     } executed 138 times by 3 tests:  end of blockExecuted by: 
  | 138 | ||||||
| 109 | - | |||||||
| 110 | - | |||||||
| 111 | int startIndex = 0; | - | ||||||
| 112 |     if (pathPrefix.isEmpty()
  | 26-132 | ||||||
| 113 | pathPrefix = QLatin1String("."); | - | ||||||
| 114 | startIndex = 2; | - | ||||||
| 115 |     } executed 26 times by 1 test:  end of blockExecuted by: 
  | 26 | ||||||
| 116 | - | |||||||
| 117 | - | |||||||
| 118 | QList<QSslCertificate> certs; | - | ||||||
| 119 | QRegExp pattern(sourcePath, Qt::CaseSensitive, syntax); | - | ||||||
| 120 | QDirIterator it(pathPrefix, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); | - | ||||||
| 121 |     while (it.hasNext()
  | 158-2628 | ||||||
| 122 |         QString filePath = startIndex == 0
  | 496-2132 | ||||||
| 123 |         if (!pattern.exactMatch(filePath)
  | 136-2492 | ||||||
| 124 |             continue; executed 2492 times by 1 test:  continue;Executed by: 
  | 2492 | ||||||
| 125 | - | |||||||
| 126 | QFile file(filePath); | - | ||||||
| 127 | QIODevice::OpenMode openMode = QIODevice::ReadOnly; | - | ||||||
| 128 |         if (format == QSsl::Pem
  | 42-94 | ||||||
| 129 |             openMode |= QIODevice::Text; executed 94 times by 1 test:  openMode |= QIODevice::Text;Executed by: 
  | 94 | ||||||
| 130 |         if (file.open(openMode)
  | 0-136 | ||||||
| 131 |             certs += QSslCertificate::fromData(file.readAll(), format); executed 136 times by 1 test:  certs += QSslCertificate::fromData(file.readAll(), format);Executed by: 
  | 136 | ||||||
| 132 |     } executed 136 times by 1 test:  end of blockExecuted by: 
  | 136 | ||||||
| 133 |     return executed 158 times by 3 tests:   certs;return certs;Executed by: 
 executed 158 times by 3 tests:  return certs;Executed by: 
  | 158 | ||||||
| 134 | } | - | ||||||
| 135 | QList<QSslCertificate> QSslCertificate::fromDevice(QIODevice *device, QSsl::EncodingFormat format) | - | ||||||
| 136 | { | - | ||||||
| 137 | if (!device) { | - | ||||||
| 138 | for (bool qt_category_enabled = lcSsl().isWarningEnabled(); qt_category_enabled; qt_category_enabled = false) QMessageLogger(__FILE__, 532539, __PRETTY_FUNCTION__, lcSsl().categoryName()).warning("QSslCertificate::fromDevice: cannot read from a null device"); | - | ||||||
| 139 | return QList<QSslCertificate>(); | - | ||||||
| 140 | } | - | ||||||
| 141 | return fromData(device->readAll(), format); | - | ||||||
| 142 | } | - | ||||||
| 143 | QList<QSslCertificate> QSslCertificate::fromData(const QByteArray &data, QSsl::EncodingFormat format) | - | ||||||
| 144 | { | - | ||||||
| 145 | return (format == QSsl::Pem) | - | ||||||
| 146 | ? QSslCertificatePrivate::certificatesFromPem(data) | - | ||||||
| 147 | : QSslCertificatePrivate::certificatesFromDer(data); | - | ||||||
| 148 | } | - | ||||||
| 149 | QList<QSslError> QSslCertificate::verify(QList<QSslCertificate> certificateChain, const QString &hostName) | - | ||||||
| 150 | - | |||||||
| 151 | { | - | ||||||
| 152 | return QSslSocketBackendPrivate::verify(certificateChain, hostName); | - | ||||||
| 153 | } | - | ||||||
| 154 | bool QSslCertificate::importPkcs12(QIODevice *device, | - | ||||||
| 155 | QSslKey *key, QSslCertificate *certificate, | - | ||||||
| 156 | QList<QSslCertificate> *caCertificates, | - | ||||||
| 157 | const QByteArray &passPhrase) | - | ||||||
| 158 | { | - | ||||||
| 159 | return QSslSocketBackendPrivate::importPkcs12(device, key, certificate, caCertificates, passPhrase); | - | ||||||
| 160 | } | - | ||||||
| 161 | - | |||||||
| 162 | - | |||||||
| 163 | - | |||||||
| 164 | static const char *const certificate_blacklist[] = { | - | ||||||
| 165 | "04:7e:cb:e9:fc:a5:5f:7b:d0:9e:ae:36:e1:0c:ae:1e", "mail.google.com", | - | ||||||
| 166 | "f5:c8:6a:f3:61:62:f1:3a:64:f5:4f:6d:c9:58:7c:06", "www.google.com", | - | ||||||
| 167 | "d7:55:8f:da:f5:f1:10:5b:b2:13:28:2b:70:77:29:a3", "login.yahoo.com", | - | ||||||
| 168 | "39:2a:43:4f:0e:07:df:1f:8a:a3:05:de:34:e0:c2:29", "login.yahoo.com", | - | ||||||
| 169 | "3e:75:ce:d4:6b:69:30:21:21:88:30:ae:86:a8:2a:71", "login.yahoo.com", | - | ||||||
| 170 | "e9:02:8b:95:78:e4:15:dc:1a:71:0a:2b:88:15:44:47", "login.skype.com", | - | ||||||
| 171 | "92:39:d5:34:8f:40:d1:69:5a:74:54:70:e1:f2:3f:43", "addons.mozilla.org", | - | ||||||
| 172 | "b0:b7:13:3e:d0:96:f9:b5:6f:ae:91:c8:74:bd:3a:c0", "login.live.com", | - | ||||||
| 173 | "d8:f3:5f:4e:b7:87:2b:2d:ab:06:92:e3:15:38:2f:b0", "global trustee", | - | ||||||
| 174 | - | |||||||
| 175 | "05:e2:e6:a4:cd:09:ea:54:d6:65:b0:75:fe:22:a2:56", "*.google.com", | - | ||||||
| 176 | "0c:76:da:9c:91:0c:4e:2c:9e:fe:15:d0:58:93:3c:4c", "DigiNotar Root CA", | - | ||||||
| 177 | "f1:4a:13:f4:87:2b:56:dc:39:df:84:ca:7a:a1:06:49", "DigiNotar Services CA", | - | ||||||
| 178 | "36:16:71:55:43:42:1b:9d:e6:cb:a3:64:41:df:24:38", "DigiNotar Services 1024 CA", | - | ||||||
| 179 | "0a:82:bd:1e:14:4e:88:14:d7:5b:1a:55:27:be:bf:3e", "DigiNotar Root CA G2", | - | ||||||
| 180 | "a4:b6:ce:e3:2e:d3:35:46:26:3c:b3:55:3a:a8:92:21", "CertiID Enterprise Certificate Authority", | - | ||||||
| 181 | "5b:d5:60:9c:64:17:68:cf:21:0e:35:fd:fb:05:ad:41", "DigiNotar Qualified CA", | - | ||||||
| 182 | - | |||||||
| 183 | "46:9c:2c:b0", "DigiNotar Services 1024 CA", | - | ||||||
| 184 | "07:27:10:0d", "DigiNotar Cyber CA", | - | ||||||
| 185 | "07:27:0f:f9", "DigiNotar Cyber CA", | - | ||||||
| 186 | "07:27:10:03", "DigiNotar Cyber CA", | - | ||||||
| 187 | "01:31:69:b0", "DigiNotar PKIoverheid CA Overheid en Bedrijven", | - | ||||||
| 188 | "01:31:34:bf", "DigiNotar PKIoverheid CA Organisatie - G2", | - | ||||||
| 189 | "d6:d0:29:77:f1:49:fd:1a:83:f2:b9:ea:94:8c:5c:b4", "DigiNotar Extended Validation CA", | - | ||||||
| 190 | "1e:7d:7a:53:3d:45:30:41:96:40:0f:71:48:1f:45:04", "DigiNotar Public CA 2025", | - | ||||||
| 191 | - | |||||||
| 192 | - | |||||||
| 193 | - | |||||||
| 194 | "46:9c:2c:af", "DigiNotar Root CA", | - | ||||||
| 195 | "46:9c:3c:c9", "DigiNotar Root CA", | - | ||||||
| 196 | - | |||||||
| 197 | "07:27:14:a9", "Digisign Server ID (Enrich)", | - | ||||||
| 198 | "4c:0e:63:6a", "Digisign Server ID - (Enrich)", | - | ||||||
| 199 | "72:03:21:05:c5:0c:08:57:3d:8e:a5:30:4e:fe:e8:b0", "UTN-USERFirst-Hardware", | - | ||||||
| 200 | "41", "MD5 Collisions Inc. (http://www.phreedom.org/md5)", | - | ||||||
| 201 | - | |||||||
| 202 | "08:27", "*.EGO.GOV.TR", | - | ||||||
| 203 | "08:64", "e-islem.kktcmerkezbankasi.org", | - | ||||||
| 204 | - | |||||||
| 205 | "03:1d:a7", "AC DG Tr\xC3\xA9sor SSL", | - | ||||||
| 206 | "27:83", "NIC Certifying Authority", | - | ||||||
| 207 | "27:92", "NIC CA 2011", | - | ||||||
| 208 | "27:b1", "NIC CA 2014", | - | ||||||
| 209 | 0 | - | ||||||
| 210 | }; | - | ||||||
| 211 | - | |||||||
| 212 | bool QSslCertificatePrivate::isBlacklisted(const QSslCertificate &certificate) | - | ||||||
| 213 | { | - | ||||||
| 214 | for (int a = 0; certificate_blacklist[a] != 0; a++) { | - | ||||||
| 215 | QString blacklistedCommonName = QString::fromUtf8(certificate_blacklist[(a+1)]); | - | ||||||
| 216 | if (certificate.serialNumber() == certificate_blacklist[a++] && | - | ||||||
| 217 | (certificate.subjectInfo(QSslCertificate::CommonName).contains(blacklistedCommonName) || | - | ||||||
| 218 | certificate.issuerInfo(QSslCertificate::CommonName).contains(blacklistedCommonName))) | - | ||||||
| 219 | return true; | - | ||||||
| 220 | } | - | ||||||
| 221 | return false; | - | ||||||
| 222 | } | - | ||||||
| 223 | - | |||||||
| 224 | QByteArray QSslCertificatePrivate::subjectInfoToString(QSslCertificate::SubjectInfo info) | - | ||||||
| 225 | { | - | ||||||
| 226 | QByteArray str; | - | ||||||
| 227 | switch (info) { | - | ||||||
| 228 | case QSslCertificate::Organization: str = QByteArray("O"); break; | - | ||||||
| 229 | case QSslCertificate::CommonName: str = QByteArray("CN"); break; | - | ||||||
| 230 | case QSslCertificate::LocalityName: str = QByteArray("L"); break; | - | ||||||
| 231 | case QSslCertificate::OrganizationalUnitName: str = QByteArray("OU"); break; | - | ||||||
| 232 | case QSslCertificate::CountryName: str = QByteArray("C"); break; | - | ||||||
| 233 | case QSslCertificate::StateOrProvinceName: str = QByteArray("ST"); break; | - | ||||||
| 234 | case QSslCertificate::DistinguishedNameQualifier: str = QByteArray("dnQualifier"); break; | - | ||||||
| 235 | case QSslCertificate::SerialNumber: str = QByteArray("serialNumber"); break; | - | ||||||
| 236 | case QSslCertificate::EmailAddress: str = QByteArray("emailAddress"); break; | - | ||||||
| 237 | } | - | ||||||
| 238 | return str; | - | ||||||
| 239 | } | - | ||||||
| 240 | QDebug operator<<(QDebug debug, const QSslCertificate &certificate) | - | ||||||
| 241 | { | - | ||||||
| 242 | QDebugStateSaver saver(debug); | - | ||||||
| 243 | debug.resetFormat().nospace(); | - | ||||||
| 244 | debug << "QSslCertificate(" | - | ||||||
| 245 | << certificate.version() | - | ||||||
| 246 | << ", " << certificate.serialNumber() | - | ||||||
| 247 | << ", " << certificate.digest().toBase64() | - | ||||||
| 248 | << ", " << certificate.issuerInfo(QSslCertificate::Organization) | - | ||||||
| 249 | << ", " << certificate.subjectInfo(QSslCertificate::Organization) | - | ||||||
| 250 | << ", " << certificate.subjectAlternativeNames() | - | ||||||
| 251 | - | |||||||
| 252 | << ", " << certificate.effectiveDate() | - | ||||||
| 253 | << ", " << certificate.expiryDate() | - | ||||||
| 254 | - | |||||||
| 255 | << ')'; | - | ||||||
| 256 | return debug; | - | ||||||
| 257 | } | - | ||||||
| 258 | QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo info) | - | ||||||
| 259 | { | - | ||||||
| 260 | switch (info) { | - | ||||||
| 261 | case QSslCertificate::Organization: debug << "Organization"; break; | - | ||||||
| 262 | case QSslCertificate::CommonName: debug << "CommonName"; break; | - | ||||||
| 263 | case QSslCertificate::CountryName: debug << "CountryName"; break; | - | ||||||
| 264 | case QSslCertificate::LocalityName: debug << "LocalityName"; break; | - | ||||||
| 265 | case QSslCertificate::OrganizationalUnitName: debug << "OrganizationalUnitName"; break; | - | ||||||
| 266 | case QSslCertificate::StateOrProvinceName: debug << "StateOrProvinceName"; break; | - | ||||||
| 267 | case QSslCertificate::DistinguishedNameQualifier: debug << "DistinguishedNameQualifier"; break; | - | ||||||
| 268 | case QSslCertificate::SerialNumber: debug << "SerialNumber"; break; | - | ||||||
| 269 | case QSslCertificate::EmailAddress: debug << "EmailAddress"; break; | - | ||||||
| 270 | } | - | ||||||
| 271 | return debug; | - | ||||||
| 272 | } | - | ||||||
| 273 | - | |||||||
| 274 | - | |||||||
| 275 | - | |||||||
| Switch to Source code | Preprocessed file |