1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef REMOTING_PROTOCOL_THIRD_PARTY_AUTHENTICATOR_BASE_H_ 6 #define REMOTING_PROTOCOL_THIRD_PARTY_AUTHENTICATOR_BASE_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/callback.h" 12 #include "base/macros.h" 13 #include "remoting/protocol/authenticator.h" 14 #include "third_party/libjingle_xmpp/xmllite/qname.h" 15 16 namespace jingle_xmpp { 17 18 class XmlElement; 19 20 } // namespace jingle_xmpp 21 22 namespace remoting { 23 namespace protocol { 24 25 // Implements an authentication method that relies on a third party server for 26 // authentication of both client and host. 27 // When third party authentication is being used, the client must request both a 28 // token and a shared secret from a third-party server (which may require the 29 // user to authenticate themselves). The client then sends only the token to the 30 // host. The host signs the token, then contacts the third-party server to 31 // exchange the token for the shared secret. Once both client and host have the 32 // shared secret, they use an underlying |V2Authenticator| (SPAKE2) to negotiate 33 // an authentication key, which is used to establish the connection. 34 class ThirdPartyAuthenticatorBase : public Authenticator { 35 public: 36 ~ThirdPartyAuthenticatorBase() override; 37 38 // Authenticator interface. 39 State state() const override; 40 bool started() const override; 41 RejectionReason rejection_reason() const override; 42 void ProcessMessage(const jingle_xmpp::XmlElement* message, 43 base::OnceClosure resume_callback) override; 44 std::unique_ptr<jingle_xmpp::XmlElement> GetNextMessage() override; 45 const std::string& GetAuthKey() const override; 46 std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator() 47 const override; 48 49 protected: 50 // XML tag names for third party authentication fields. 51 static const jingle_xmpp::StaticQName kTokenUrlTag; 52 static const jingle_xmpp::StaticQName kTokenScopeTag; 53 static const jingle_xmpp::StaticQName kTokenTag; 54 55 explicit ThirdPartyAuthenticatorBase(State initial_state); 56 57 // Gives the message to the underlying authenticator for processing. 58 void ProcessUnderlyingMessage(const jingle_xmpp::XmlElement* message, 59 base::OnceClosure resume_callback); 60 61 // Processes the token-related elements of the message. 62 virtual void ProcessTokenMessage(const jingle_xmpp::XmlElement* message, 63 base::OnceClosure resume_callback) = 0; 64 65 // Adds the token related XML elements to the message. 66 virtual void AddTokenElements(jingle_xmpp::XmlElement* message) = 0; 67 68 std::unique_ptr<Authenticator> underlying_; 69 State token_state_; 70 bool started_; 71 RejectionReason rejection_reason_; 72 73 private: 74 DISALLOW_COPY_AND_ASSIGN(ThirdPartyAuthenticatorBase); 75 }; 76 77 } // namespace protocol 78 } // namespace remoting 79 80 #endif // REMOTING_PROTOCOL_THIRD_PARTY_AUTHENTICATOR_BASE_H_ 81