Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtls_schannel_p.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QTLS_SCHANNEL_P_H
6#define QTLS_SCHANNEL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20
22
23#include "../shared/qwincrypt_p.h"
24
26
27#include <QtNetwork/private/qsslsocket_p.h>
28
29#define SECURITY_WIN32
30#define SCHANNEL_USE_BLACKLISTS 1
31#include <winternl.h> // needed for UNICODE defines
32#include <security.h>
33#include <schnlsp.h>
34#undef SCHANNEL_USE_BLACKLISTS
35#undef SECURITY_WIN32
36
37QT_BEGIN_NAMESPACE
38
39namespace QTlsPrivate {
40
42{
44public:
47
48 void init(QSslSocket *q, QSslSocketPrivate *d) override;
49
52 void transmit() override;
55 QSslCipher sessionCipher() const override;
56 QSsl::SslProtocol sessionProtocol() const override;
58 QList<QSslError> tlsErrors() const override;
59
60private:
61 enum class SchannelState {
62 InitializeHandshake, // create and transmit context (client)/accept context (server)
63 PerformHandshake, // get token back, process it
64 VerifyHandshake, // Verify that things are OK
65 Done, // Connection encrypted!
66 Renegotiate // Renegotiating!
67 } schannelState = SchannelState::InitializeHandshake;
68
69 // Close to std::optional<QBArray>, but need to also cover the case where
70 // we encrypted some data, but encountered an error later.
71 struct MessageBufferResult {
72 bool ok = false;
73 QByteArray messageBuffer;
74 };
75 MessageBufferResult getNextEncryptedMessage();
76
77 void reset();
78 bool acquireCredentialsHandle();
79 ULONG getContextRequirements();
80 bool createContext(); // for clients
81 bool acceptContext(); // for server
82 bool performHandshake();
83 bool verifyHandshake();
84 bool renegotiate();
85
86 bool sendToken(void *token, unsigned long tokenLength, bool emitError = true);
87 QString targetName() const;
88
89 bool checkSslErrors();
90 void deallocateContext();
91 void freeCredentialsHandle();
92 void closeCertificateStores();
93 void sendShutdown();
94
95 void initializeCertificateStores();
96 bool verifyCertContext(CERT_CONTEXT *certContext);
97
98 bool rootCertOnDemandLoadingAllowed();
99
100 bool hasUndecryptedData() const override { return intermediateBuffer.size() > 0; }
101
102 QSslSocket *q = nullptr;
103 QSslSocketPrivate *d = nullptr;
104
105 SecPkgContext_CipherInfo cipherInfo = {};
106 SecPkgContext_ConnectionInfo connectionInfo = {};
107 SecPkgContext_StreamSizes streamSizes = {};
108
109 CredHandle credentialHandle; // Initialized in ctor
110 CtxtHandle contextHandle; // Initialized in ctor
111
112 QByteArray intermediateBuffer; // data which is left-over or incomplete
113
114 QHCertStorePointer localCertificateStore = nullptr;
115 QHCertStorePointer peerCertificateStore = nullptr;
116 QHCertStorePointer caCertificateStore = nullptr;
117
118 ULONG contextAttributes = 0;
119 qint64 missingData = 0;
120
121 bool renegotiating = false;
122 bool shutdown = false;
123 QList<QSslError> sslErrors;
124};
125
126} // namespace QTlsPrivate
127
128QT_END_NAMESPACE
129
130#endif // QTLS_SCHANNEL_P_H
void init(QSslSocket *q, QSslSocketPrivate *d) override
QSsl::SslProtocol sessionProtocol() const override
bool hasUndecryptedData() const override
QSslCipher sessionCipher() const override
QList< QSslError > tlsErrors() const override
QByteArray derFromPem(const QByteArray &pem, QMap< QByteArray, QByteArray > *headers) const override
bool isPkcs8() const override
QByteArray toPem(const QByteArray &passPhrase) const override
int length() const override
void decodePem(KeyType type, KeyAlgorithm algorithm, const QByteArray &pem, const QByteArray &passPhrase, bool deepClear) override
void fromHandle(Qt::HANDLE opaque, KeyType expectedType) override
Qt::HANDLE handle() const override
void clear(bool deep) override
void decodeDer(KeyType type, KeyAlgorithm algorithm, const QByteArray &der, const QByteArray &passPhrase, bool deepClear) override
QByteArray decrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
QByteArray encrypt(Cipher cipher, const QByteArray &data, const QByteArray &key, const QByteArray &iv) const override
TlsKey * publicKey() const override
Qt::HANDLE handle() const override
static bool importPkcs12(QIODevice *device, QSslKey *key, QSslCertificate *cert, QList< QSslCertificate > *caCertificates, const QByteArray &passPhrase)
Q_DISABLE_COPY_MOVE(X509CertificateSchannel)
static QSslCertificate QSslCertificate_from_CERT_CONTEXT(const CERT_CONTEXT *certificateContext)
Namespace containing onternal types that TLS backends implement.
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED std::array< SchannelCipherInfo, 44 > schannelCipherInfo
QList< QSslCipher > defaultCiphers()
UNICODE_STRING cbcChainingMode
QList< CRYPTO_SETTINGS > cryptoSettingsForCiphers(const QList< QSslCipher > &ciphers)
bool containsTls13Cipher(const QList< QSslCipher > &ciphers)
UNICODE_STRING gcmChainingMode
QList< QSslCipher > ciphersByName(QStringView schannelSuiteName)
static void attachPrivateKeyToCertificate(const QSslCertificate &certificate, const QSslKey &privateKey)
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
Q_GLOBAL_STATIC(QReadWriteLock, g_updateMutex)
QT_REQUIRE_CONFIG(thread)
#define SP_PROT_TLS1_0_SERVER
#define SP_PROT_TLS1_1_SERVER
#define SP_PROT_TLS1_2_SERVER
#define BCRYPT_ECDSA_ALGORITHM
#define SP_PROT_TLS1_2
#define SP_PROT_TLS1_3_SERVER
#define MAP_PROTOCOL(sp_protocol, q_protocol)
#define SP_PROT_TLS1_0
#define SP_PROT_TLS1_3
#define CHECK_STATUS(status)
#define CHECK_ATTRIBUTE(attributeName)
#define DEBUG_WARN(message)
QByteArray _q_makePkcs12(const QList< QSslCertificate > &certs, const QSslKey &key, const QString &passPhrase)
#define SP_PROT_TLS1_1_CLIENT
#define SP_PROT_TLS1_SERVER
QAsn1Element _q_PKCS12_key(const QSslKey &key)
#define BCRYPT_ECDH_ALGORITHM
#define SP_PROT_TLS1_3_CLIENT
#define SP_PROT_TLS1_1
#define SEC_E_APPLICATION_PROTOCOL_MISMATCH
#define SP_PROT_TLS1_CLIENT
#define SP_PROT_TLS1_0_CLIENT
#define SECBUFFER_ALERT
#define SP_PROT_TLS1_2_CLIENT
std::unique_ptr< void, QHCertStoreDeleter > QHCertStorePointer
Definition qwincrypt_p.h:42
QList< QSsl::SslProtocol > protocols