/src/network/ssl/qsslsocket_p.h

https://bitbucket.org/ultra_iter/qt-vtl · C Header · 183 lines · 103 code · 26 blank · 54 comment · 1 complexity · 64ac0611dab963118185ed22827159bb MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the QtNetwork module of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #ifndef QSSLSOCKET_P_H
  42. #define QSSLSOCKET_P_H
  43. #include "qsslsocket.h"
  44. //
  45. // W A R N I N G
  46. // -------------
  47. //
  48. // This file is not part of the Qt API. It exists for the convenience
  49. // of the QLibrary class. This header file may change from
  50. // version to version without notice, or even be removed.
  51. //
  52. // We mean it.
  53. //
  54. #include <private/qtcpsocket_p.h>
  55. #include "qsslkey.h"
  56. #include "qsslconfiguration_p.h"
  57. #include <QtCore/qstringlist.h>
  58. #include <private/qringbuffer_p.h>
  59. QT_BEGIN_NAMESPACE
  60. #if defined(Q_OS_MAC)
  61. #include <Security/SecCertificate.h>
  62. #include <CoreFoundation/CFArray.h>
  63. #ifndef QT_NO_CORESERVICES
  64. typedef OSStatus (*PtrSecCertificateGetData)(SecCertificateRef, CSSM_DATA_PTR);
  65. typedef OSStatus (*PtrSecTrustSettingsCopyCertificates)(int, CFArrayRef*);
  66. typedef OSStatus (*PtrSecTrustCopyAnchorCertificates)(CFArrayRef*);
  67. #endif
  68. #elif defined(Q_OS_WIN)
  69. #include <windows.h>
  70. #include <wincrypt.h>
  71. #ifndef HCRYPTPROV_LEGACY
  72. #define HCRYPTPROV_LEGACY HCRYPTPROV
  73. #endif
  74. #if defined(Q_OS_WINCE)
  75. typedef HCERTSTORE (WINAPI *PtrCertOpenSystemStoreW)(LPCSTR, DWORD, HCRYPTPROV_LEGACY, DWORD, const void*);
  76. #else
  77. typedef HCERTSTORE (WINAPI *PtrCertOpenSystemStoreW)(HCRYPTPROV_LEGACY, LPCWSTR);
  78. #endif
  79. typedef PCCERT_CONTEXT (WINAPI *PtrCertFindCertificateInStore)(HCERTSTORE, DWORD, DWORD, DWORD, const void*, PCCERT_CONTEXT);
  80. typedef BOOL (WINAPI *PtrCertCloseStore)(HCERTSTORE, DWORD);
  81. #endif
  82. class QSslSocketPrivate : public QTcpSocketPrivate
  83. {
  84. Q_DECLARE_PUBLIC(QSslSocket)
  85. public:
  86. QSslSocketPrivate();
  87. virtual ~QSslSocketPrivate();
  88. void init();
  89. bool initialized;
  90. QSslSocket::SslMode mode;
  91. bool autoStartHandshake;
  92. bool connectionEncrypted;
  93. bool ignoreAllSslErrors;
  94. QList<QSslError> ignoreErrorsList;
  95. bool* readyReadEmittedPointer;
  96. QSslConfigurationPrivate configuration;
  97. QList<QSslError> sslErrors;
  98. // if set, this hostname is used for certificate validation instead of the hostname
  99. // that was used for connecting to.
  100. QString verificationPeerName;
  101. bool allowRootCertOnDemandLoading;
  102. static bool supportsSsl();
  103. static void ensureInitialized();
  104. static void deinitialize();
  105. static QList<QSslCipher> defaultCiphers();
  106. static QList<QSslCipher> supportedCiphers();
  107. static void setDefaultCiphers(const QList<QSslCipher> &ciphers);
  108. static void setDefaultSupportedCiphers(const QList<QSslCipher> &ciphers);
  109. static void resetDefaultCiphers();
  110. static QList<QSslCertificate> defaultCaCertificates();
  111. static QList<QSslCertificate> systemCaCertificates();
  112. static void setDefaultCaCertificates(const QList<QSslCertificate> &certs);
  113. static bool addDefaultCaCertificates(const QString &path, QSsl::EncodingFormat format,
  114. QRegExp::PatternSyntax syntax);
  115. static void addDefaultCaCertificate(const QSslCertificate &cert);
  116. static void addDefaultCaCertificates(const QList<QSslCertificate> &certs);
  117. #if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
  118. static PtrSecCertificateGetData ptrSecCertificateGetData;
  119. static PtrSecTrustSettingsCopyCertificates ptrSecTrustSettingsCopyCertificates;
  120. static PtrSecTrustCopyAnchorCertificates ptrSecTrustCopyAnchorCertificates;
  121. #elif defined(Q_OS_WIN)
  122. static PtrCertOpenSystemStoreW ptrCertOpenSystemStoreW;
  123. static PtrCertFindCertificateInStore ptrCertFindCertificateInStore;
  124. static PtrCertCloseStore ptrCertCloseStore;
  125. #endif
  126. // The socket itself, including private slots.
  127. QTcpSocket *plainSocket;
  128. void createPlainSocket(QIODevice::OpenMode openMode);
  129. static void pauseSocketNotifiers(QSslSocket*);
  130. static void resumeSocketNotifiers(QSslSocket*);
  131. void _q_connectedSlot();
  132. void _q_hostFoundSlot();
  133. void _q_disconnectedSlot();
  134. void _q_stateChangedSlot(QAbstractSocket::SocketState);
  135. void _q_errorSlot(QAbstractSocket::SocketError);
  136. void _q_readyReadSlot();
  137. void _q_bytesWrittenSlot(qint64);
  138. void _q_flushWriteBuffer();
  139. void _q_flushReadBuffer();
  140. // Platform specific functions
  141. virtual void startClientEncryption() = 0;
  142. virtual void startServerEncryption() = 0;
  143. virtual void transmit() = 0;
  144. virtual void disconnectFromHost() = 0;
  145. virtual void disconnected() = 0;
  146. virtual QSslCipher sessionCipher() const = 0;
  147. private:
  148. static bool ensureLibraryLoaded();
  149. static void ensureCiphersAndCertsLoaded();
  150. static bool s_libraryLoaded;
  151. static bool s_loadedCiphersAndCerts;
  152. protected:
  153. static bool s_loadRootCertsOnDemand;
  154. static QList<QByteArray> unixRootCertDirectories();
  155. };
  156. QT_END_NAMESPACE
  157. #endif