1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // Copyright (C) 2014 BlackBerry Limited. All rights reserved. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | |
6 | #ifndef QSSLCONTEXT_OPENSSL_P_H |
7 | #define QSSLCONTEXT_OPENSSL_P_H |
8 | |
9 | // |
10 | // W A R N I N G |
11 | // ------------- |
12 | // |
13 | // This file is not part of the Qt API. It exists purely as an |
14 | // implementation detail. This header file may change from version to |
15 | // version without notice, or even be removed. |
16 | // |
17 | // We mean it. |
18 | // |
19 | |
20 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
21 | #include <QtCore/qvariant.h> |
22 | #include <QtNetwork/qsslcertificate.h> |
23 | #include <QtNetwork/qsslconfiguration.h> |
24 | #include <openssl/ssl.h> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | #ifndef QT_NO_SSL |
29 | |
30 | class QSslContext |
31 | { |
32 | public: |
33 | |
34 | ~QSslContext(); |
35 | |
36 | static std::shared_ptr<QSslContext> sharedFromConfiguration(QSslSocket::SslMode mode, const QSslConfiguration &configuration, |
37 | bool allowRootCertOnDemandLoading); |
38 | static std::shared_ptr<QSslContext> sharedFromPrivateConfiguration(QSslSocket::SslMode mode, QSslConfigurationPrivate *privConfiguration, |
39 | bool allowRootCertOnDemandLoading); |
40 | |
41 | static qssloptions setupOpenSslOptions(QSsl::SslProtocol protocol, QSsl::SslOptions sslOptions); |
42 | |
43 | QSslError::SslError error() const; |
44 | QString errorString() const; |
45 | |
46 | SSL* createSsl(); |
47 | bool cacheSession(SSL*); // should be called when handshake completed |
48 | |
49 | QByteArray sessionASN1() const; |
50 | void setSessionASN1(const QByteArray &sessionASN1); |
51 | int sessionTicketLifeTimeHint() const; |
52 | |
53 | static void forceAutoTestSecurityLevel(); |
54 | |
55 | #ifndef OPENSSL_NO_NEXTPROTONEG |
56 | // must be public because we want to use it from an OpenSSL callback |
57 | struct NPNContext { |
58 | NPNContext() : data(nullptr), |
59 | len(0), |
60 | status(QSslConfiguration::NextProtocolNegotiationNone) |
61 | { } |
62 | unsigned char *data; |
63 | unsigned short len; |
64 | QSslConfiguration::NextProtocolNegotiationStatus status; |
65 | }; |
66 | NPNContext npnContext() const; |
67 | #endif // !OPENSSL_NO_NEXTPROTONEG |
68 | |
69 | protected: |
70 | QSslContext(); |
71 | |
72 | private: |
73 | static void initSslContext(QSslContext* sslContext, QSslSocket::SslMode mode, const QSslConfiguration &configuration, |
74 | bool allowRootCertOnDemandLoading); |
75 | static void applyBackendConfig(QSslContext *sslContext); |
76 | |
77 | private: |
78 | SSL_CTX* ctx; |
79 | EVP_PKEY *pkey; |
80 | SSL_SESSION *session; |
81 | QByteArray m_sessionASN1; |
82 | int m_sessionTicketLifeTimeHint; |
83 | QSslError::SslError errorCode; |
84 | QString errorStr; |
85 | QSslConfiguration sslConfiguration; |
86 | #ifndef OPENSSL_NO_NEXTPROTONEG |
87 | QByteArray m_supportedNPNVersions; |
88 | NPNContext m_npnContext; |
89 | #endif // !OPENSSL_NO_NEXTPROTONEG |
90 | }; |
91 | |
92 | #endif // QT_NO_SSL |
93 | |
94 | QT_END_NAMESPACE |
95 | |
96 | #endif // QSSLCONTEXT_OPENSSL_P_H |
97 | |