1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtNetwork module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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 io
|
---|
50 | \ingroup ssl
|
---|
51 | \inmodule QtNetwork
|
---|
52 |
|
---|
53 | QSslError provides a simple API for managing errors during QSslSocket's
|
---|
54 | SSL handshake.
|
---|
55 |
|
---|
56 | \sa QSslSocket, QSslCertificate, QSslCipher
|
---|
57 | */
|
---|
58 |
|
---|
59 | /*!
|
---|
60 | \enum QSslError::SslError
|
---|
61 |
|
---|
62 | Describes all recognized errors that can occur during an SSL handshake.
|
---|
63 |
|
---|
64 | \value NoError
|
---|
65 | \value UnableToGetIssuerCertificate
|
---|
66 | \value UnableToDecryptCertificateSignature
|
---|
67 | \value UnableToDecodeIssuerPublicKey
|
---|
68 | \value CertificateSignatureFailed
|
---|
69 | \value CertificateNotYetValid
|
---|
70 | \value CertificateExpired
|
---|
71 | \value InvalidNotBeforeField
|
---|
72 | \value InvalidNotAfterField
|
---|
73 | \value SelfSignedCertificate
|
---|
74 | \value SelfSignedCertificateInChain
|
---|
75 | \value UnableToGetLocalIssuerCertificate
|
---|
76 | \value UnableToVerifyFirstCertificate
|
---|
77 | \value CertificateRevoked
|
---|
78 | \value InvalidCaCertificate
|
---|
79 | \value PathLengthExceeded
|
---|
80 | \value InvalidPurpose
|
---|
81 | \value CertificateUntrusted
|
---|
82 | \value CertificateRejected
|
---|
83 | \value SubjectIssuerMismatch
|
---|
84 | \value AuthorityIssuerSerialNumberMismatch
|
---|
85 | \value NoPeerCertificate
|
---|
86 | \value HostNameMismatch
|
---|
87 | \value UnspecifiedError
|
---|
88 | \value NoSslSupport
|
---|
89 |
|
---|
90 | \sa QSslError::errorString()
|
---|
91 | */
|
---|
92 |
|
---|
93 | #include "qsslerror.h"
|
---|
94 | #ifndef QT_NO_DEBUG_STREAM
|
---|
95 | #include <QtCore/qdebug.h>
|
---|
96 |
|
---|
97 | QT_BEGIN_NAMESPACE
|
---|
98 | #endif
|
---|
99 |
|
---|
100 | class QSslErrorPrivate
|
---|
101 | {
|
---|
102 | public:
|
---|
103 | QSslError::SslError error;
|
---|
104 | QSslCertificate certificate;
|
---|
105 | };
|
---|
106 |
|
---|
107 | /*!
|
---|
108 | Constructs a QSslError object. The two optional arguments specify the \a
|
---|
109 | error that occurred, and which \a certificate the error relates to.
|
---|
110 |
|
---|
111 | \sa QSslCertificate
|
---|
112 | */
|
---|
113 | QSslError::QSslError(SslError error, const QSslCertificate &certificate)
|
---|
114 | : d(new QSslErrorPrivate)
|
---|
115 | {
|
---|
116 | d->error = error;
|
---|
117 | d->certificate = certificate;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /*!
|
---|
121 | Constructs an identical copy of \a other.
|
---|
122 | */
|
---|
123 | QSslError::QSslError(const QSslError &other)
|
---|
124 | : d(new QSslErrorPrivate)
|
---|
125 | {
|
---|
126 | *d = *other.d;
|
---|
127 | }
|
---|
128 |
|
---|
129 | /*!
|
---|
130 | Destroys the QSslError object.
|
---|
131 | */
|
---|
132 | QSslError::~QSslError()
|
---|
133 | {
|
---|
134 | delete d;
|
---|
135 | }
|
---|
136 |
|
---|
137 | /*!
|
---|
138 | \since 4.4
|
---|
139 |
|
---|
140 | Assigns the contents of \a other to this error.
|
---|
141 | */
|
---|
142 | QSslError &QSslError::operator=(const QSslError &other)
|
---|
143 | {
|
---|
144 | *d = *other.d;
|
---|
145 | return *this;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /*!
|
---|
149 | \since 4.4
|
---|
150 |
|
---|
151 | Returns true if this error is equal to \a other; otherwise returns false.
|
---|
152 | */
|
---|
153 | bool QSslError::operator==(const QSslError &other) const
|
---|
154 | {
|
---|
155 | return d->error == other.d->error
|
---|
156 | && d->certificate == other.d->certificate;
|
---|
157 | }
|
---|
158 |
|
---|
159 | /*!
|
---|
160 | \fn bool QSslError::operator!=(const QSslError &other) const
|
---|
161 | \since 4.4
|
---|
162 |
|
---|
163 | Returns true if this error is not equal to \a other; otherwise returns
|
---|
164 | false.
|
---|
165 | */
|
---|
166 |
|
---|
167 | /*!
|
---|
168 | Returns the type of the error.
|
---|
169 |
|
---|
170 | \sa errorString(), certificate()
|
---|
171 | */
|
---|
172 | QSslError::SslError QSslError::error() const
|
---|
173 | {
|
---|
174 | return d->error;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /*!
|
---|
178 | Returns a short localized human-readable description of the error.
|
---|
179 |
|
---|
180 | \sa error(), certificate()
|
---|
181 | */
|
---|
182 | QString QSslError::errorString() const
|
---|
183 | {
|
---|
184 | QString errStr;
|
---|
185 | switch (d->error) {
|
---|
186 | case NoError:
|
---|
187 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "No error"));
|
---|
188 | break;
|
---|
189 | case UnableToGetIssuerCertificate:
|
---|
190 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The issuer certificate could not be found"));
|
---|
191 | break;
|
---|
192 | case UnableToDecryptCertificateSignature:
|
---|
193 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate signature could not be decrypted"));
|
---|
194 | break;
|
---|
195 | case UnableToDecodeIssuerPublicKey:
|
---|
196 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The public key in the certificate could not be read"));
|
---|
197 | break;
|
---|
198 | case CertificateSignatureFailed:
|
---|
199 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The signature of the certificate is invalid"));
|
---|
200 | break;
|
---|
201 | case CertificateNotYetValid:
|
---|
202 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate is not yet valid"));
|
---|
203 | break;
|
---|
204 | case CertificateExpired:
|
---|
205 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate has expired"));
|
---|
206 | break;
|
---|
207 | case InvalidNotBeforeField:
|
---|
208 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate's notBefore field contains an invalid time"));
|
---|
209 | break;
|
---|
210 | case InvalidNotAfterField:
|
---|
211 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate's notAfter field contains an invalid time"));
|
---|
212 | break;
|
---|
213 | case SelfSignedCertificate:
|
---|
214 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The certificate is self-signed, and untrusted"));
|
---|
215 | break;
|
---|
216 | case SelfSignedCertificateInChain:
|
---|
217 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The root certificate of the certificate chain is self-signed, and untrusted"));
|
---|
218 | break;
|
---|
219 | case UnableToGetLocalIssuerCertificate:
|
---|
220 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The issuer certificate of a locally looked up certificate could not be found"));
|
---|
221 | break;
|
---|
222 | case UnableToVerifyFirstCertificate:
|
---|
223 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "No certificates could be verified"));
|
---|
224 | break;
|
---|
225 | case InvalidCaCertificate:
|
---|
226 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "One of the CA certificates is invalid"));
|
---|
227 | break;
|
---|
228 | case PathLengthExceeded:
|
---|
229 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The basicConstraints pathlength parameter has been exceeded"));
|
---|
230 | break;
|
---|
231 | case InvalidPurpose:
|
---|
232 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The supplied certificate is unsuited for this purpose"));
|
---|
233 | break;
|
---|
234 | case CertificateUntrusted:
|
---|
235 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The root CA certificate is not trusted for this purpose"));
|
---|
236 | break;
|
---|
237 | case CertificateRejected:
|
---|
238 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The root CA certificate is marked to reject the specified purpose"));
|
---|
239 | break;
|
---|
240 | case SubjectIssuerMismatch: // hostname mismatch
|
---|
241 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError,
|
---|
242 | "The current candidate issuer certificate was rejected because its"
|
---|
243 | " subject name did not match the issuer name of the current certificate"));
|
---|
244 | break;
|
---|
245 | case AuthorityIssuerSerialNumberMismatch:
|
---|
246 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The current candidate issuer certificate was rejected because"
|
---|
247 | " its issuer name and serial number was present and did not match the"
|
---|
248 | " authority key identifier of the current certificate"));
|
---|
249 | break;
|
---|
250 | case NoPeerCertificate:
|
---|
251 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "The peer did not present any certificate"));
|
---|
252 | break;
|
---|
253 | case HostNameMismatch:
|
---|
254 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError,
|
---|
255 | "The host name did not match any of the valid hosts"
|
---|
256 | " for this certificate"));
|
---|
257 | break;
|
---|
258 | case NoSslSupport:
|
---|
259 | break;
|
---|
260 | default:
|
---|
261 | errStr = QObject::tr(QT_TRANSLATE_NOOP(QSslError, "Unknown error"));
|
---|
262 | break;
|
---|
263 | }
|
---|
264 |
|
---|
265 | return errStr;
|
---|
266 | }
|
---|
267 |
|
---|
268 | /*!
|
---|
269 | Returns the certificate associated with this error, or a null certificate
|
---|
270 | if the error does not relate to any certificate.
|
---|
271 |
|
---|
272 | \sa error(), errorString()
|
---|
273 | */
|
---|
274 | QSslCertificate QSslError::certificate() const
|
---|
275 | {
|
---|
276 | return d->certificate;
|
---|
277 | }
|
---|
278 |
|
---|
279 | #ifndef QT_NO_DEBUG_STREAM
|
---|
280 | //class QDebug;
|
---|
281 | QDebug operator<<(QDebug debug, const QSslError &error)
|
---|
282 | {
|
---|
283 | debug << error.errorString();
|
---|
284 | return debug;
|
---|
285 | }
|
---|
286 | QDebug operator<<(QDebug debug, const QSslError::SslError &error)
|
---|
287 | {
|
---|
288 | debug << QSslError(error).errorString();
|
---|
289 | return debug;
|
---|
290 | }
|
---|
291 | #endif
|
---|
292 |
|
---|
293 | QT_END_NAMESPACE
|
---|