QXmppSasl_p.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Copyright (C) 2008-2012 The QXmpp developers
  3. *
  4. * Authors:
  5. * Manjeet Dahiya
  6. * Jeremy Lainé
  7. *
  8. * Source:
  9. * http://code.google.com/p/qxmpp
  10. *
  11. * This file is a part of QXmpp library.
  12. *
  13. * This library is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU Lesser General Public
  15. * License as published by the Free Software Foundation; either
  16. * version 2.1 of the License, or (at your option) any later version.
  17. *
  18. * This library is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. * Lesser General Public License for more details.
  22. *
  23. */
  24. #ifndef QXMPPSASL_P_H
  25. #define QXMPPSASL_P_H
  26. #include <QByteArray>
  27. #include <QMap>
  28. #include "QXmppGlobal.h"
  29. #include "QXmppLogger.h"
  30. #include "QXmppStanza.h"
  31. class QXmppSaslClientPrivate;
  32. class QXmppSaslServerPrivate;
  33. //
  34. // W A R N I N G
  35. // -------------
  36. //
  37. // This file is not part of the QXmpp API. It exists for the convenience
  38. // of the QXmppIncomingClient and QXmppOutgoingClient classes.
  39. //
  40. // This header file may change from version to version without notice,
  41. // or even be removed.
  42. //
  43. // We mean it.
  44. //
  45. class QXMPP_AUTOTEST_EXPORT QXmppSaslClient : public QXmppLoggable
  46. {
  47. public:
  48. QXmppSaslClient(QObject *parent = 0);
  49. virtual ~QXmppSaslClient();
  50. QString host() const;
  51. void setHost(const QString &host);
  52. QString serviceType() const;
  53. void setServiceType(const QString &serviceType);
  54. QString username() const;
  55. void setUsername(const QString &username);
  56. QString password() const;
  57. void setPassword(const QString &password);
  58. virtual QString mechanism() const = 0;
  59. virtual bool respond(const QByteArray &challenge, QByteArray &response) = 0;
  60. static QStringList availableMechanisms();
  61. static QXmppSaslClient* create(const QString &mechanism, QObject *parent = 0);
  62. private:
  63. QXmppSaslClientPrivate *d;
  64. };
  65. class QXMPP_AUTOTEST_EXPORT QXmppSaslServer : public QXmppLoggable
  66. {
  67. public:
  68. enum Response {
  69. Challenge = 0,
  70. Succeeded = 1,
  71. Failed = 2,
  72. InputNeeded = 3
  73. };
  74. QXmppSaslServer(QObject *parent = 0);
  75. virtual ~QXmppSaslServer();
  76. QString username() const;
  77. void setUsername(const QString &username);
  78. QString password() const;
  79. void setPassword(const QString &password);
  80. QByteArray passwordDigest() const;
  81. void setPasswordDigest(const QByteArray &digest);
  82. QString realm() const;
  83. void setRealm(const QString &realm);
  84. virtual QString mechanism() const = 0;
  85. virtual Response respond(const QByteArray &challenge, QByteArray &response) = 0;
  86. static QXmppSaslServer* create(const QString &mechanism, QObject *parent = 0);
  87. private:
  88. QXmppSaslServerPrivate *d;
  89. };
  90. class QXMPP_AUTOTEST_EXPORT QXmppSaslDigestMd5
  91. {
  92. public:
  93. static void setNonce(const QByteArray &nonce);
  94. // message parsing and serialization
  95. static QMap<QByteArray, QByteArray> parseMessage(const QByteArray &ba);
  96. static QByteArray serializeMessage(const QMap<QByteArray, QByteArray> &map);
  97. };
  98. class QXMPP_AUTOTEST_EXPORT QXmppSaslAuth : public QXmppStanza
  99. {
  100. public:
  101. QXmppSaslAuth(const QString &mechanism = QString(), const QByteArray &value = QByteArray());
  102. QString mechanism() const;
  103. void setMechanism(const QString &mechanism);
  104. QByteArray value() const;
  105. void setValue(const QByteArray &value);
  106. /// \cond
  107. void parse(const QDomElement &element);
  108. void toXml(QXmlStreamWriter *writer) const;
  109. /// \endcond
  110. private:
  111. QString m_mechanism;
  112. QByteArray m_value;
  113. };
  114. class QXMPP_AUTOTEST_EXPORT QXmppSaslChallenge : public QXmppStanza
  115. {
  116. public:
  117. QXmppSaslChallenge(const QByteArray &value = QByteArray());
  118. QByteArray value() const;
  119. void setValue(const QByteArray &value);
  120. /// \cond
  121. void parse(const QDomElement &element);
  122. void toXml(QXmlStreamWriter *writer) const;
  123. /// \endcond
  124. private:
  125. QByteArray m_value;
  126. };
  127. class QXMPP_AUTOTEST_EXPORT QXmppSaslFailure : public QXmppStanza
  128. {
  129. public:
  130. QXmppSaslFailure(const QString &condition = QString());
  131. QString condition() const;
  132. void setCondition(const QString &condition);
  133. /// \cond
  134. void parse(const QDomElement &element);
  135. void toXml(QXmlStreamWriter *writer) const;
  136. /// \endcond
  137. private:
  138. QString m_condition;
  139. };
  140. class QXMPP_AUTOTEST_EXPORT QXmppSaslResponse : public QXmppStanza
  141. {
  142. public:
  143. QXmppSaslResponse(const QByteArray &value = QByteArray());
  144. QByteArray value() const;
  145. void setValue(const QByteArray &value);
  146. /// \cond
  147. void parse(const QDomElement &element);
  148. void toXml(QXmlStreamWriter *writer) const;
  149. /// \endcond
  150. private:
  151. QByteArray m_value;
  152. };
  153. class QXMPP_AUTOTEST_EXPORT QXmppSaslSuccess : public QXmppStanza
  154. {
  155. public:
  156. QXmppSaslSuccess();
  157. /// \cond
  158. void parse(const QDomElement &element);
  159. void toXml(QXmlStreamWriter *writer) const;
  160. /// \endcond
  161. };
  162. class QXmppSaslClientAnonymous : public QXmppSaslClient
  163. {
  164. public:
  165. QXmppSaslClientAnonymous(QObject *parent = 0);
  166. QString mechanism() const;
  167. bool respond(const QByteArray &challenge, QByteArray &response);
  168. private:
  169. int m_step;
  170. };
  171. class QXmppSaslClientDigestMd5 : public QXmppSaslClient
  172. {
  173. public:
  174. QXmppSaslClientDigestMd5(QObject *parent = 0);
  175. QString mechanism() const;
  176. bool respond(const QByteArray &challenge, QByteArray &response);
  177. private:
  178. QByteArray m_cnonce;
  179. QByteArray m_nc;
  180. QByteArray m_nonce;
  181. QByteArray m_secret;
  182. int m_step;
  183. };
  184. class QXmppSaslClientFacebook : public QXmppSaslClient
  185. {
  186. public:
  187. QXmppSaslClientFacebook(QObject *parent = 0);
  188. QString mechanism() const;
  189. bool respond(const QByteArray &challenge, QByteArray &response);
  190. private:
  191. int m_step;
  192. };
  193. class QXmppSaslClientGoogle : public QXmppSaslClient
  194. {
  195. public:
  196. QXmppSaslClientGoogle(QObject *parent = 0);
  197. QString mechanism() const;
  198. bool respond(const QByteArray &challenge, QByteArray &response);
  199. private:
  200. int m_step;
  201. };
  202. class QXmppSaslClientPlain : public QXmppSaslClient
  203. {
  204. public:
  205. QXmppSaslClientPlain(QObject *parent = 0);
  206. QString mechanism() const;
  207. bool respond(const QByteArray &challenge, QByteArray &response);
  208. private:
  209. int m_step;
  210. };
  211. class QXmppSaslClientWindowsLive : public QXmppSaslClient
  212. {
  213. public:
  214. QXmppSaslClientWindowsLive(QObject *parent = 0);
  215. QString mechanism() const;
  216. bool respond(const QByteArray &challenge, QByteArray &response);
  217. private:
  218. int m_step;
  219. };
  220. class QXmppSaslServerAnonymous : public QXmppSaslServer
  221. {
  222. public:
  223. QXmppSaslServerAnonymous(QObject *parent = 0);
  224. QString mechanism() const;
  225. Response respond(const QByteArray &challenge, QByteArray &response);
  226. private:
  227. int m_step;
  228. };
  229. class QXmppSaslServerDigestMd5 : public QXmppSaslServer
  230. {
  231. public:
  232. QXmppSaslServerDigestMd5(QObject *parent = 0);
  233. QString mechanism() const;
  234. Response respond(const QByteArray &challenge, QByteArray &response);
  235. private:
  236. QByteArray m_cnonce;
  237. QByteArray m_nc;
  238. QByteArray m_nonce;
  239. QByteArray m_secret;
  240. int m_step;
  241. };
  242. class QXmppSaslServerFacebook : public QXmppSaslServer
  243. {
  244. public:
  245. QXmppSaslServerFacebook(QObject *parent = 0);
  246. QString mechanism() const;
  247. Response respond(const QByteArray &challenge, QByteArray &response);
  248. private:
  249. int m_step;
  250. };
  251. class QXmppSaslServerPlain : public QXmppSaslServer
  252. {
  253. public:
  254. QXmppSaslServerPlain(QObject *parent = 0);
  255. QString mechanism() const;
  256. Response respond(const QByteArray &challenge, QByteArray &response);
  257. private:
  258. int m_step;
  259. };
  260. #endif