| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | |
| 6 | #ifndef QSSLERROR_H |
| 7 | #define QSSLERROR_H |
| 8 | |
| 9 | #include <QtNetwork/qtnetworkglobal.h> |
| 10 | #include <QtCore/qdebug.h> |
| 11 | #include <QtCore/qvariant.h> |
| 12 | #include <QtNetwork/qsslcertificate.h> |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | |
| 19 | #ifndef QT_NO_SSL |
| 20 | |
| 21 | #ifndef QT_NO_DEBUG_STREAM |
| 22 | class QDebug; |
| 23 | #endif |
| 24 | |
| 25 | class QSslErrorPrivate; |
| 26 | class Q_NETWORK_EXPORT QSslError |
| 27 | { |
| 28 | Q_GADGET |
| 29 | public: |
| 30 | enum SslError { |
| 31 | NoError, |
| 32 | UnableToGetIssuerCertificate, |
| 33 | UnableToDecryptCertificateSignature, |
| 34 | UnableToDecodeIssuerPublicKey, |
| 35 | CertificateSignatureFailed, |
| 36 | CertificateNotYetValid, |
| 37 | CertificateExpired, |
| 38 | InvalidNotBeforeField, |
| 39 | InvalidNotAfterField, |
| 40 | SelfSignedCertificate, |
| 41 | SelfSignedCertificateInChain, |
| 42 | UnableToGetLocalIssuerCertificate, |
| 43 | UnableToVerifyFirstCertificate, |
| 44 | CertificateRevoked, |
| 45 | InvalidCaCertificate, |
| 46 | PathLengthExceeded, |
| 47 | InvalidPurpose, |
| 48 | CertificateUntrusted, |
| 49 | CertificateRejected, |
| 50 | SubjectIssuerMismatch, // hostname mismatch? |
| 51 | AuthorityIssuerSerialNumberMismatch, |
| 52 | NoPeerCertificate, |
| 53 | HostNameMismatch, |
| 54 | NoSslSupport, |
| 55 | CertificateBlacklisted, |
| 56 | CertificateStatusUnknown, |
| 57 | OcspNoResponseFound, |
| 58 | OcspMalformedRequest, |
| 59 | OcspMalformedResponse, |
| 60 | OcspInternalError, |
| 61 | OcspTryLater, |
| 62 | OcspSigRequred, |
| 63 | OcspUnauthorized, |
| 64 | OcspResponseCannotBeTrusted, |
| 65 | OcspResponseCertIdUnknown, |
| 66 | OcspResponseExpired, |
| 67 | OcspStatusUnknown, |
| 68 | UnspecifiedError = -1 |
| 69 | }; |
| 70 | Q_ENUM(SslError) |
| 71 | |
| 72 | // RVCT compiler in debug build does not like about default values in const- |
| 73 | // So as an workaround we define all constructor overloads here explicitly |
| 74 | QSslError(); |
| 75 | explicit QSslError(SslError error); |
| 76 | QSslError(SslError error, const QSslCertificate &certificate); |
| 77 | |
| 78 | QSslError(const QSslError &other); |
| 79 | |
| 80 | void swap(QSslError &other) noexcept |
| 81 | { d.swap(u&: other.d); } |
| 82 | |
| 83 | ~QSslError(); |
| 84 | QSslError &operator=(QSslError &&other) noexcept { swap(other); return *this; } |
| 85 | QSslError &operator=(const QSslError &other); |
| 86 | bool operator==(const QSslError &other) const; |
| 87 | inline bool operator!=(const QSslError &other) const |
| 88 | { return !(*this == other); } |
| 89 | |
| 90 | SslError error() const; |
| 91 | QString errorString() const; |
| 92 | QSslCertificate certificate() const; |
| 93 | |
| 94 | private: |
| 95 | // ### Qt 7: make QSslError implicitly shared |
| 96 | std::unique_ptr<QSslErrorPrivate> d; |
| 97 | #ifndef QT_NO_DEBUG_STREAM |
| 98 | Q_NETWORK_EXPORT friend QDebug print(QDebug debug, QSslError::SslError error); |
| 99 | friend QDebug operator<<(QDebug debug, SslError error) |
| 100 | { return print(debug: std::move(debug), error); } |
| 101 | #endif |
| 102 | }; |
| 103 | Q_DECLARE_SHARED(QSslError) |
| 104 | |
| 105 | Q_NETWORK_EXPORT size_t qHash(const QSslError &key, size_t seed = 0) noexcept; |
| 106 | |
| 107 | #ifndef QT_NO_DEBUG_STREAM |
| 108 | |
| 109 | Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError &error); |
| 110 | #if QT_NETWORK_REMOVED_SINCE(6, 8) |
| 111 | Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QSslError::SslError &error); |
| 112 | #endif |
| 113 | #endif |
| 114 | #else |
| 115 | class Q_NETWORK_EXPORT QSslError {}; // dummy class so that moc has a complete type |
| 116 | #endif // QT_NO_SSL |
| 117 | |
| 118 | QT_END_NAMESPACE |
| 119 | |
| 120 | #ifndef QT_NO_SSL |
| 121 | QT_DECL_METATYPE_EXTERN_TAGGED(QList<QSslError>, QList_QSslError, Q_NETWORK_EXPORT) |
| 122 | #endif |
| 123 | |
| 124 | #endif |
| 125 | |