| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_ | 5 #ifndef REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_ |
| 6 #define REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_ | 6 #define REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "remoting/protocol/authentication_method.h" | 14 #include "remoting/protocol/authentication_method.h" |
| 15 #include "remoting/protocol/authenticator.h" | 15 #include "remoting/protocol/authenticator.h" |
| 16 #include "remoting/protocol/negotiating_authenticator_base.h" | 16 #include "remoting/protocol/negotiating_authenticator_base.h" |
| 17 #include "remoting/protocol/third_party_client_authenticator.h" | 17 #include "remoting/protocol/third_party_client_authenticator.h" |
| 18 | 18 |
| 19 namespace remoting { | 19 namespace remoting { |
| 20 namespace protocol { | 20 namespace protocol { |
| 21 | 21 |
| 22 typedef base::Callback<void(const std::string& secret)> SecretFetchedCallback; | |
| 23 typedef base::Callback<void( | |
| 24 const SecretFetchedCallback& secret_fetched_callback)> FetchSecretCallback; | |
| 25 | |
| 26 // Client-side implementation of NegotiatingAuthenticatorBase. | 22 // Client-side implementation of NegotiatingAuthenticatorBase. |
| 27 // See comments in negotiating_authenticator_base.h for a general explanation. | 23 // See comments in negotiating_authenticator_base.h for a general explanation. |
| 28 class NegotiatingClientAuthenticator : public NegotiatingAuthenticatorBase { | 24 class NegotiatingClientAuthenticator : public NegotiatingAuthenticatorBase { |
| 29 public: | 25 public: |
| 26 // TODO(jamiewalch): Pass ClientConfig instead of separate parameters. |
| 30 NegotiatingClientAuthenticator( | 27 NegotiatingClientAuthenticator( |
| 28 const std::string& client_pairing_id, |
| 29 const std::string& shared_secret, |
| 31 const std::string& authentication_tag, | 30 const std::string& authentication_tag, |
| 32 const FetchSecretCallback& fetch_secret_callback, | 31 const FetchSecretCallback& fetch_secret_callback, |
| 33 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher_, | 32 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher_, |
| 34 const std::vector<AuthenticationMethod>& methods); | 33 const std::vector<AuthenticationMethod>& methods); |
| 35 | 34 |
| 36 virtual ~NegotiatingClientAuthenticator(); | 35 virtual ~NegotiatingClientAuthenticator(); |
| 37 | 36 |
| 38 // Overriden from Authenticator. | 37 // Overriden from Authenticator. |
| 39 virtual void ProcessMessage(const buzz::XmlElement* message, | 38 virtual void ProcessMessage(const buzz::XmlElement* message, |
| 40 const base::Closure& resume_callback) OVERRIDE; | 39 const base::Closure& resume_callback) OVERRIDE; |
| 41 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; | 40 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; |
| 42 | 41 |
| 43 private: | 42 private: |
| 44 // (Asynchronously) creates an authenticator, and stores it in | 43 // (Asynchronously) creates an authenticator, and stores it in |
| 45 // |current_authenticator_|. Authenticators that can be started in either | 44 // |current_authenticator_|. Authenticators that can be started in either |
| 46 // state will be created in |preferred_initial_state|. | 45 // state will be created in |preferred_initial_state|. |
| 47 // |resume_callback| is called after |current_authenticator_| is set. | 46 // |resume_callback| is called after |current_authenticator_| is set. |
| 48 void CreateAuthenticatorForCurrentMethod( | 47 void CreateAuthenticatorForCurrentMethod( |
| 49 Authenticator::State preferred_initial_state, | 48 Authenticator::State preferred_initial_state, |
| 50 const base::Closure& resume_callback); | 49 const base::Closure& resume_callback); |
| 51 | 50 |
| 52 // If possible, create a preferred authenticator ready to send an | 51 // If possible, create a preferred authenticator ready to send an |
| 53 // initial message optimistically to the host. The host is free to | 52 // initial message optimistically to the host. The host is free to |
| 54 // ignore the client's preferred authenticator and initial message | 53 // ignore the client's preferred authenticator and initial message |
| 55 // and to instead reply with an alternative method. See the comments | 54 // and to instead reply with an alternative method. See the comments |
| 56 // in negotiating_authenticator_base.h for more details. | 55 // in negotiating_authenticator_base.h for more details. |
| 57 // | 56 // |
| 58 // Returns the preferred authenticator if possible, or NULL otherwise. | 57 // Sets |current_authenticator_| and |current_method_| iff the client |
| 59 scoped_ptr<Authenticator> CreatePreferredAuthenticator(); | 58 // has a preferred authenticator that can optimistically send an initial |
| 60 | 59 // message. |
| 60 void CreatePreferredAuthenticator(); |
| 61 | 61 |
| 62 // Creates a V2Authenticator in state |initial_state| with the given | 62 // Creates a V2Authenticator in state |initial_state| with the given |
| 63 // |shared_secret|, then runs |resume_callback|. | 63 // |shared_secret|, then runs |resume_callback|. |
| 64 void CreateV2AuthenticatorWithSecret( | 64 void CreateV2AuthenticatorWithSecret( |
| 65 Authenticator::State initial_state, | 65 Authenticator::State initial_state, |
| 66 const base::Closure& resume_callback, | 66 const base::Closure& resume_callback, |
| 67 const std::string& shared_secret); | 67 const std::string& shared_secret); |
| 68 | 68 |
| 69 // Used for both authenticators. | 69 // Used for pairing authenticators |
| 70 std::string client_pairing_id_; |
| 71 std::string shared_secret_; |
| 72 |
| 73 // Used for all authenticators. |
| 70 std::string authentication_tag_; | 74 std::string authentication_tag_; |
| 71 | 75 |
| 72 // Used for shared secret authenticators. | 76 // Used for shared secret authenticators. |
| 73 FetchSecretCallback fetch_secret_callback_; | 77 FetchSecretCallback fetch_secret_callback_; |
| 74 | 78 |
| 75 // Used for third party authenticators. | 79 // Used for third party authenticators. |
| 76 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher_; | 80 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher_; |
| 77 | 81 |
| 78 // Internal NegotiatingClientAuthenticator data. | 82 // Internal NegotiatingClientAuthenticator data. |
| 79 bool method_set_by_host_; | 83 bool method_set_by_host_; |
| 80 base::WeakPtrFactory<NegotiatingClientAuthenticator> weak_factory_; | 84 base::WeakPtrFactory<NegotiatingClientAuthenticator> weak_factory_; |
| 81 | 85 |
| 82 DISALLOW_COPY_AND_ASSIGN(NegotiatingClientAuthenticator); | 86 DISALLOW_COPY_AND_ASSIGN(NegotiatingClientAuthenticator); |
| 83 }; | 87 }; |
| 84 | 88 |
| 85 } // namespace protocol | 89 } // namespace protocol |
| 86 } // namespace remoting | 90 } // namespace remoting |
| 87 | 91 |
| 88 #endif // REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_ | 92 #endif // REMOTING_PROTOCOL_NEGOTIATING_CLIENT_AUTHENTICATOR_H_ |
| OLD | NEW |