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
qauthenticator_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QAUTHENTICATOR_P_H
6#define QAUTHENTICATOR_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#include <qhash.h>
21#include <qbytearray.h>
22#include <qstring.h>
23#include <qauthenticator.h>
24#include <qvariant.h>
25
26#include <memory>
27
29
30class QHttpResponseHeader;
31class QHttpHeaders;
32#if QT_CONFIG(sspi) // SSPI
33class QSSPIWindowsHandles;
34#elif QT_CONFIG(gssapi) // GSSAPI
35class QGssApiHandles;
36#endif
37
38class Q_NETWORK_EXPORT QAuthenticatorPrivate
39{
40public:
41 enum Method { None, Basic, Negotiate, Ntlm, DigestMd5, };
42 QAuthenticatorPrivate();
43
44 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QAuthenticatorPrivate)
45 void swap(QAuthenticatorPrivate &other) noexcept
46 {
47 user.swap(other.user);
48 extractedUser.swap(other.extractedUser);
49 password.swap(other.password);
50 options.swap(other.options);
51 std::swap(method, other.method);
52 realm.swap(other.realm);
53 challenge.swap(other.challenge);
54#if QT_CONFIG(sspi) // SSPI
55 sspiWindowsHandles.swap(other.sspiWindowsHandles);
56#elif QT_CONFIG(gssapi) // GSSAPI
57 gssApiHandles.swap(other.gssApiHandles);
58#endif
59 std::swap(hasFailed, other.hasFailed);
60 std::swap(phase, other.phase);
61 cnonce.swap(other.cnonce);
62 std::swap(nonceCount, other.nonceCount);
63 workstation.swap(other.workstation);
64 userDomain.swap(other.userDomain);
65 }
66
67 ~QAuthenticatorPrivate();
68
69 QString user;
70 QString extractedUser;
71 QString password;
72 QVariantHash options;
73 Method method;
74 QString realm;
75 QByteArray challenge;
76#if QT_CONFIG(sspi) // SSPI
77 std::unique_ptr<QSSPIWindowsHandles> sspiWindowsHandles;
78#elif QT_CONFIG(gssapi) // GSSAPI
79 std::unique_ptr<QGssApiHandles> gssApiHandles;
80#endif
81 bool hasFailed; //credentials have been tried but rejected by server.
82
83 enum Phase {
84 Start,
85 Phase1,
86 Phase2,
87 Done,
88 Invalid
89 };
90 Phase phase;
91
92 // digest specific
93 QByteArray cnonce;
94 int nonceCount;
95
96 // ntlm specific
97 QString workstation;
98 QString userDomain;
99
100 QByteArray calculateResponse(QByteArrayView method, QByteArrayView path, QStringView host);
101
102 inline static QAuthenticatorPrivate *getPrivate(QAuthenticator &auth) { return auth.d; }
103 inline static const QAuthenticatorPrivate *getPrivate(const QAuthenticator &auth) { return auth.d; }
104
105 QByteArray digestMd5Response(QByteArrayView challenge, QByteArrayView method,
106 QByteArrayView path);
107 static QHash<QByteArray, QByteArray>
108 parseDigestAuthenticationChallenge(QByteArrayView challenge);
109
110 void parseHttpResponse(const QHttpHeaders &headers, bool isProxy, QStringView host);
111 void updateCredentials();
112
113 static bool isMethodSupported(QByteArrayView method);
114};
115
116
117QT_END_NAMESPACE
118
119#endif
unsigned char challenge[8]
static QByteArray clientChallenge(const QAuthenticatorPrivate *ctx)
const quint8 respversion
static QByteArray qNtlmPhase1()
#define NTLMSSP_NEGOTIATE_NTLM2
#define NTLMSSP_NEGOTIATE_TARGET_INFO
static QByteArray qStringAsUcs2Le(const QString &src)
static QByteArray qEncodeLmv2Response(const QAuthenticatorPrivate *ctx, const QNtlmPhase2Block &ch, QNtlmPhase3Block *phase3)
static bool verifyDigestMD5(QByteArrayView value)
static bool containsAuth(QByteArrayView data)
static int qEncodeNtlmString(QNtlmBuffer &buf, int offset, const QString &s, bool unicode)
static QByteArray qNtlmPhase3(QAuthenticatorPrivate *ctx, const QByteArray &phase2data)
QByteArray qEncodeHmacMd5(QByteArray &key, QByteArrayView message)
#define NTLMSSP_NEGOTIATE_OEM
static QByteArray qEncodeNtlmv2Response(const QAuthenticatorPrivate *ctx, const QNtlmPhase2Block &ch, QNtlmPhase3Block *phase3)
static QByteArray digestMd5ResponseHelper(QByteArrayView alg, QByteArrayView userName, QByteArrayView realm, QByteArrayView password, QByteArrayView nonce, QByteArrayView nonceCount, QByteArrayView cNonce, QByteArrayView qop, QByteArrayView method, QByteArrayView digestUri, QByteArrayView hEntity)
static QDataStream & operator>>(QDataStream &s, QNtlmBuffer &b)
static QByteArray qCreatev2Hash(const QAuthenticatorPrivate *ctx, QNtlmPhase3Block *phase3)
static void qStreamNtlmBuffer(QDataStream &ds, const QByteArray &s)
#define NTLMSSP_REQUEST_TARGET
static QString qStringFromUcs2Le(QByteArray src)
static void qStreamNtlmString(QDataStream &ds, const QString &s, bool unicode)
#define NTLMSSP_NEGOTIATE_NTLM
static QByteArray qExtractServerTime(const QByteArray &targetInfoBuff)
#define NTLMSSP_NEGOTIATE_UNICODE
static int qEncodeNtlmBuffer(QNtlmBuffer &buf, int offset, const QByteArray &s)
const quint8 hirespversion
const int blockSize
#define AVTIMESTAMP
#define NTLMSSP_NEGOTIATE_ALWAYS_SIGN
static bool qNtlmDecodePhase2(const QByteArray &data, QNtlmPhase2Block &ch)
#define Q_LOGGING_CATEGORY(name,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)