Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsslerror.cpp
Go to the documentation of this file.
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
4
70#include "qsslerror.h"
71#include "qsslsocket.h"
72#ifndef QT_NO_DEBUG_STREAM
73#include <QtCore/qdebug.h>
74#endif
75
77
78#ifndef QT_NO_SSL
79QT_IMPL_METATYPE_EXTERN_TAGGED(QList<QSslError>, QList_QSslError)
80#endif
81
82
83#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
84// Avoid an ABI break due to the QScopedPointer->std::unique_ptr change
85static_assert(sizeof(QScopedPointer<QSslErrorPrivate>) == sizeof(std::unique_ptr<QSslErrorPrivate>));
86#endif
87
94
95// RVCT compiler in debug build does not like about default values in const-
96// So as an workaround we define all constructor overloads here explicitly
103 : d(new QSslErrorPrivate)
104{
105 d->error = QSslError::NoError;
106 d->certificate = QSslCertificate();
107}
108
115 : d(new QSslErrorPrivate)
116{
117 d->error = error;
118 d->certificate = QSslCertificate();
119}
120
128 : d(new QSslErrorPrivate)
129{
130 d->error = error;
131 d->certificate = certificate;
132}
133
138 : d(new QSslErrorPrivate)
139{
140 *d.get() = *other.d.get();
141}
142
149
156{
157 *d.get() = *other.d.get();
158 return *this;
159}
160
175{
176 return d->error == other.d->error
177 && d->certificate == other.d->certificate;
178}
179
194{
195 return d->error;
196}
197
204{
205 QString errStr;
206 switch (d->error) {
207 case NoError:
208 errStr = QSslSocket::tr("No error");
209 break;
211 errStr = QSslSocket::tr("The issuer certificate could not be found");
212 break;
214 errStr = QSslSocket::tr("The certificate signature could not be decrypted");
215 break;
217 errStr = QSslSocket::tr("The public key in the certificate could not be read");
218 break;
220 errStr = QSslSocket::tr("The signature of the certificate is invalid");
221 break;
223 errStr = QSslSocket::tr("The certificate is not yet valid");
224 break;
226 errStr = QSslSocket::tr("The certificate has expired");
227 break;
229 errStr = QSslSocket::tr("The certificate's notBefore field contains an invalid time");
230 break;
232 errStr = QSslSocket::tr("The certificate's notAfter field contains an invalid time");
233 break;
235 errStr = QSslSocket::tr("The certificate is self-signed, and untrusted");
236 break;
238 errStr = QSslSocket::tr("The root certificate of the certificate chain is self-signed, and untrusted");
239 break;
241 errStr = QSslSocket::tr("The issuer certificate of a locally looked up certificate could not be found");
242 break;
244 errStr = QSslSocket::tr("No certificates could be verified");
245 break;
247 errStr = QSslSocket::tr("One of the CA certificates is invalid");
248 break;
250 errStr = QSslSocket::tr("The basicConstraints path length parameter has been exceeded");
251 break;
252 case InvalidPurpose:
253 errStr = QSslSocket::tr("The supplied certificate is unsuitable for this purpose");
254 break;
256 errStr = QSslSocket::tr("The root CA certificate is not trusted for this purpose");
257 break;
259 errStr = QSslSocket::tr("The root CA certificate is marked to reject the specified purpose");
260 break;
261 case SubjectIssuerMismatch: // hostname mismatch
262 errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because its"
263 " subject name did not match the issuer name of the current certificate");
264 break;
266 errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because"
267 " its issuer name and serial number was present and did not match the"
268 " authority key identifier of the current certificate");
269 break;
271 errStr = QSslSocket::tr("The peer did not present any certificate");
272 break;
273 case HostNameMismatch:
274 errStr = QSslSocket::tr("The host name did not match any of the valid hosts"
275 " for this certificate");
276 break;
277 case NoSslSupport:
278 break;
280 errStr = QSslSocket::tr("The peer certificate is blacklisted");
281 break;
283 errStr = QSslSocket::tr("No OCSP status response found");
284 break;
286 errStr = QSslSocket::tr("The OCSP status request had invalid syntax");
287 break;
289 errStr = QSslSocket::tr("OCSP response contains an unexpected number of SingleResponse structures");
290 break;
292 errStr = QSslSocket::tr("OCSP responder reached an inconsistent internal state");
293 break;
294 case OcspTryLater:
295 errStr = QSslSocket::tr("OCSP responder was unable to return a status for the requested certificate");
296 break;
297 case OcspSigRequred:
298 errStr = QSslSocket::tr("The server requires the client to sign the OCSP request in order to construct a response");
299 break;
300 case OcspUnauthorized:
301 errStr = QSslSocket::tr("The client is not authorized to request OCSP status from this server");
302 break;
304 errStr = QSslSocket::tr("OCSP responder's identity cannot be verified");
305 break;
307 errStr = QSslSocket::tr("The identity of a certificate in an OCSP response cannot be established");
308 break;
310 errStr = QSslSocket::tr("The certificate status response has expired");
311 break;
313 errStr = QSslSocket::tr("The certificate's status is unknown");
314 break;
315 default:
316 errStr = QSslSocket::tr("Unknown error");
317 break;
318 }
319
320 return errStr;
321}
322
330{
331 return d->certificate;
332}
333
339size_t qHash(const QSslError &key, size_t seed) noexcept
340{
342 seed = hash(seed, key.error());
343 seed = hash(seed, key.certificate());
344 return seed;
345}
346
347#ifndef QT_NO_DEBUG_STREAM
348//class QDebug;
350{
351 debug << error.errorString();
352 return debug;
353}
359#endif
360
362
363#include "moc_qsslerror.cpp"
\inmodule QtCore
size_t qHash(const QSslError &key, size_t seed) noexcept
Returns the hash value for the key, using seed to seed the calculation.
The QSslCertificate class provides a convenient API for an X509 certificate.
QSslCertificate certificate
Definition qsslerror.cpp:92
QSslError::SslError error
Definition qsslerror.cpp:91
The QSslError class provides an SSL error.
Definition qsslerror.h:21
SslError error() const
Returns the type of the error.
bool operator==(const QSslError &other) const
QString errorString() const
Returns a short localized human-readable description of the error.
~QSslError()
Destroys the QSslError object.
QSslError & operator=(QSslError &&other) noexcept
Definition qsslerror.h:78
QSslError()
Constructs a QSslError object with no error and default certificate.
SslError
Describes all recognized errors that can occur during an SSL handshake.
Definition qsslerror.h:24
@ InvalidNotAfterField
Definition qsslerror.h:33
@ OcspResponseCannotBeTrusted
Definition qsslerror.h:58
@ OcspMalformedRequest
Definition qsslerror.h:52
@ OcspUnauthorized
Definition qsslerror.h:57
@ CertificateRejected
Definition qsslerror.h:43
@ SelfSignedCertificate
Definition qsslerror.h:34
@ UnableToVerifyFirstCertificate
Definition qsslerror.h:37
@ AuthorityIssuerSerialNumberMismatch
Definition qsslerror.h:45
@ OcspResponseExpired
Definition qsslerror.h:60
@ OcspResponseCertIdUnknown
Definition qsslerror.h:59
@ OcspSigRequred
Definition qsslerror.h:56
@ CertificateNotYetValid
Definition qsslerror.h:30
@ CertificateBlacklisted
Definition qsslerror.h:49
@ CertificateExpired
Definition qsslerror.h:31
@ UnableToDecodeIssuerPublicKey
Definition qsslerror.h:28
@ UnableToDecryptCertificateSignature
Definition qsslerror.h:27
@ UnableToGetLocalIssuerCertificate
Definition qsslerror.h:36
@ UnableToGetIssuerCertificate
Definition qsslerror.h:26
@ SubjectIssuerMismatch
Definition qsslerror.h:44
@ OcspMalformedResponse
Definition qsslerror.h:53
@ PathLengthExceeded
Definition qsslerror.h:40
@ OcspTryLater
Definition qsslerror.h:55
@ SelfSignedCertificateInChain
Definition qsslerror.h:35
@ HostNameMismatch
Definition qsslerror.h:47
@ InvalidNotBeforeField
Definition qsslerror.h:32
@ OcspInternalError
Definition qsslerror.h:54
@ NoSslSupport
Definition qsslerror.h:48
@ CertificateUntrusted
Definition qsslerror.h:42
@ OcspStatusUnknown
Definition qsslerror.h:61
@ CertificateSignatureFailed
Definition qsslerror.h:29
@ InvalidPurpose
Definition qsslerror.h:41
@ InvalidCaCertificate
Definition qsslerror.h:39
@ OcspNoResponseFound
Definition qsslerror.h:51
@ NoPeerCertificate
Definition qsslerror.h:46
QSslCertificate certificate() const
Returns the certificate associated with this error, or a null certificate if the error does not relat...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QHash< int, QWidget * > hash
[35multi]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG)
Definition qmetatype.h:1384
GLuint64 key
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
QDebug operator<<(QDebug debug, const QSslError &error)
QSharedPointer< T > other(t)
[5]