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