QXmpp Version: 1.10.0
QXmppSaslManager_p.h
1// SPDX-FileCopyrightText: 2012 Jeremy Lainé <jeremy.laine@m4x.org>
2// SPDX-FileCopyrightText: 2024 Linus Jahn <lnj@kaidan.im>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
6#ifndef QXMPPSASLMANAGER_P_H
7#define QXMPPSASLMANAGER_P_H
8
9#include "QXmppAuthenticationError.h"
10#include "QXmppOutgoingClient.h"
11#include "QXmppPromise.h"
12#include "QXmppSasl_p.h"
13#include "QXmppTask.h"
14
15#include <optional>
16
19
20namespace QXmpp::Private {
21
22class SendDataInterface;
23
24// Authentication using SASL
25class SaslManager
26{
27public:
28 using AuthError = std::pair<QString, AuthenticationError>;
29 using AuthResult = std::variant<Success, AuthError>;
30
31 explicit SaslManager(SendDataInterface *socket) : m_socket(socket) { }
32
33 QXmppTask<AuthResult> authenticate(const QXmppConfiguration &config, const QList<QString> &availableMechanisms, QXmppLoggable *parent);
34 HandleElementResult handleElement(const QDomElement &el);
35
36private:
37 SendDataInterface *m_socket;
38 std::unique_ptr<QXmppSaslClient> m_saslClient;
39 std::optional<QXmppPromise<AuthResult>> m_promise;
40};
41
42// Authentication using SASL 2
43class Sasl2Manager
44{
45public:
46 using AuthError = std::pair<QString, AuthenticationError>;
47 using AuthResult = std::variant<Sasl2::Success, AuthError>;
48
49 explicit Sasl2Manager(SendDataInterface *socket) : m_socket(socket) { }
50
51 QXmppTask<AuthResult> authenticate(Sasl2::Authenticate &&authenticate, const QXmppConfiguration &config, const Sasl2::StreamFeature &feature, QXmppLoggable *loggable);
52 HandleElementResult handleElement(const QDomElement &);
53
54private:
55 struct State {
56 std::unique_ptr<QXmppSaslClient> sasl;
58 std::optional<Sasl2::Continue> unsupportedContinue;
59 };
60
61 SendDataInterface *m_socket;
62 std::optional<State> m_state;
63};
64
65// Authentication token management
66class FastTokenManager
67{
68public:
69 explicit FastTokenManager(QXmppConfiguration &config);
70
71 static bool isFastEnabled(const QXmppConfiguration &);
72 bool hasToken() const;
73 void onSasl2Authenticate(Sasl2::Authenticate &auth, const Sasl2::StreamFeature &feature);
74 void onSasl2Success(const Sasl2::Success &success);
75 bool tokenChanged() const { return m_tokenChanged; }
76
77private:
78 QXmppConfiguration &config;
79 std::optional<SaslHtMechanism> requestedMechanism;
80 bool m_tokenChanged = false;
81};
82
83} // namespace QXmpp::Private
84
85#endif // QXMPPSASLMANAGER_P_H
The QXmppConfiguration class holds configuration options.
Definition: QXmppConfiguration.h:37
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110
The QXmppStreamFeatures class represents the features returned by an XMPP server or client.
Definition: QXmppStreamFeatures.h:23
Definition: QXmppTask.h:62