Qt 4.8
qsslsocket_p.h
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 
43 #ifndef QSSLSOCKET_P_H
44 #define QSSLSOCKET_P_H
45 
46 #include "qsslsocket.h"
47 
48 //
49 // W A R N I N G
50 // -------------
51 //
52 // This file is not part of the Qt API. It exists for the convenience
53 // of the QLibrary class. This header file may change from
54 // version to version without notice, or even be removed.
55 //
56 // We mean it.
57 //
58 
59 #include <private/qtcpsocket_p.h>
60 #include "qsslkey.h"
61 #include "qsslconfiguration_p.h"
62 
63 #include <QtCore/qstringlist.h>
64 
65 #include <private/qringbuffer_p.h>
66 
67 #if defined(Q_OS_MAC)
68 #include <Security/SecCertificate.h>
69 #include <CoreFoundation/CFArray.h>
70 #elif defined(Q_OS_WIN)
71 #include <windows.h>
72 #include <wincrypt.h>
73 #ifndef HCRYPTPROV_LEGACY
74 #define HCRYPTPROV_LEGACY HCRYPTPROV
75 #endif
76 #endif
77 
79 
80 #if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
81  typedef OSStatus (*PtrSecCertificateGetData)(SecCertificateRef, CSSM_DATA_PTR);
84 #endif
85 
86 #if defined(Q_OS_WIN)
87 #if defined(Q_OS_WINCE)
88  typedef HCERTSTORE (WINAPI *PtrCertOpenSystemStoreW)(LPCSTR, DWORD, HCRYPTPROV_LEGACY, DWORD, const void*);
89 #else
90  typedef HCERTSTORE (WINAPI *PtrCertOpenSystemStoreW)(HCRYPTPROV_LEGACY, LPCWSTR);
91 #endif
92  typedef PCCERT_CONTEXT (WINAPI *PtrCertFindCertificateInStore)(HCERTSTORE, DWORD, DWORD, DWORD, const void*, PCCERT_CONTEXT);
93  typedef BOOL (WINAPI *PtrCertCloseStore)(HCERTSTORE, DWORD);
94 #endif
95 
96 
97 
99 {
101 public:
103  virtual ~QSslSocketPrivate();
104 
105  void init();
107 
111  bool shutdown;
115 
118 
119  // if set, this hostname is used for certificate validation instead of the hostname
120  // that was used for connecting to.
122 
124 
125  static bool supportsSsl();
126  static void ensureInitialized();
127  static void deinitialize();
130  static void setDefaultCiphers(const QList<QSslCipher> &ciphers);
131  static void setDefaultSupportedCiphers(const QList<QSslCipher> &ciphers);
132  static void resetDefaultCiphers();
133 
136  static void setDefaultCaCertificates(const QList<QSslCertificate> &certs);
138  QRegExp::PatternSyntax syntax);
139  static void addDefaultCaCertificate(const QSslCertificate &cert);
140  static void addDefaultCaCertificates(const QList<QSslCertificate> &certs);
141 
142 #if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
146 #elif defined(Q_OS_WIN)
147  static PtrCertOpenSystemStoreW ptrCertOpenSystemStoreW;
148  static PtrCertFindCertificateInStore ptrCertFindCertificateInStore;
149  static PtrCertCloseStore ptrCertCloseStore;
150 #endif
151 
152  // The socket itself, including private slots.
154  void createPlainSocket(QIODevice::OpenMode openMode);
155  static void pauseSocketNotifiers(QSslSocket*);
156  static void resumeSocketNotifiers(QSslSocket*);
157  void _q_connectedSlot();
158  void _q_hostFoundSlot();
159  void _q_disconnectedSlot();
162  void _q_readyReadSlot();
164  void _q_flushWriteBuffer();
165  void _q_flushReadBuffer();
166 
167  virtual qint64 peek(char *data, qint64 maxSize);
168  virtual QByteArray peek(qint64 maxSize);
169 
170  // Platform specific functions
171  virtual void startClientEncryption() = 0;
172  virtual void startServerEncryption() = 0;
173  virtual void transmit() = 0;
174  virtual void disconnectFromHost() = 0;
175  virtual void disconnected() = 0;
176  virtual QSslCipher sessionCipher() const = 0;
177 
179 
180 private:
181  static bool ensureLibraryLoaded();
182  static void ensureCiphersAndCertsLoaded();
183 
184  static bool s_libraryLoaded;
186 protected:
189 };
190 
192 
193 #endif
static PtrSecTrustCopyAnchorCertificates ptrSecTrustCopyAnchorCertificates
Definition: qsslsocket_p.h:145
static void deinitialize()
static bool addDefaultCaCertificates(const QString &path, QSsl::EncodingFormat format, QRegExp::PatternSyntax syntax)
virtual void startServerEncryption()=0
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QIODevice::OpenMode openMode
Definition: qiodevice_p.h:212
static void resumeSocketNotifiers(QSslSocket *)
static void setDefaultSupportedCiphers(const QList< QSslCipher > &ciphers)
static QList< QByteArray > unixRootCertDirectories()
void createPlainSocket(QIODevice::OpenMode openMode)
HCERTSTORE(WINAPI * PtrCertOpenSystemStoreW)(LPCSTR, DWORD, HCRYPTPROV_LEGACY, DWORD, const void *)
Definition: qsslsocket_p.h:88
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition: qsslsocket.h:67
virtual void startClientEncryption()=0
static void addDefaultCaCertificate(const QSslCertificate &cert)
void _q_stateChangedSlot(QAbstractSocket::SocketState)
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual void disconnectFromHost()=0
static QList< QSslCertificate > defaultCaCertificates()
BOOL(WINAPI * PtrCertCloseStore)(HCERTSTORE, DWORD)
Definition: qsslsocket_p.h:93
QSslSocket::SslMode mode
Definition: qsslsocket_p.h:108
static bool s_loadRootCertsOnDemand
Definition: qsslsocket_p.h:187
void _q_bytesWrittenSlot(qint64)
The QSslCipher class represents an SSL cryptographic cipher.
Definition: qsslcipher.h:59
OSStatus(* PtrSecTrustCopyAnchorCertificates)(CFArrayRef *)
Definition: qsslsocket_p.h:83
void _q_disconnectedSlot()
SocketState
This enum describes the different states in which a socket can be.
static void setDefaultCiphers(const QList< QSslCipher > &ciphers)
QList< QSslError > ignoreErrorsList
Definition: qsslsocket_p.h:113
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void transmit()=0
SslMode
Describes the connection modes available for QSslSocket.
Definition: qsslsocket.h:71
static bool s_loadedCiphersAndCerts
Definition: qsslsocket_p.h:185
SocketError
This enum describes the socket errors that can occur.
static void setDefaultCaCertificates(const QList< QSslCertificate > &certs)
static const char * data(const QByteArray &arr)
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
static bool supportsSsl()
Does the minimum amount of initialization to determine whether SSL is supported or not...
static void ensureCiphersAndCertsLoaded()
signed long OSStatus
static bool s_libraryLoaded
Definition: qsslsocket_p.h:184
virtual QSslCipher sessionCipher() const =0
QSslConfigurationPrivate configuration
Definition: qsslsocket_p.h:116
OSStatus(* PtrSecTrustSettingsCopyCertificates)(int, CFArrayRef *)
Definition: qsslsocket_p.h:82
static PtrSecCertificateGetData ptrSecCertificateGetData
Definition: qsslsocket_p.h:143
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
PatternSyntax
The syntax used to interpret the meaning of the pattern.
Definition: qregexp.h:64
EncodingFormat
Describes supported encoding formats for certificates and keys.
Definition: qssl.h:61
static PtrSecTrustSettingsCopyCertificates ptrSecTrustSettingsCopyCertificates
Definition: qsslsocket_p.h:144
virtual void disconnected()=0
static void resetDefaultCiphers()
Declared static in QSslSocketPrivate, backend-dependent loading of application-wide global ciphers...
static QList< QSslCertificate > systemCaCertificates()
QTcpSocket * plainSocket
Definition: qsslsocket_p.h:153
void _q_flushWriteBuffer()
OSStatus(* PtrSecCertificateGetData)(SecCertificateRef, CSSM_DATA_PTR)
Definition: qsslsocket_p.h:81
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
void _q_errorSlot(QAbstractSocket::SocketError)
bool * readyReadEmittedPointer
Definition: qsslsocket_p.h:114
virtual ~QSslSocketPrivate()
QString verificationPeerName
Definition: qsslsocket_p.h:121
static void ensureInitialized()
Declared static in QSslSocketPrivate, makes sure the SSL libraries have been initialized.
QList< QSslError > sslErrors
Definition: qsslsocket_p.h:117
The QSslCertificate class provides a convenient API for an X509 certificate.
static QList< QSslCipher > supportedCiphers()
static QList< QSslCipher > defaultCiphers()
bool allowRootCertOnDemandLoading
Definition: qsslsocket_p.h:123
PCCERT_CONTEXT(WINAPI * PtrCertFindCertificateInStore)(HCERTSTORE, DWORD, DWORD, DWORD, const void *, PCCERT_CONTEXT)
Definition: qsslsocket_p.h:92
const struct __CFArray * CFArrayRef
static void pauseSocketNotifiers(QSslSocket *)
static bool ensureLibraryLoaded()
virtual qint64 peek(char *data, qint64 maxSize)
static Q_AUTOTEST_EXPORT bool rootCertOnDemandLoadingSupported()