qsslconfiguration.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
  5. ** Contact: https://www.qt.io/licensing/
  6. **
  7. ** This file is part of the QtNetwork module of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** Commercial License Usage
  11. ** Licensees holding valid commercial Qt licenses may use this file in
  12. ** accordance with the commercial license agreement provided with the
  13. ** Software or, alternatively, in accordance with the terms contained in
  14. ** a written agreement between you and The Qt Company. For licensing terms
  15. ** and conditions see https://www.qt.io/terms-conditions. For further
  16. ** information use the contact form at https://www.qt.io/contact-us.
  17. **
  18. ** GNU Lesser General Public License Usage
  19. ** Alternatively, this file may be used under the terms of the GNU Lesser
  20. ** General Public License version 3 as published by the Free Software
  21. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  22. ** packaging of this file. Please review the following information to
  23. ** ensure the GNU Lesser General Public License version 3 requirements
  24. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  25. **
  26. ** GNU General Public License Usage
  27. ** Alternatively, this file may be used under the terms of the GNU
  28. ** General Public License version 2.0 or (at your option) the GNU General
  29. ** Public license version 3 or any later version approved by the KDE Free
  30. ** Qt Foundation. The licenses are as published by the Free Software
  31. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  32. ** included in the packaging of this file. Please review the following
  33. ** information to ensure the GNU General Public License requirements will
  34. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  35. ** https://www.gnu.org/licenses/gpl-3.0.html.
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. /****************************************************************************
  41. **
  42. ** In addition, as a special exception, the copyright holders listed above give
  43. ** permission to link the code of its release of Qt with the OpenSSL project's
  44. ** "OpenSSL" library (or modified versions of the "OpenSSL" library that use the
  45. ** same license as the original version), and distribute the linked executables.
  46. **
  47. ** You must comply with the GNU General Public License version 2 in all
  48. ** respects for all of the code used other than the "OpenSSL" code. If you
  49. ** modify this file, you may extend this exception to your version of the file,
  50. ** but you are not obligated to do so. If you do not wish to do so, delete
  51. ** this exception statement from your version of this file.
  52. **
  53. ****************************************************************************/
  54. #ifndef QSSLCONFIGURATION_H
  55. #define QSSLCONFIGURATION_H
  56. #include <QtCore/qshareddata.h>
  57. #include <QtNetwork/qsslsocket.h>
  58. #include <QtNetwork/qssl.h>
  59. #ifndef QT_NO_SSL
  60. QT_BEGIN_NAMESPACE
  61. template<typename T> class QList;
  62. class QSslCertificate;
  63. class QSslCipher;
  64. class QSslKey;
  65. class QSslEllipticCurve;
  66. class QSslConfigurationPrivate;
  67. class Q_NETWORK_EXPORT QSslConfiguration
  68. {
  69. public:
  70. QSslConfiguration();
  71. QSslConfiguration(const QSslConfiguration &other);
  72. ~QSslConfiguration();
  73. #ifdef Q_COMPILER_RVALUE_REFS
  74. QSslConfiguration &operator=(QSslConfiguration &&other) Q_DECL_NOTHROW { swap(other); return *this; }
  75. #endif
  76. QSslConfiguration &operator=(const QSslConfiguration &other);
  77. void swap(QSslConfiguration &other) Q_DECL_NOTHROW
  78. { qSwap(d, other.d); }
  79. bool operator==(const QSslConfiguration &other) const;
  80. inline bool operator!=(const QSslConfiguration &other) const
  81. { return !(*this == other); }
  82. bool isNull() const;
  83. QSsl::SslProtocol protocol() const;
  84. void setProtocol(QSsl::SslProtocol protocol);
  85. // Verification
  86. QSslSocket::PeerVerifyMode peerVerifyMode() const;
  87. void setPeerVerifyMode(QSslSocket::PeerVerifyMode mode);
  88. int peerVerifyDepth() const;
  89. void setPeerVerifyDepth(int depth);
  90. // Certificate & cipher configuration
  91. QList<QSslCertificate> localCertificateChain() const;
  92. void setLocalCertificateChain(const QList<QSslCertificate> &localChain);
  93. QSslCertificate localCertificate() const;
  94. void setLocalCertificate(const QSslCertificate &certificate);
  95. QSslCertificate peerCertificate() const;
  96. QList<QSslCertificate> peerCertificateChain() const;
  97. QSslCipher sessionCipher() const;
  98. QSsl::SslProtocol sessionProtocol() const;
  99. // Private keys, for server sockets
  100. QSslKey privateKey() const;
  101. void setPrivateKey(const QSslKey &key);
  102. // Cipher settings
  103. QList<QSslCipher> ciphers() const;
  104. void setCiphers(const QList<QSslCipher> &ciphers);
  105. static QList<QSslCipher> supportedCiphers();
  106. // Certificate Authority (CA) settings
  107. QList<QSslCertificate> caCertificates() const;
  108. void setCaCertificates(const QList<QSslCertificate> &certificates);
  109. static QList<QSslCertificate> systemCaCertificates();
  110. void setSslOption(QSsl::SslOption option, bool on);
  111. bool testSslOption(QSsl::SslOption option) const;
  112. QByteArray sessionTicket() const;
  113. void setSessionTicket(const QByteArray &sessionTicket);
  114. int sessionTicketLifeTimeHint() const;
  115. QSslKey ephemeralServerKey() const;
  116. // EC settings
  117. QVector<QSslEllipticCurve> ellipticCurves() const;
  118. void setEllipticCurves(const QVector<QSslEllipticCurve> &curves);
  119. static QVector<QSslEllipticCurve> supportedEllipticCurves();
  120. static QSslConfiguration defaultConfiguration();
  121. static void setDefaultConfiguration(const QSslConfiguration &configuration);
  122. enum NextProtocolNegotiationStatus {
  123. NextProtocolNegotiationNone,
  124. NextProtocolNegotiationNegotiated,
  125. NextProtocolNegotiationUnsupported
  126. };
  127. #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
  128. void setAllowedNextProtocols(const QList<QByteArray> &protocols);
  129. #else
  130. void setAllowedNextProtocols(QList<QByteArray> protocols);
  131. #endif
  132. QList<QByteArray> allowedNextProtocols() const;
  133. QByteArray nextNegotiatedProtocol() const;
  134. NextProtocolNegotiationStatus nextProtocolNegotiationStatus() const;
  135. static const char NextProtocolSpdy3_0[];
  136. static const char NextProtocolHttp1_1[];
  137. private:
  138. friend class QSslSocket;
  139. friend class QSslConfigurationPrivate;
  140. friend class QSslSocketBackendPrivate;
  141. friend class QSslContext;
  142. QSslConfiguration(QSslConfigurationPrivate *dd);
  143. QSharedDataPointer<QSslConfigurationPrivate> d;
  144. };
  145. Q_DECLARE_SHARED(QSslConfiguration)
  146. QT_END_NAMESPACE
  147. Q_DECLARE_METATYPE(QSslConfiguration)
  148. #endif // QT_NO_SSL
  149. #endif