Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QTLS_SCHANNEL_P_H
5#define QTLS_SCHANNEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19
21
23
25
26#include <QtNetwork/private/qsslsocket_p.h>
27
28#define SECURITY_WIN32
29#define SCHANNEL_USE_BLACKLISTS 1
30#include <winternl.h> // needed for UNICODE defines
31#include <security.h>
32#include <schnlsp.h>
33#undef SCHANNEL_USE_BLACKLISTS
34#undef SECURITY_WIN32
35
37
38namespace QTlsPrivate {
39
40class TlsCryptographSchannel final : public TlsCryptograph
41{
42 Q_DISABLE_COPY_MOVE(TlsCryptographSchannel)
43public:
46
47 void init(QSslSocket *q, QSslSocketPrivate *d) override;
48
49 void startClientEncryption() override;
50 void startServerEncryption() override;
51 void transmit() override;
52 void disconnectFromHost() override;
53 void disconnected() override;
54 QSslCipher sessionCipher() const override;
55 QSsl::SslProtocol sessionProtocol() const override;
56 void continueHandshake() override;
57 QList<QSslError> tlsErrors() const override;
58
59private:
60 enum class SchannelState {
61 InitializeHandshake, // create and transmit context (client)/accept context (server)
62 PerformHandshake, // get token back, process it
63 VerifyHandshake, // Verify that things are OK
64 Done, // Connection encrypted!
65 Renegotiate // Renegotiating!
66 } schannelState = SchannelState::InitializeHandshake;
67
68 void reset();
69 bool acquireCredentialsHandle();
70 ULONG getContextRequirements();
71 bool createContext(); // for clients
72 bool acceptContext(); // for server
73 bool performHandshake();
74 bool verifyHandshake();
75 bool renegotiate();
76
77 bool sendToken(void *token, unsigned long tokenLength, bool emitError = true);
78 QString targetName() const;
79
80 bool checkSslErrors();
81 void deallocateContext();
82 void freeCredentialsHandle();
83 void closeCertificateStores();
84 void sendShutdown();
85
86 void initializeCertificateStores();
87 bool verifyCertContext(CERT_CONTEXT *certContext);
88
89 bool rootCertOnDemandLoadingAllowed();
90
91 bool hasUndecryptedData() const override { return intermediateBuffer.size() > 0; }
92
93 QSslSocket *q = nullptr;
94 QSslSocketPrivate *d = nullptr;
95
96 SecPkgContext_CipherInfo cipherInfo = {};
97 SecPkgContext_ConnectionInfo connectionInfo = {};
98 SecPkgContext_StreamSizes streamSizes = {};
99
100 CredHandle credentialHandle; // Initialized in ctor
101 CtxtHandle contextHandle; // Initialized in ctor
102
103 QByteArray intermediateBuffer; // data which is left-over or incomplete
104
105 QHCertStorePointer localCertificateStore = nullptr;
106 QHCertStorePointer peerCertificateStore = nullptr;
107 QHCertStorePointer caCertificateStore = nullptr;
108
109 const CERT_CONTEXT *localCertContext = nullptr;
110
111 ULONG contextAttributes = 0;
112 qint64 missingData = 0;
113
114 bool renegotiating = false;
115 bool shutdown = false;
116 QList<QSslError> sslErrors;
117};
118
119} // namespace QTlsPrivate
120
122
123#endif // QTLS_SCHANNEL_P_H
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
The QSslCipher class represents an SSL cryptographic cipher.
Definition qsslcipher.h:22
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition qsslsocket.h:29
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
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
Token token
Definition keywords.cpp:444
SslProtocol
Describes the protocol of the cipher.
Definition qssl.h:50
Combined button and popup list for selecting options.
Namespace containing onternal types that TLS backends implement.
GLboolean reset
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define QT_REQUIRE_CONFIG(feature)
long long qint64
Definition qtypes.h:60
std::unique_ptr< void, QHCertStoreDeleter > QHCertStorePointer
Definition qwincrypt_p.h:41