Qt 4.8
qsslerror.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
100 #include "qsslerror.h"
101 #include "qsslsocket.h"
102 #ifndef QT_NO_DEBUG_STREAM
103 #include <QtCore/qdebug.h>
104 
106 #endif
107 
109 {
110 public:
113 };
114 
120 // RVCT compiler in debug build does not like about default values in const-
121 // So as an workaround we define all constructor overloads here explicitly
123  : d(new QSslErrorPrivate)
124 {
127 }
128 
135  : d(new QSslErrorPrivate)
136 {
137  d->error = error;
139 }
140 
148  : d(new QSslErrorPrivate)
149 {
150  d->error = error;
152 }
153 
158  : d(new QSslErrorPrivate)
159 {
160  *d.data() = *other.d.data();
161 }
162 
167 {
168 }
169 
179 {
180  *d.data() = *other.d.data();
181  return *this;
182 }
183 
192 bool QSslError::operator==(const QSslError &other) const
193 {
194  return d->error == other.d->error
195  && d->certificate == other.d->certificate;
196 }
197 
215 {
216  return d->error;
217 }
218 
225 {
226  QString errStr;
227  switch (d->error) {
228  case NoError:
229  errStr = QSslSocket::tr("No error");
230  break;
232  errStr = QSslSocket::tr("The issuer certificate could not be found");
233  break;
235  errStr = QSslSocket::tr("The certificate signature could not be decrypted");
236  break;
238  errStr = QSslSocket::tr("The public key in the certificate could not be read");
239  break;
241  errStr = QSslSocket::tr("The signature of the certificate is invalid");
242  break;
244  errStr = QSslSocket::tr("The certificate is not yet valid");
245  break;
246  case CertificateExpired:
247  errStr = QSslSocket::tr("The certificate has expired");
248  break;
250  errStr = QSslSocket::tr("The certificate's notBefore field contains an invalid time");
251  break;
253  errStr = QSslSocket::tr("The certificate's notAfter field contains an invalid time");
254  break;
256  errStr = QSslSocket::tr("The certificate is self-signed, and untrusted");
257  break;
259  errStr = QSslSocket::tr("The root certificate of the certificate chain is self-signed, and untrusted");
260  break;
262  errStr = QSslSocket::tr("The issuer certificate of a locally looked up certificate could not be found");
263  break;
265  errStr = QSslSocket::tr("No certificates could be verified");
266  break;
268  errStr = QSslSocket::tr("One of the CA certificates is invalid");
269  break;
270  case PathLengthExceeded:
271  errStr = QSslSocket::tr("The basicConstraints path length parameter has been exceeded");
272  break;
273  case InvalidPurpose:
274  errStr = QSslSocket::tr("The supplied certificate is unsuitable for this purpose");
275  break;
277  errStr = QSslSocket::tr("The root CA certificate is not trusted for this purpose");
278  break;
279  case CertificateRejected:
280  errStr = QSslSocket::tr("The root CA certificate is marked to reject the specified purpose");
281  break;
282  case SubjectIssuerMismatch: // hostname mismatch
283  errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because its"
284  " subject name did not match the issuer name of the current certificate");
285  break;
287  errStr = QSslSocket::tr("The current candidate issuer certificate was rejected because"
288  " its issuer name and serial number was present and did not match the"
289  " authority key identifier of the current certificate");
290  break;
291  case NoPeerCertificate:
292  errStr = QSslSocket::tr("The peer did not present any certificate");
293  break;
294  case HostNameMismatch:
295  errStr = QSslSocket::tr("The host name did not match any of the valid hosts"
296  " for this certificate");
297  break;
298  case NoSslSupport:
299  break;
301  errStr = QSslSocket::tr("The peer certificate is blacklisted");
302  break;
303  default:
304  errStr = QSslSocket::tr("Unknown error");
305  break;
306  }
307 
308  return errStr;
309 }
310 
318 {
319  return d->certificate;
320 }
321 
322 #ifndef QT_NO_DEBUG_STREAM
323 //class QDebug;
325 {
326  debug << error.errorString();
327  return debug;
328 }
330 {
331  debug << QSslError(error).errorString();
332  return debug;
333 }
334 #endif
335 
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
double d
Definition: qnumeric_p.h:62
QSslCertificate certificate() const
Returns the certificate associated with this error, or a null certificate if the error does not relat...
Definition: qsslerror.cpp:317
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QSslCertificate certificate
Definition: qsslerror.cpp:112
T * data() const
Returns the value of the pointer referenced by this object.
QDebug operator<<(QDebug debug, const QSslError &error)
Definition: qsslerror.cpp:324
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString errorString() const
Returns a short localized human-readable description of the error.
Definition: qsslerror.cpp:224
QScopedPointer< QSslErrorPrivate > d
Definition: qsslerror.h:109
QSslError::SslError error
Definition: qsslerror.cpp:111
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
SslError
Describes all recognized errors that can occur during an SSL handshake.
Definition: qsslerror.h:61
~QSslError()
Destroys the QSslError object.
Definition: qsslerror.cpp:166
QSslError()
Constructs a QSslError object with no error and default certificate.
Definition: qsslerror.cpp:122
The QSslCertificate class provides a convenient API for an X509 certificate.
The QSslError class provides an SSL error.
Definition: qsslerror.h:58
bool operator==(const QSslError &other) const
Returns true if this error is equal to other; otherwise returns false.
Definition: qsslerror.cpp:192
SslError error() const
Returns the type of the error.
Definition: qsslerror.cpp:214
QSslError & operator=(const QSslError &other)
Assigns the contents of other to this error.
Definition: qsslerror.cpp:178