OpenCoverage

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

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