qsslerror.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/ssl/qsslerror.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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-
93QT_BEGIN_NAMESPACE-
94-
95class QSslErrorPrivate-
96{-
97public:-
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-
109QSslError::QSslError()-
110 : d(new QSslErrorPrivate)-
111{-
112 d->error = QSslError::NoError;-
113 d->certificate = QSslCertificate();-
114}
executed 739 times by 9 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsslcertificate - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
739
115-
116/*!-
117 Constructs a QSslError object. The argument specifies the \a-
118 error that occurred.-
119-
120*/-
121QSslError::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 block
Executed by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
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*/-
134QSslError::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 block
Executed by:
  • tst_NetworkSelfTest
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
810
140-
141/*!-
142 Constructs an identical copy of \a other.-
143*/-
144QSslError::QSslError(const QSslError &other)-
145 : d(new QSslErrorPrivate)-
146{-
147 *d.data() = *other.d.data();-
148}
executed 638 times by 9 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsslcertificate - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
638
149-
150/*!-
151 Destroys the QSslError object.-
152*/-
153QSslError::~QSslError()-
154{-
155}-
156-
157/*!-
158 \since 4.4-
159-
160 Assigns the contents of \a other to this error.-
161*/-
162QSslError &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*/-
181bool 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:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
d->error == other.d->errorDescription
TRUEevaluated 72 times by 3 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_qsslcertificate - unknown status
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:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
d->certificate...d->certificateDescription
TRUEevaluated 41 times by 3 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
FALSEevaluated 31 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qsslsocket - unknown status
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*/-
200QSslError::SslError QSslError::error() const-
201{-
202 return d->error;
executed 64 times by 3 tests: return d->error;
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslerror - unknown status
  • tst_qsslsocket - unknown status
64
203}-
204-
205/*!-
206 Returns a short localized human-readable description of the error.-
207-
208 \sa error(), certificate()-
209*/-
210QString 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:
  • tst_qsslcertificate - unknown status
2
233 errStr = QSslSocket::tr("The certificate has expired");-
234 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_qsslcertificate - unknown status
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:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
60
242 errStr = QSslSocket::tr("The certificate is self-signed, and untrusted");-
243 break;
executed 60 times by 5 tests: break;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
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:
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
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:
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
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:
  • tst_qsslcertificate - unknown status
1
254 errStr = QSslSocket::tr("One of the CA certificates is invalid");-
255 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_qsslcertificate - unknown status
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:
  • tst_qsslsocket - unknown status
1
260 errStr = QSslSocket::tr("The supplied certificate is unsuitable for this purpose");-
261 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_qsslsocket - unknown status
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:
  • tst_qsslsocket - unknown status
1
278 errStr = QSslSocket::tr("The peer did not present any certificate");-
279 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_qsslsocket - unknown status
1
280 case HostNameMismatch:
executed 11 times by 2 tests: case HostNameMismatch:
Executed by:
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
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:
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
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:
  • tst_qsslsocket - unknown status
1
287 errStr = QSslSocket::tr("The peer certificate is blacklisted");-
288 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_qsslsocket - unknown status
1
289 default:
executed 2 times by 1 test: default:
Executed by:
  • tst_qsslcertificate - unknown status
2
290 errStr = QSslSocket::tr("Unknown error");-
291 break;
executed 2 times by 1 test: break;
Executed by:
  • tst_qsslcertificate - unknown status
2
292 }-
293-
294 return errStr;
executed 92 times by 7 tests: return errStr;
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_Spdy
  • tst_qsslcertificate - unknown status
  • tst_qsslsocket - unknown status
  • tst_qsslsocket_onDemandCertificates_member - unknown status
  • tst_qsslsocket_onDemandCertificates_static - unknown status
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*/-
303QSslCertificate QSslError::certificate() const-
304{-
305 return d->certificate;
executed 2 times by 1 test: return d->certificate;
Executed by:
  • tst_qsslerror - unknown status
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*/-
313uint 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:
  • tst_qsslerror - unknown status
2
319}-
320-
321#ifndef QT_NO_DEBUG_STREAM-
322//class QDebug;-
323QDebug operator<<(QDebug debug, const QSslError &error)-
324{-
325 debug << error.errorString();-
326 return debug;
never executed: return debug;
0
327}-
328QDebug 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-
335QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9