| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslerror.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | - | |||||||
| 35 | /*! | - | ||||||
| 36 | \class QSslError | - | ||||||
| 37 | \brief The QSslError class provides an SSL error. | - | ||||||
| 38 | \since 4.3 | - | ||||||
| 39 | - | |||||||
| 40 | \reentrant | - | ||||||
| 41 | \ingroup network | - | ||||||
| 42 | \ingroup ssl | - | ||||||
| 43 | \ingroup shared | - | ||||||
| 44 | \inmodule QtNetwork | - | ||||||
| 45 | - | |||||||
| 46 | QSslError provides a simple API for managing errors during QSslSocket's | - | ||||||
| 47 | SSL handshake. | - | ||||||
| 48 | - | |||||||
| 49 | \sa QSslSocket, QSslCertificate, QSslCipher | - | ||||||
| 50 | */ | - | ||||||
| 51 | - | |||||||
| 52 | /*! | - | ||||||
| 53 | \enum QSslError::SslError | - | ||||||
| 54 | - | |||||||
| 55 | Describes all recognized errors that can occur during an SSL handshake. | - | ||||||
| 56 | - | |||||||
| 57 | \value NoError | - | ||||||
| 58 | \value UnableToGetIssuerCertificate | - | ||||||
| 59 | \value UnableToDecryptCertificateSignature | - | ||||||
| 60 | \value UnableToDecodeIssuerPublicKey | - | ||||||
| 61 | \value CertificateSignatureFailed | - | ||||||
| 62 | \value CertificateNotYetValid | - | ||||||
| 63 | \value CertificateExpired | - | ||||||
| 64 | \value InvalidNotBeforeField | - | ||||||
| 65 | \value InvalidNotAfterField | - | ||||||
| 66 | \value SelfSignedCertificate | - | ||||||
| 67 | \value SelfSignedCertificateInChain | - | ||||||
| 68 | \value UnableToGetLocalIssuerCertificate | - | ||||||
| 69 | \value UnableToVerifyFirstCertificate | - | ||||||
| 70 | \value CertificateRevoked | - | ||||||
| 71 | \value InvalidCaCertificate | - | ||||||
| 72 | \value PathLengthExceeded | - | ||||||
| 73 | \value InvalidPurpose | - | ||||||
| 74 | \value CertificateUntrusted | - | ||||||
| 75 | \value CertificateRejected | - | ||||||
| 76 | \value SubjectIssuerMismatch | - | ||||||
| 77 | \value AuthorityIssuerSerialNumberMismatch | - | ||||||
| 78 | \value NoPeerCertificate | - | ||||||
| 79 | \value HostNameMismatch | - | ||||||
| 80 | \value UnspecifiedError | - | ||||||
| 81 | \value NoSslSupport | - | ||||||
| 82 | \value CertificateBlacklisted | - | ||||||
| 83 | - | |||||||
| 84 | \sa QSslError::errorString() | - | ||||||
| 85 | */ | - | ||||||
| 86 | - | |||||||
| 87 | #include "qsslerror.h" | - | ||||||
| 88 | #include "qsslsocket.h" | - | ||||||
| 89 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||
| 90 | #include <QtCore/qdebug.h> | - | ||||||
| 91 | #endif | - | ||||||
| 92 | - | |||||||
| 93 | QT_BEGIN_NAMESPACE | - | ||||||
| 94 | - | |||||||
| 95 | class QSslErrorPrivate | - | ||||||
| 96 | { | - | ||||||
| 97 | public: | - | ||||||
| 98 | QSslError::SslError error; | - | ||||||
| 99 | QSslCertificate certificate; | - | ||||||
| 100 | }; | - | ||||||
| 101 | - | |||||||
| 102 | /*! | - | ||||||
| 103 | Constructs a QSslError object with no error and default certificate. | - | ||||||
| 104 | - | |||||||
| 105 | */ | - | ||||||
| 106 | - | |||||||
| 107 | // RVCT compiler in debug build does not like about default values in const- | - | ||||||
| 108 | // So as an workaround we define all constructor overloads here explicitly | - | ||||||
| 109 | QSslError::QSslError() | - | ||||||
| 110 | : d(new QSslErrorPrivate) | - | ||||||
| 111 | { | - | ||||||
| 112 | d->error = QSslError::NoError; | - | ||||||
| 113 | d->certificate = QSslCertificate(); | - | ||||||
| 114 | } executed 739 times by 9 tests: end of blockExecuted by:
| 739 | ||||||
| 115 | - | |||||||
| 116 | /*! | - | ||||||
| 117 | Constructs a QSslError object. The argument specifies the \a | - | ||||||
| 118 | error that occurred. | - | ||||||
| 119 | - | |||||||
| 120 | */ | - | ||||||
| 121 | QSslError::QSslError(SslError error) | - | ||||||
| 122 | : d(new QSslErrorPrivate) | - | ||||||
| 123 | { | - | ||||||
| 124 | d->error = error; | - | ||||||
| 125 | d->certificate = QSslCertificate(); | - | ||||||
| 126 | } executed 8 times by 3 tests: end of blockExecuted by:
| 8 | ||||||
| 127 | - | |||||||
| 128 | /*! | - | ||||||
| 129 | Constructs a QSslError object. The two arguments specify the \a | - | ||||||
| 130 | error that occurred, and which \a certificate the error relates to. | - | ||||||
| 131 | - | |||||||
| 132 | \sa QSslCertificate | - | ||||||
| 133 | */ | - | ||||||
| 134 | QSslError::QSslError(SslError error, const QSslCertificate &certificate) | - | ||||||
| 135 | : d(new QSslErrorPrivate) | - | ||||||
| 136 | { | - | ||||||
| 137 | d->error = error; | - | ||||||
| 138 | d->certificate = certificate; | - | ||||||
| 139 | } executed 810 times by 8 tests: end of blockExecuted by:
| 810 | ||||||
| 140 | - | |||||||
| 141 | /*! | - | ||||||
| 142 | Constructs an identical copy of \a other. | - | ||||||
| 143 | */ | - | ||||||
| 144 | QSslError::QSslError(const QSslError &other) | - | ||||||
| 145 | : d(new QSslErrorPrivate) | - | ||||||
| 146 | { | - | ||||||
| 147 | *d.data() = *other.d.data(); | - | ||||||
| 148 | } executed 638 times by 9 tests: end of blockExecuted by:
| 638 | ||||||
| 149 | - | |||||||
| 150 | /*! | - | ||||||
| 151 | Destroys the QSslError object. | - | ||||||
| 152 | */ | - | ||||||
| 153 | QSslError::~QSslError() | - | ||||||
| 154 | { | - | ||||||
| 155 | } | - | ||||||
| 156 | - | |||||||
| 157 | /*! | - | ||||||
| 158 | \since 4.4 | - | ||||||
| 159 | - | |||||||
| 160 | Assigns the contents of \a other to this error. | - | ||||||
| 161 | */ | - | ||||||
| 162 | QSslError &QSslError::operator=(const QSslError &other) | - | ||||||
| 163 | { | - | ||||||
| 164 | *d.data() = *other.d.data(); | - | ||||||
| 165 | return *this; never executed: return *this; | 0 | ||||||
| 166 | } | - | ||||||
| 167 | - | |||||||
| 168 | /*! | - | ||||||
| 169 | \fn void QSslError::swap(QSslError &other) | - | ||||||
| 170 | \since 5.0 | - | ||||||
| 171 | - | |||||||
| 172 | Swaps this error instance with \a other. This function is very | - | ||||||
| 173 | fast and never fails. | - | ||||||
| 174 | */ | - | ||||||
| 175 | - | |||||||
| 176 | /*! | - | ||||||
| 177 | \since 4.4 | - | ||||||
| 178 | - | |||||||
| 179 | Returns \c true if this error is equal to \a other; otherwise returns \c false. | - | ||||||
| 180 | */ | - | ||||||
| 181 | bool QSslError::operator==(const QSslError &other) const | - | ||||||
| 182 | { | - | ||||||
| 183 | return d->error == other.d->error executed 73 times by 3 tests: return d->error == other.d->error && d->certificate == other.d->certificate;Executed by:
| 1-73 | ||||||
| 184 | && d->certificate == other.d->certificate; executed 73 times by 3 tests: return d->error == other.d->error && d->certificate == other.d->certificate;Executed by:
| 31-73 | ||||||
| 185 | } | - | ||||||
| 186 | - | |||||||
| 187 | /*! | - | ||||||
| 188 | \fn bool QSslError::operator!=(const QSslError &other) const | - | ||||||
| 189 | \since 4.4 | - | ||||||
| 190 | - | |||||||
| 191 | Returns \c true if this error is not equal to \a other; otherwise returns | - | ||||||
| 192 | false. | - | ||||||
| 193 | */ | - | ||||||
| 194 | - | |||||||
| 195 | /*! | - | ||||||
| 196 | Returns the type of the error. | - | ||||||
| 197 | - | |||||||
| 198 | \sa errorString(), certificate() | - | ||||||
| 199 | */ | - | ||||||
| 200 | QSslError::SslError QSslError::error() const | - | ||||||
| 201 | { | - | ||||||
| 202 | return d->error; executed 64 times by 3 tests: return d->error;Executed by:
| 64 | ||||||
| 203 | } | - | ||||||
| 204 | - | |||||||
| 205 | /*! | - | ||||||
| 206 | Returns a short localized human-readable description of the error. | - | ||||||
| 207 | - | |||||||
| 208 | \sa error(), certificate() | - | ||||||
| 209 | */ | - | ||||||
| 210 | QString QSslError::errorString() const | - | ||||||
| 211 | { | - | ||||||
| 212 | QString errStr; | - | ||||||
| 213 | switch (d->error) { | - | ||||||
| 214 | case NoError: never executed: case NoError: | 0 | ||||||
| 215 | errStr = QSslSocket::tr("No error"); | - | ||||||
| 216 | break; never executed: break; | 0 | ||||||
| 217 | case UnableToGetIssuerCertificate: never executed: case UnableToGetIssuerCertificate: | 0 | ||||||
| 218 | errStr = QSslSocket::tr("The issuer certificate could not be found"); | - | ||||||
| 219 | break; never executed: break; | 0 | ||||||
| 220 | case UnableToDecryptCertificateSignature: never executed: case UnableToDecryptCertificateSignature: | 0 | ||||||
| 221 | errStr = QSslSocket::tr("The certificate signature could not be decrypted"); | - | ||||||
| 222 | break; never executed: break; | 0 | ||||||
| 223 | case UnableToDecodeIssuerPublicKey: never executed: case UnableToDecodeIssuerPublicKey: | 0 | ||||||
| 224 | errStr = QSslSocket::tr("The public key in the certificate could not be read"); | - | ||||||
| 225 | break; never executed: break; | 0 | ||||||
| 226 | case CertificateSignatureFailed: never executed: case CertificateSignatureFailed: | 0 | ||||||
| 227 | errStr = QSslSocket::tr("The signature of the certificate is invalid"); | - | ||||||
| 228 | break; never executed: break; | 0 | ||||||
| 229 | case CertificateNotYetValid: never executed: case CertificateNotYetValid: | 0 | ||||||
| 230 | errStr = QSslSocket::tr("The certificate is not yet valid"); | - | ||||||
| 231 | break; never executed: break; | 0 | ||||||
| 232 | case CertificateExpired: executed 2 times by 1 test: case CertificateExpired:Executed by:
| 2 | ||||||
| 233 | errStr = QSslSocket::tr("The certificate has expired"); | - | ||||||
| 234 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||
| 235 | case InvalidNotBeforeField: never executed: case InvalidNotBeforeField: | 0 | ||||||
| 236 | errStr = QSslSocket::tr("The certificate's notBefore field contains an invalid time"); | - | ||||||
| 237 | break; never executed: break; | 0 | ||||||
| 238 | case InvalidNotAfterField: never executed: case InvalidNotAfterField: | 0 | ||||||
| 239 | errStr = QSslSocket::tr("The certificate's notAfter field contains an invalid time"); | - | ||||||
| 240 | break; never executed: break; | 0 | ||||||
| 241 | case SelfSignedCertificate: executed 60 times by 5 tests: case SelfSignedCertificate:Executed by:
| 60 | ||||||
| 242 | errStr = QSslSocket::tr("The certificate is self-signed, and untrusted"); | - | ||||||
| 243 | break; executed 60 times by 5 tests: break;Executed by:
| 60 | ||||||
| 244 | case SelfSignedCertificateInChain: never executed: case SelfSignedCertificateInChain: | 0 | ||||||
| 245 | errStr = QSslSocket::tr("The root certificate of the certificate chain is self-signed, and untrusted"); | - | ||||||
| 246 | break; never executed: break; | 0 | ||||||
| 247 | case UnableToGetLocalIssuerCertificate: executed 13 times by 3 tests: case UnableToGetLocalIssuerCertificate:Executed by:
| 13 | ||||||
| 248 | errStr = QSslSocket::tr("The issuer certificate of a locally looked up certificate could not be found"); | - | ||||||
| 249 | break; executed 13 times by 3 tests: break;Executed by:
| 13 | ||||||
| 250 | case UnableToVerifyFirstCertificate: never executed: case UnableToVerifyFirstCertificate: | 0 | ||||||
| 251 | errStr = QSslSocket::tr("No certificates could be verified"); | - | ||||||
| 252 | break; never executed: break; | 0 | ||||||
| 253 | case InvalidCaCertificate: executed 1 time by 1 test: case InvalidCaCertificate:Executed by:
| 1 | ||||||
| 254 | errStr = QSslSocket::tr("One of the CA certificates is invalid"); | - | ||||||
| 255 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||
| 256 | case PathLengthExceeded: never executed: case PathLengthExceeded: | 0 | ||||||
| 257 | errStr = QSslSocket::tr("The basicConstraints path length parameter has been exceeded"); | - | ||||||
| 258 | break; never executed: break; | 0 | ||||||
| 259 | case InvalidPurpose: executed 1 time by 1 test: case InvalidPurpose:Executed by:
| 1 | ||||||
| 260 | errStr = QSslSocket::tr("The supplied certificate is unsuitable for this purpose"); | - | ||||||
| 261 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||
| 262 | case CertificateUntrusted: never executed: case CertificateUntrusted: | 0 | ||||||
| 263 | errStr = QSslSocket::tr("The root CA certificate is not trusted for this purpose"); | - | ||||||
| 264 | break; never executed: break; | 0 | ||||||
| 265 | case CertificateRejected: never executed: case CertificateRejected: | 0 | ||||||
| 266 | errStr = QSslSocket::tr("The root CA certificate is marked to reject the specified purpose"); | - | ||||||
| 267 | break; never executed: break; | 0 | ||||||
| 268 | case SubjectIssuerMismatch: // hostname mismatch never executed: case SubjectIssuerMismatch: | 0 | ||||||
| 269 | errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because its" | - | ||||||
| 270 | " subject name did not match the issuer name of the current certificate"); | - | ||||||
| 271 | break; never executed: break; | 0 | ||||||
| 272 | case AuthorityIssuerSerialNumberMismatch: never executed: case AuthorityIssuerSerialNumberMismatch: | 0 | ||||||
| 273 | errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because" | - | ||||||
| 274 | " its issuer name and serial number was present and did not match the" | - | ||||||
| 275 | " authority key identifier of the current certificate"); | - | ||||||
| 276 | break; never executed: break; | 0 | ||||||
| 277 | case NoPeerCertificate: executed 1 time by 1 test: case NoPeerCertificate:Executed by:
| 1 | ||||||
| 278 | errStr = QSslSocket::tr("The peer did not present any certificate"); | - | ||||||
| 279 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||
| 280 | case HostNameMismatch: executed 11 times by 2 tests: case HostNameMismatch:Executed by:
| 11 | ||||||
| 281 | errStr = QSslSocket::tr("The host name did not match any of the valid hosts" | - | ||||||
| 282 | " for this certificate"); | - | ||||||
| 283 | break; executed 11 times by 2 tests: break;Executed by:
| 11 | ||||||
| 284 | case NoSslSupport: never executed: case NoSslSupport: | 0 | ||||||
| 285 | break; never executed: break; | 0 | ||||||
| 286 | case CertificateBlacklisted: executed 1 time by 1 test: case CertificateBlacklisted:Executed by:
| 1 | ||||||
| 287 | errStr = QSslSocket::tr("The peer certificate is blacklisted"); | - | ||||||
| 288 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||
| 289 | default: executed 2 times by 1 test: default:Executed by:
| 2 | ||||||
| 290 | errStr = QSslSocket::tr("Unknown error"); | - | ||||||
| 291 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||
| 292 | } | - | ||||||
| 293 | - | |||||||
| 294 | return errStr; executed 92 times by 7 tests: return errStr;Executed by:
| 92 | ||||||
| 295 | } | - | ||||||
| 296 | - | |||||||
| 297 | /*! | - | ||||||
| 298 | Returns the certificate associated with this error, or a null certificate | - | ||||||
| 299 | if the error does not relate to any certificate. | - | ||||||
| 300 | - | |||||||
| 301 | \sa error(), errorString() | - | ||||||
| 302 | */ | - | ||||||
| 303 | QSslCertificate QSslError::certificate() const | - | ||||||
| 304 | { | - | ||||||
| 305 | return d->certificate; executed 2 times by 1 test: return d->certificate;Executed by:
| 2 | ||||||
| 306 | } | - | ||||||
| 307 | - | |||||||
| 308 | /*! | - | ||||||
| 309 | Returns the hash value for the \a key, using \a seed to seed the calculation. | - | ||||||
| 310 | \since 5.4 | - | ||||||
| 311 | \relates QHash | - | ||||||
| 312 | */ | - | ||||||
| 313 | uint qHash(const QSslError &key, uint seed) Q_DECL_NOTHROW | - | ||||||
| 314 | { | - | ||||||
| 315 | // 2x boost::hash_combine inlined: | - | ||||||
| 316 | seed ^= qHash(key.error()) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | - | ||||||
| 317 | seed ^= qHash(key.certificate()) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | - | ||||||
| 318 | return seed; executed 2 times by 1 test: return seed;Executed by:
| 2 | ||||||
| 319 | } | - | ||||||
| 320 | - | |||||||
| 321 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||
| 322 | //class QDebug; | - | ||||||
| 323 | QDebug operator<<(QDebug debug, const QSslError &error) | - | ||||||
| 324 | { | - | ||||||
| 325 | debug << error.errorString(); | - | ||||||
| 326 | return debug; never executed: return debug; | 0 | ||||||
| 327 | } | - | ||||||
| 328 | QDebug operator<<(QDebug debug, const QSslError::SslError &error) | - | ||||||
| 329 | { | - | ||||||
| 330 | debug << QSslError(error).errorString(); | - | ||||||
| 331 | return debug; never executed: return debug; | 0 | ||||||
| 332 | } | - | ||||||
| 333 | #endif | - | ||||||
| 334 | - | |||||||
| 335 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |