QXmpp: QXmppSaslManager_p.h Source File

QXmpp Version: 1.14.3

Loading...
Searching...
No Matches
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
17class QXmppConfiguration;
18class QXmppStreamFeatures;
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 static constexpr QStringView TaskName = u"SASL 1 authentication";
31
32 explicit SaslManager(SendDataInterface *socket) : m_socket(socket) { }
33
34 QXmppTask<AuthResult> authenticate(const QXmppConfiguration &config, const QList<QString> &availableMechanisms, QXmppLoggable *parent);
35 HandleElementResult handleElement(const QDomElement &el);
36
37private:
38 SendDataInterface *m_socket;
39 std::unique_ptr<QXmppSaslClient> m_saslClient;
40 std::optional<QXmppPromise<AuthResult>> m_promise;
41};
42
43// Authentication using SASL 2
44class Sasl2Manager
45{
46public:
47 using AuthError = std::pair<QString, AuthenticationError>;
48 using AuthResult = std::variant<Sasl2::Success, AuthError>;
49 static constexpr QStringView TaskName = u"SASL 2 authentication";
50
51 explicit Sasl2Manager(SendDataInterface *socket) : m_socket(socket) { }
52
53 QXmppTask<AuthResult> authenticate(Sasl2::Authenticate &&authenticate, const QXmppConfiguration &config, const Sasl2::StreamFeature &feature, QXmppLoggable *loggable);
54 HandleElementResult handleElement(const QDomElement &);
55
56private:
57 struct State {
58 std::unique_ptr<QXmppSaslClient> sasl;
59 QXmppPromise<AuthResult> p;
60 std::optional<Sasl2::Continue> unsupportedContinue;
61 };
62
63 SendDataInterface *m_socket;
64 std::optional<State> m_state;
65};
66
67// Authentication token management
68class FastTokenManager
69{
70public:
71 explicit FastTokenManager(QXmppConfiguration &config);
72
73 static bool isFastEnabled(const QXmppConfiguration &);
74 bool hasToken() const;
75 void onSasl2Authenticate(Sasl2::Authenticate &auth, const Sasl2::StreamFeature &feature);
76 void onSasl2Success(const Sasl2::Success &success);
77 bool tokenChanged() const { return m_tokenChanged; }
78
79private:
80 QXmppConfiguration &config;
81 std::optional<SaslHtMechanism> requestedMechanism;
82 bool m_tokenChanged = false;
83};
84
85} // namespace QXmpp::Private
86
87#endif // QXMPPSASLMANAGER_P_H
QXmppConfiguration
The QXmppConfiguration class holds configuration options.
Definition QXmppConfiguration.h:37
QXmppStreamFeatures
The QXmppStreamFeatures class represents the features returned by an XMPP server or client.
Definition QXmppStreamFeatures.h:23