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
4#ifndef QAUTHENTICATOR_P_H
5#define QAUTHENTICATOR_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#include <qhash.h>
20#include <qbytearray.h>
21#include <qscopedpointer.h>
22#include <qstring.h>
23#include <qauthenticator.h>
24#include <qvariant.h>
25
26QT_BEGIN_NAMESPACE
27
28class QHttpResponseHeader;
29#if QT_CONFIG(sspi) // SSPI
30class QSSPIWindowsHandles;
31#elif QT_CONFIG(gssapi) // GSSAPI
32class QGssApiHandles;
33#endif
34
35class Q_NETWORK_EXPORT QAuthenticatorPrivate
36{
37public:
38 enum Method { None, Basic, Negotiate, Ntlm, DigestMd5, };
39 QAuthenticatorPrivate();
40 ~QAuthenticatorPrivate();
41
42 QString user;
43 QString extractedUser;
44 QString password;
45 QVariantHash options;
46 Method method;
47 QString realm;
48 QByteArray challenge;
49#if QT_CONFIG(sspi) // SSPI
50 QScopedPointer<QSSPIWindowsHandles> sspiWindowsHandles;
51#elif QT_CONFIG(gssapi) // GSSAPI
52 QScopedPointer<QGssApiHandles> gssApiHandles;
53#endif
54 bool hasFailed; //credentials have been tried but rejected by server.
55
56 enum Phase {
57 Start,
58 Phase1,
59 Phase2,
60 Done,
61 Invalid
62 };
63 Phase phase;
64
65 // digest specific
66 QByteArray cnonce;
67 int nonceCount;
68
69 // ntlm specific
70 QString workstation;
71 QString userDomain;
72
73 QByteArray calculateResponse(QByteArrayView method, QByteArrayView path, QStringView host);
74
75 inline static QAuthenticatorPrivate *getPrivate(QAuthenticator &auth) { return auth.d; }
76 inline static const QAuthenticatorPrivate *getPrivate(const QAuthenticator &auth) { return auth.d; }
77
78 QByteArray digestMd5Response(QByteArrayView challenge, QByteArrayView method,
79 QByteArrayView path);
80 static QHash<QByteArray, QByteArray>
81 parseDigestAuthenticationChallenge(QByteArrayView challenge);
82
83 void parseHttpResponse(const QList<QPair<QByteArray, QByteArray>> &, bool isProxy,
84 QStringView host);
85 void updateCredentials();
86
87 static bool isMethodSupported(QByteArrayView method);
88};
89
90
91QT_END_NAMESPACE
92
93#endif
94

source code of qtbase/src/network/kernel/qauthenticator_p.h