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_SASLMECHANISM_H_ 12 #define WEBRTC_LIBJINGLE_XMPP_SASLMECHANISM_H_ 13 14 #include <string> 15 16 namespace buzz { 17 18 class XmlElement; 19 20 21 // Defines a mechnanism to do SASL authentication. 22 // Subclass instances should have a self-contained way to present 23 // credentials. 24 class SaslMechanism { 25 26 public: 27 28 // Intended to be subclassed ~SaslMechanism()29 virtual ~SaslMechanism() {} 30 31 // Should return the name of the SASL mechanism, e.g., "PLAIN" 32 virtual std::string GetMechanismName() = 0; 33 34 // Should generate the initial "auth" request. Default is just <auth/>. 35 virtual XmlElement * StartSaslAuth(); 36 37 // Should respond to a SASL "<challenge>" request. Default is 38 // to abort (for mechanisms that do not do challenge-response) 39 virtual XmlElement * HandleSaslChallenge(const XmlElement * challenge); 40 41 // Notification of a SASL "<success>". Sometimes information 42 // is passed on success. 43 virtual void HandleSaslSuccess(const XmlElement * success); 44 45 // Notification of a SASL "<failure>". Sometimes information 46 // for the user is passed on failure. 47 virtual void HandleSaslFailure(const XmlElement * failure); 48 49 protected: 50 static std::string Base64Encode(const std::string & plain); 51 static std::string Base64Decode(const std::string & encoded); 52 static std::string Base64EncodeFromArray(const char * plain, size_t length); 53 }; 54 55 } 56 57 #endif // WEBRTC_LIBJINGLE_XMPP_SASLMECHANISM_H_ 58