| 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 #include "remoting/protocol/negotiating_client_authenticator.h" | 5 #include "remoting/protocol/negotiating_client_authenticator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "remoting/protocol/channel_authenticator.h" | 14 #include "remoting/protocol/channel_authenticator.h" |
| 15 #include "remoting/protocol/v2_authenticator.h" | 15 #include "remoting/protocol/v2_authenticator.h" |
| 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 16 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 namespace protocol { | 19 namespace protocol { |
| 20 | 20 |
| 21 NegotiatingClientAuthenticator::NegotiatingClientAuthenticator( | 21 NegotiatingClientAuthenticator::NegotiatingClientAuthenticator( |
| 22 const std::string& authentication_tag, | 22 const std::string& authentication_tag, |
| 23 const FetchSecretCallback& fetch_secret_callback, | 23 const FetchSecretCallback& fetch_secret_callback, |
| 24 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> token_fetcher, |
| 24 const std::vector<AuthenticationMethod>& methods) | 25 const std::vector<AuthenticationMethod>& methods) |
| 25 : NegotiatingAuthenticatorBase(MESSAGE_READY), | 26 : NegotiatingAuthenticatorBase(MESSAGE_READY), |
| 26 authentication_tag_(authentication_tag), | 27 authentication_tag_(authentication_tag), |
| 27 fetch_secret_callback_(fetch_secret_callback), | 28 fetch_secret_callback_(fetch_secret_callback), |
| 29 token_fetcher_(token_fetcher.Pass()), |
| 28 method_set_by_host_(false), | 30 method_set_by_host_(false), |
| 29 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 31 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 30 DCHECK(!methods.empty()); | 32 DCHECK(!methods.empty()); |
| 31 for (std::vector<AuthenticationMethod>::const_iterator it = methods.begin(); | 33 for (std::vector<AuthenticationMethod>::const_iterator it = methods.begin(); |
| 32 it != methods.end(); ++it) { | 34 it != methods.end(); ++it) { |
| 33 AddMethod(*it); | 35 AddMethod(*it); |
| 34 } | 36 } |
| 35 } | 37 } |
| 36 | 38 |
| 37 NegotiatingClientAuthenticator::~NegotiatingClientAuthenticator() { | 39 NegotiatingClientAuthenticator::~NegotiatingClientAuthenticator() { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 result->AddAttr(kSupportedMethodsAttributeQName, supported_methods.str()); | 92 result->AddAttr(kSupportedMethodsAttributeQName, supported_methods.str()); |
| 91 state_ = WAITING_MESSAGE; | 93 state_ = WAITING_MESSAGE; |
| 92 return result.Pass(); | 94 return result.Pass(); |
| 93 } | 95 } |
| 94 return GetNextMessageInternal(); | 96 return GetNextMessageInternal(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void NegotiatingClientAuthenticator::CreateAuthenticator( | 99 void NegotiatingClientAuthenticator::CreateAuthenticator( |
| 98 Authenticator::State preferred_initial_state, | 100 Authenticator::State preferred_initial_state, |
| 99 const base::Closure& resume_callback) { | 101 const base::Closure& resume_callback) { |
| 100 fetch_secret_callback_.Run(base::Bind( | 102 DCHECK(current_method_.is_valid()); |
| 101 &NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret, | 103 if (current_method_.type() == AuthenticationMethod::THIRD_PARTY) { |
| 102 weak_factory_.GetWeakPtr(), preferred_initial_state, resume_callback)); | 104 // |ThirdPartyClientAuthenticator| takes ownership of |token_fetcher_|. |
| 105 // The authentication method negotiation logic should guarantee that only |
| 106 // one |ThirdPartyClientAuthenticator| will need to be created per session. |
| 107 DCHECK(token_fetcher_); |
| 108 current_authenticator_.reset(new ThirdPartyClientAuthenticator( |
| 109 token_fetcher_.Pass())); |
| 110 resume_callback.Run(); |
| 111 } else { |
| 112 fetch_secret_callback_.Run(base::Bind( |
| 113 &NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret, |
| 114 weak_factory_.GetWeakPtr(), preferred_initial_state, resume_callback)); |
| 115 } |
| 103 } | 116 } |
| 104 | 117 |
| 105 void NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret( | 118 void NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret( |
| 106 Authenticator::State initial_state, | 119 Authenticator::State initial_state, |
| 107 const base::Closure& resume_callback, | 120 const base::Closure& resume_callback, |
| 108 const std::string& shared_secret) { | 121 const std::string& shared_secret) { |
| 109 current_authenticator_ = V2Authenticator::CreateForClient( | 122 current_authenticator_ = V2Authenticator::CreateForClient( |
| 110 AuthenticationMethod::ApplyHashFunction( | 123 AuthenticationMethod::ApplyHashFunction( |
| 111 current_method_.hash_function(), authentication_tag_, shared_secret), | 124 current_method_.hash_function(), authentication_tag_, shared_secret), |
| 112 initial_state); | 125 initial_state); |
| 113 resume_callback.Run(); | 126 resume_callback.Run(); |
| 114 } | 127 } |
| 115 | 128 |
| 116 } // namespace protocol | 129 } // namespace protocol |
| 117 } // namespace remoting | 130 } // namespace remoting |
| OLD | NEW |