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