1/*
2 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_LIBJINGLE_XMPP_SASLPLAINMECHANISM_H_
12#define WEBRTC_LIBJINGLE_XMPP_SASLPLAINMECHANISM_H_
13
14#include "webrtc/libjingle/xmpp/saslmechanism.h"
15#include "webrtc/base/cryptstring.h"
16
17namespace buzz {
18
19class SaslPlainMechanism : public SaslMechanism {
20
21public:
22  SaslPlainMechanism(const buzz::Jid user_jid, const rtc::CryptString & password) :
23    user_jid_(user_jid), password_(password) {}
24
25  virtual std::string GetMechanismName() { return "PLAIN"; }
26
27  virtual XmlElement * StartSaslAuth() {
28    // send initial request
29    XmlElement * el = new XmlElement(QN_SASL_AUTH, true);
30    el->AddAttr(QN_MECHANISM, "PLAIN");
31
32    rtc::FormatCryptString credential;
33    credential.Append("\0", 1);
34    credential.Append(user_jid_.node());
35    credential.Append("\0", 1);
36    credential.Append(&password_);
37    el->AddText(Base64EncodeFromArray(credential.GetData(), credential.GetLength()));
38    return el;
39  }
40
41private:
42  Jid user_jid_;
43  rtc::CryptString password_;
44};
45
46}
47
48#endif  // WEBRTC_LIBJINGLE_XMPP_SASLPLAINMECHANISM_H_
49