QtBase  v6.3.1
qsslcontext_openssl_p.h
Go to the documentation of this file.
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 #ifndef QSSLCONTEXT_OPENSSL_P_H
43 #define QSSLCONTEXT_OPENSSL_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtNetwork/private/qtnetworkglobal_p.h>
57 #include <QtCore/qvariant.h>
58 #include <QtNetwork/qsslcertificate.h>
59 #include <QtNetwork/qsslconfiguration.h>
60 #include <openssl/ssl.h>
61 
63 
64 #ifndef QT_NO_SSL
65 
67 {
68 public:
69 
70  ~QSslContext();
71 
72  static std::shared_ptr<QSslContext> sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration,
73  bool allowRootCertOnDemandLoading);
74  static std::shared_ptr<QSslContext> sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration,
75  bool allowRootCertOnDemandLoading);
76  static long setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions);
77 
78  QSslError::SslError error() const;
79  QString errorString() const;
80 
81  SSL* createSsl();
82  bool cacheSession(SSL*); // should be called when handshake completed
83 
84  QByteArray sessionASN1() const;
86  int sessionTicketLifeTimeHint() const;
87 
88  static void forceAutoTestSecurityLevel();
89 
90 #ifndef OPENSSL_NO_NEXTPROTONEG
91  // must be public because we want to use it from an OpenSSL callback
92  struct NPNContext {
94  len(0),
95  status(QSslConfiguration::NextProtocolNegotiationNone)
96  { }
97  unsigned char *data;
98  unsigned short len;
100  };
101  NPNContext npnContext() const;
102 #endif // !OPENSSL_NO_NEXTPROTONEG
103 
104 protected:
105  QSslContext();
106 
107 private:
108  static void initSslContext(QSslContext* sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration,
109  bool allowRootCertOnDemandLoading);
110  static void applyBackendConfig(QSslContext *sslContext);
111 
112 private:
113  SSL_CTX* ctx;
114  EVP_PKEY *pkey;
115  SSL_SESSION *session;
116  QByteArray m_sessionASN1;
117  int m_sessionTicketLifeTimeHint;
118  QSslError::SslError errorCode;
119  QString errorStr;
120  QSslConfiguration sslConfiguration;
121 #ifndef OPENSSL_NO_NEXTPROTONEG
122  QByteArray m_supportedNPNVersions;
123  NPNContext m_npnContext;
124 #endif // !OPENSSL_NO_NEXTPROTONEG
125 };
126 
127 #endif // QT_NO_SSL
128 
130 
131 #endif // QSSLCONTEXT_OPENSSL_P_H
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QSslConfiguration class holds the configuration and state of an SSL connection.
QByteArray sessionASN1() const
static std::shared_ptr< QSslContext > sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration, bool allowRootCertOnDemandLoading)
int sessionTicketLifeTimeHint() const
NPNContext npnContext() const
QString errorString() const
static void forceAutoTestSecurityLevel()
static long setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions)
void setSessionASN1(const QByteArray &sessionASN1)
bool cacheSession(SSL *)
QSslError::SslError error() const
static std::shared_ptr< QSslContext > sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, bool allowRootCertOnDemandLoading)
The QString class provides a Unicode character string.
Definition: qstring.h:388
SslProtocol
Definition: qssl.h:75
GLenum mode
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLsizei len
Definition: qopenglext.h:3292
QObject::connect nullptr
QSslConfiguration::NextProtocolNegotiationStatus status