11#include "QXmppGlobal.h"
12#include "QXmppLogger.h"
13#include "QXmppNonza.h"
14#include "QXmppStreamManagement_p.h"
18#include <QCryptographicHash>
24class QXmlStreamWriter;
25class QXmppSaslServerPrivate;
27namespace QXmpp::Private {
44namespace QXmpp::Private {
48enum class ErrorCondition {
62QString errorConditionToString(ErrorCondition);
63std::optional<ErrorCondition> errorConditionFromString(QStringView);
66 static std::optional<Auth> fromDom(
const QDomElement &);
67 void toXml(QXmlStreamWriter *writer)
const;
74 static std::optional<Challenge> fromDom(
const QDomElement &);
75 void toXml(QXmlStreamWriter *writer)
const;
81 static std::optional<Failure> fromDom(
const QDomElement &);
82 void toXml(QXmlStreamWriter *writer)
const;
84 std::optional<ErrorCondition> condition;
89 static std::optional<Response> fromDom(
const QDomElement &);
90 void toXml(QXmlStreamWriter *writer)
const;
96 static std::optional<Success> fromDom(
const QDomElement &);
97 void toXml(QXmlStreamWriter *writer)
const;
103 static std::optional<Bind2Feature> fromDom(
const QDomElement &);
104 void toXml(QXmlStreamWriter *)
const;
106 std::vector<QString> features;
110 static std::optional<Bind2Request> fromDom(
const QDomElement &);
111 void toXml(QXmlStreamWriter *)
const;
115 bool csiInactive =
false;
116 bool carbonsEnable =
false;
117 std::optional<SmEnable> smEnable;
121 static std::optional<Bind2Bound> fromDom(
const QDomElement &);
122 void toXml(QXmlStreamWriter *)
const;
125 std::optional<SmFailed> smFailed;
126 std::optional<SmEnabled> smEnabled;
130 static std::optional<FastFeature> fromDom(
const QDomElement &);
131 void toXml(QXmlStreamWriter *)
const;
133 std::vector<QString> mechanisms;
134 bool tls0rtt =
false;
137struct FastTokenRequest {
138 static std::optional<FastTokenRequest> fromDom(
const QDomElement &);
139 void toXml(QXmlStreamWriter *)
const;
145 static std::optional<FastToken> fromDom(
const QDomElement &);
146 void toXml(QXmlStreamWriter *)
const;
153 static std::optional<FastRequest> fromDom(
const QDomElement &);
154 void toXml(QXmlStreamWriter *)
const;
156 std::optional<uint64_t> count;
157 bool invalidate =
false;
162struct StreamFeature {
163 static std::optional<StreamFeature> fromDom(
const QDomElement &);
164 void toXml(QXmlStreamWriter *)
const;
166 QList<QString> mechanisms;
167 std::optional<Bind2Feature> bind2Feature;
168 std::optional<FastFeature> fast;
169 bool streamResumptionAvailable =
false;
173 static std::optional<UserAgent> fromDom(
const QDomElement &);
174 void toXml(QXmlStreamWriter *)
const;
182 static std::optional<Authenticate> fromDom(
const QDomElement &);
183 void toXml(QXmlStreamWriter *)
const;
186 QByteArray initialResponse;
187 std::optional<UserAgent> userAgent;
188 std::optional<Bind2Request> bindRequest;
189 std::optional<SmResume> smResume;
190 std::optional<FastTokenRequest> tokenRequest;
191 std::optional<FastRequest> fast;
195 static std::optional<Challenge> fromDom(
const QDomElement &);
196 void toXml(QXmlStreamWriter *)
const;
202 static std::optional<Response> fromDom(
const QDomElement &);
203 void toXml(QXmlStreamWriter *)
const;
209 static std::optional<Success> fromDom(
const QDomElement &);
210 void toXml(QXmlStreamWriter *)
const;
212 std::optional<QByteArray> additionalData;
213 QString authorizationIdentifier;
215 std::optional<Bind2Bound> bound;
216 std::optional<SmResumed> smResumed;
217 std::optional<SmFailed> smFailed;
218 std::optional<FastToken> token;
222 static std::optional<Failure> fromDom(
const QDomElement &);
223 void toXml(QXmlStreamWriter *)
const;
225 Sasl::ErrorCondition condition;
231 static std::optional<Continue> fromDom(
const QDomElement &);
232 void toXml(QXmlStreamWriter *)
const;
234 QByteArray additionalData;
235 std::vector<QString> tasks;
240 static std::optional<Abort> fromDom(
const QDomElement &);
241 void toXml(QXmlStreamWriter *)
const;
248enum class IanaHashAlgorithm {
256#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
263QCryptographicHash::Algorithm ianaHashAlgorithmToQt(IanaHashAlgorithm alg);
269struct SaslScramMechanism {
270 static std::optional<SaslScramMechanism> fromString(QStringView str);
271 QString toString()
const;
273 QCryptographicHash::Algorithm qtAlgorithm()
const;
275 auto operator<=>(
const SaslScramMechanism &)
const =
default;
285struct SaslHtMechanism {
286 static std::optional<SaslHtMechanism> fromString(QStringView);
287 QString toString()
const;
289 auto operator<=>(
const SaslHtMechanism &)
const =
default;
291 enum ChannelBindingType {
298 IanaHashAlgorithm hashAlgorithm;
299 ChannelBindingType channelBindingType;
302struct SaslDigestMd5Mechanism {
303 auto operator<=>(
const SaslDigestMd5Mechanism &)
const =
default;
305struct SaslPlainMechanism {
306 auto operator<=>(
const SaslPlainMechanism &)
const =
default;
308struct SaslAnonymousMechanism {
309 auto operator<=>(
const SaslAnonymousMechanism &)
const =
default;
311struct SaslXFacebookMechanism {
312 auto operator<=>(
const SaslXFacebookMechanism &)
const =
default;
314struct SaslXWindowsLiveMechanism {
315 auto operator<=>(
const SaslXWindowsLiveMechanism &)
const =
default;
317struct SaslXGoogleMechanism {
318 auto operator<=>(
const SaslXGoogleMechanism &)
const =
default;
323 : std::variant<SaslXGoogleMechanism,
324 SaslXWindowsLiveMechanism,
325 SaslXFacebookMechanism,
326 SaslAnonymousMechanism,
328 SaslDigestMd5Mechanism,
331 static std::optional<SaslMechanism> fromString(QStringView str);
332 QString toString()
const;
335inline QDebug operator<<(QDebug dbg, SaslMechanism mechanism) {
return dbg << mechanism.toString(); }
342 static std::optional<HtToken> fromXml(QXmlStreamReader &);
343 void toXml(QXmlStreamWriter &)
const;
344 bool operator==(
const HtToken &other)
const =
default;
346 SaslHtMechanism mechanism;
353 std::optional<HtToken> htToken;
356 QString facebookAccessToken;
357 QString facebookAppId;
359 QString googleAccessToken;
361 QString windowsLiveAccessToken;
366class QXMPP_AUTOTEST_EXPORT QXmppSaslClient :
public QXmppLoggable
372 QString host()
const {
return m_host; }
373 void setHost(
const QString &host) { m_host = host; }
375 QString serviceType()
const {
return m_serviceType; }
376 void setServiceType(
const QString &serviceType) { m_serviceType = serviceType; }
378 QString username()
const {
return m_username; }
379 void setUsername(
const QString &username) { m_username = username; }
381 virtual void setCredentials(
const QXmpp::Private::Credentials &) = 0;
382 virtual QXmpp::Private::SaslMechanism mechanism()
const = 0;
383 virtual std::optional<QByteArray> respond(
const QByteArray &challenge) = 0;
385 static bool isMechanismAvailable(QXmpp::Private::SaslMechanism,
const QXmpp::Private::Credentials &);
386 static std::unique_ptr<QXmppSaslClient> create(
const QString &mechanism, QObject *parent =
nullptr);
387 static std::unique_ptr<QXmppSaslClient> create(QXmpp::Private::SaslMechanism mechanism, QObject *parent =
nullptr);
390 friend class QXmpp::Private::SaslManager;
393 QString m_serviceType;
398class QXMPP_AUTOTEST_EXPORT QXmppSaslServer :
public QXmppLoggable
409 QXmppSaslServer(QObject *parent =
nullptr);
410 ~QXmppSaslServer()
override;
412 QString username()
const;
413 void setUsername(
const QString &username);
415 QString password()
const;
416 void setPassword(
const QString &password);
418 QByteArray passwordDigest()
const;
419 void setPasswordDigest(
const QByteArray &digest);
421 QString realm()
const;
422 void setRealm(
const QString &realm);
424 virtual QString mechanism()
const = 0;
425 virtual Response respond(
const QByteArray &challenge, QByteArray &response) = 0;
427 static std::unique_ptr<QXmppSaslServer> create(
const QString &mechanism, QObject *parent =
nullptr);
430 const std::unique_ptr<QXmppSaslServerPrivate> d;
433class QXMPP_AUTOTEST_EXPORT QXmppSaslDigestMd5
436 static void setNonce(
const QByteArray &nonce);
439 static QMap<QByteArray, QByteArray> parseMessage(
const QByteArray &ba);
440 static QByteArray serializeMessage(
const QMap<QByteArray, QByteArray> &map);
443class QXmppSaslClientAnonymous :
public QXmppSaslClient
447 QXmppSaslClientAnonymous(QObject *parent =
nullptr);
448 void setCredentials(
const QXmpp::Private::Credentials &)
override { }
449 QXmpp::Private::SaslMechanism mechanism()
const override {
return { QXmpp::Private::SaslAnonymousMechanism() }; }
450 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
456class QXmppSaslClientDigestMd5 :
public QXmppSaslClient
460 QXmppSaslClientDigestMd5(QObject *parent =
nullptr);
461 void setCredentials(
const QXmpp::Private::Credentials &)
override;
462 QXmpp::Private::SaslMechanism mechanism()
const override {
return { QXmpp::Private::SaslDigestMd5Mechanism() }; }
463 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
474class QXmppSaslClientFacebook :
public QXmppSaslClient
478 QXmppSaslClientFacebook(QObject *parent =
nullptr);
479 void setCredentials(
const QXmpp::Private::Credentials &)
override;
480 QXmpp::Private::SaslMechanism mechanism()
const override {
return { QXmpp::Private::SaslXFacebookMechanism() }; }
481 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
485 QString m_accessToken;
489class QXmppSaslClientGoogle :
public QXmppSaslClient
493 QXmppSaslClientGoogle(QObject *parent =
nullptr);
494 void setCredentials(
const QXmpp::Private::Credentials &)
override;
495 QXmpp::Private::SaslMechanism mechanism()
const override {
return { QXmpp::Private::SaslXGoogleMechanism() }; }
496 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
499 QString m_accessToken;
503class QXmppSaslClientPlain :
public QXmppSaslClient
507 QXmppSaslClientPlain(QObject *parent =
nullptr);
508 void setCredentials(
const QXmpp::Private::Credentials &)
override;
509 QXmpp::Private::SaslMechanism mechanism()
const override {
return { QXmpp::Private::SaslPlainMechanism() }; }
510 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
517class QXmppSaslClientScram :
public QXmppSaslClient
521 QXmppSaslClientScram(QXmpp::Private::SaslScramMechanism mechanism, QObject *parent =
nullptr);
522 void setCredentials(
const QXmpp::Private::Credentials &)
override;
523 QXmpp::Private::SaslMechanism mechanism()
const override {
return { m_mechanism }; }
524 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
527 QXmpp::Private::SaslScramMechanism m_mechanism;
531 QByteArray m_gs2Header;
532 QByteArray m_clientFirstMessageBare;
533 QByteArray m_serverSignature;
537class QXmppSaslClientHt :
public QXmppSaslClient
540 using HtMechanism = QXmpp::Private::SaslHtMechanism;
543 QXmppSaslClientHt(HtMechanism mechanism, QObject *parent)
544 : QXmppSaslClient(parent), m_mechanism(mechanism)
548 void setCredentials(
const QXmpp::Private::Credentials &credentials)
override { m_token = credentials.htToken; }
549 QXmpp::Private::SaslMechanism mechanism()
const override {
return { m_mechanism }; }
550 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
553 std::optional<QXmpp::Private::HtToken> m_token;
554 HtMechanism m_mechanism;
558class QXmppSaslClientWindowsLive :
public QXmppSaslClient
562 QXmppSaslClientWindowsLive(QObject *parent =
nullptr);
563 void setCredentials(
const QXmpp::Private::Credentials &)
override;
564 QXmpp::Private::SaslMechanism mechanism()
const override {
return { QXmpp::Private::SaslXWindowsLiveMechanism() }; }
565 std::optional<QByteArray> respond(
const QByteArray &challenge)
override;
568 QString m_accessToken;
572class QXmppSaslServerAnonymous :
public QXmppSaslServer
576 QXmppSaslServerAnonymous(QObject *parent =
nullptr);
577 QString mechanism()
const override;
579 Response respond(
const QByteArray &challenge, QByteArray &response)
override;
585class QXmppSaslServerDigestMd5 :
public QXmppSaslServer
589 QXmppSaslServerDigestMd5(QObject *parent =
nullptr);
590 QString mechanism()
const override;
592 Response respond(
const QByteArray &challenge, QByteArray &response)
override;
602class QXmppSaslServerPlain :
public QXmppSaslServer
606 QXmppSaslServerPlain(QObject *parent =
nullptr);
607 QString mechanism()
const override;
609 Response respond(
const QByteArray &challenge, QByteArray &response)
override;
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110