Qt 4.8
qsslconfiguration.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 #include "qsslconfiguration.h"
43 #include "qsslconfiguration_p.h"
44 #include "qsslsocket.h"
45 #include "qmutex.h"
46 #include "qdebug.h"
47 
49 
121 {
122 }
123 
129  : d(other.d)
130 {
131 }
132 
137 {
138  // QSharedDataPointer deletes d for us if necessary
139 }
140 
146 {
147  d = other.d;
148  return *this;
149 }
150 
161 {
162  if (d == other.d)
163  return true;
164  return d->peerCertificate == other.d->peerCertificate &&
166  d->localCertificate == other.d->localCertificate &&
167  d->privateKey == other.d->privateKey &&
168  d->sessionCipher == other.d->sessionCipher &&
169  d->ciphers == other.d->ciphers &&
170  d->caCertificates == other.d->caCertificates &&
171  d->protocol == other.d->protocol &&
172  d->peerVerifyMode == other.d->peerVerifyMode &&
173  d->peerVerifyDepth == other.d->peerVerifyDepth &&
175  d->sslOptions == other.d->sslOptions;
176 }
177 
201 {
202  return (d->protocol == QSsl::SecureProtocols &&
204  d->peerVerifyDepth == 0 &&
205  d->allowRootCertOnDemandLoading == true &&
206  d->caCertificates.count() == 0 &&
207  d->ciphers.count() == 0 &&
209  d->privateKey.isNull() &&
210  d->peerCertificate.isNull() &&
211  d->peerCertificateChain.count() == 0 &&
215 }
216 
223 {
224  return d->protocol;
225 }
226 
237 {
238  d->protocol = protocol;
239 }
240 
253 {
254  return d->peerVerifyMode;
255 }
256 
269 {
270  d->peerVerifyMode = mode;
271 }
272 
273 
286 {
287  return d->peerVerifyDepth;
288 }
289 
302 {
303  if (depth < 0) {
304  qWarning("QSslConfiguration::setPeerVerifyDepth: cannot set negative depth of %d", depth);
305  return;
306  }
307  d->peerVerifyDepth = depth;
308 }
309 
317 {
318  return d->localCertificate;
319 }
320 
338 {
339  d->localCertificate = certificate;
340 }
341 
371 {
372  return d->peerCertificate;
373 }
374 
403 {
404  return d->peerCertificateChain;
405 }
406 
421 {
422  return d->sessionCipher;
423 }
424 
432 {
433  return d->privateKey;
434 }
435 
450 {
451  d->privateKey = key;
452 }
453 
474 {
475  return d->ciphers;
476 }
477 
489 {
490  d->ciphers = ciphers;
491 }
492 
504 {
505  return d->caCertificates;
506 }
507 
517 {
518  d->caCertificates = certificates;
520 }
521 
528 {
529  if (on)
530  d->sslOptions |= option;
531  else
532  d->sslOptions &= ~option;
533 }
534 
546 {
547  return d->sslOptions & option;
548 }
549 
567 {
569 }
570 
579 {
581 }
582 
double d
Definition: qnumeric_p.h:62
The QSslKey class provides an interface for private and public keys.
Definition: qsslkey.h:64
QSharedDataPointer< QSslConfigurationPrivate > d
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QList< QSslCipher > ciphers() const
Returns this connection&#39;s current cryptographic cipher suite.
void setPrivateKey(const QSslKey &key)
Sets the connection&#39;s private QSslKey {key} to key.
void setCaCertificates(const QList< QSslCertificate > &certificates)
Sets this socket&#39;s CA certificate database to be certificates.
QList< QSslCipher > ciphers
void setCiphers(const QList< QSslCipher > &ciphers)
Sets the cryptographic cipher suite for this socket to ciphers, which must contain a subset of the ci...
void setPeerVerifyDepth(int depth)
Sets the maximum number of certificates in the peer&#39;s certificate chain to be checked during the SSL ...
bool operator==(const QSslConfiguration &other) const
Returns true if this QSslConfiguration object is equal to other.
QList< QSslCertificate > peerCertificateChain() const
Returns the peer&#39;s chain of digital certificates, starting with the peer&#39;s immediate certificate and ...
~QSslConfiguration()
Releases any resources held by QSslConfiguration.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QSslCipher class represents an SSL cryptographic cipher.
Definition: qsslcipher.h:59
bool isNull() const
Returns true if this is a null certificate (i.e., a certificate with no contents); otherwise returns ...
QSsl::SslProtocol protocol() const
Returns the protocol setting for this SSL configuration.
QList< QSslCertificate > caCertificates
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
SslProtocol
Describes the protocol of the cipher.
Definition: qssl.h:76
QSslConfiguration()
Constructs an empty SSL configuration.
static QSslConfiguration defaultConfiguration()
static void setDefaultConfiguration(const QSslConfiguration &configuration)
Sets the default SSL configuration to be used in new SSL connections to be configuration.
QSslCipher sessionCipher() const
Returns the socket&#39;s cryptographic QSslCipher {cipher}, or a null cipher if the connection isn&#39;t encr...
bool isNull() const
Returns true if this is a null QSslConfiguration object.
QSslSocket::PeerVerifyMode peerVerifyMode
Q_CORE_EXPORT void qWarning(const char *,...)
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
static void setDefaultConfiguration(const QSslConfiguration &configuration)
QSslKey privateKey() const
Returns the QSslKey {SSL key} assigned to this connection or a null key if none has been assigned yet...
QSslCertificate localCertificate
SslOption
Describes the options that can be used to control the details of SSL behaviour.
Definition: qssl.h:86
void setLocalCertificate(const QSslCertificate &certificate)
Sets the certificate to be presented to the peer during SSL handshake to be certificate.
bool testSslOption(QSsl::SslOption option) const
Returns true if the specified SSL compatibility option is enabled.
void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
Sets the verify mode to mode.
int peerVerifyDepth() const
Returns the maximum number of certificates in the peer&#39;s certificate chain to be checked during the S...
int key
QSslCertificate localCertificate() const
Returns the certificate to be presented to the peer during the SSL handshake process.
void setSslOption(QSsl::SslOption option, bool on)
Enables or disables an SSL compatibility option.
QSslConfiguration & operator=(const QSslConfiguration &other)
Copies the configuration and state of other.
bool isNull() const
Returns true if this is a null key; otherwise false.
Definition: qsslkey.cpp:310
The QSslCertificate class provides a convenient API for an X509 certificate.
The QSslConfiguration class holds the configuration and state of an SSL connection.
QSslSocket::PeerVerifyMode peerVerifyMode() const
Returns the verify mode.
QList< QSslCertificate > caCertificates() const
Returns this connection&#39;s CA certificate database.
QList< QSslCertificate > peerCertificateChain
void setProtocol(QSsl::SslProtocol protocol)
Sets the protocol setting for this configuration to be protocol.
QSslCertificate peerCertificate() const
Returns the peer&#39;s digital certificate (i.e., the immediate certificate of the host you are connected...
PeerVerifyMode
Describes the peer verification modes for QSslSocket.
Definition: qsslsocket.h:77