| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 token_fetcher_(std::move(token_fetcher)), | 35 token_fetcher_(std::move(token_fetcher)), |
| 36 method_set_by_host_(false), | 36 method_set_by_host_(false), |
| 37 weak_factory_(this) { | 37 weak_factory_(this) { |
| 38 DCHECK(!methods.empty()); | 38 DCHECK(!methods.empty()); |
| 39 for (std::vector<AuthenticationMethod>::const_iterator it = methods.begin(); | 39 for (std::vector<AuthenticationMethod>::const_iterator it = methods.begin(); |
| 40 it != methods.end(); ++it) { | 40 it != methods.end(); ++it) { |
| 41 AddMethod(*it); | 41 AddMethod(*it); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 NegotiatingClientAuthenticator::~NegotiatingClientAuthenticator() { | 45 NegotiatingClientAuthenticator::~NegotiatingClientAuthenticator() {} |
| 46 } | |
| 47 | 46 |
| 48 void NegotiatingClientAuthenticator::ProcessMessage( | 47 void NegotiatingClientAuthenticator::ProcessMessage( |
| 49 const buzz::XmlElement* message, | 48 const buzz::XmlElement* message, |
| 50 const base::Closure& resume_callback) { | 49 const base::Closure& resume_callback) { |
| 51 DCHECK_EQ(state(), WAITING_MESSAGE); | 50 DCHECK_EQ(state(), WAITING_MESSAGE); |
| 52 | 51 |
| 53 std::string method_attr = message->Attr(kMethodAttributeQName); | 52 std::string method_attr = message->Attr(kMethodAttributeQName); |
| 54 AuthenticationMethod method = ParseAuthenticationMethodString(method_attr); | 53 AuthenticationMethod method = ParseAuthenticationMethodString(method_attr); |
| 55 | 54 |
| 56 // The host picked a method different from the one the client had selected. | 55 // The host picked a method different from the one the client had selected. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void NegotiatingClientAuthenticator::CreateAuthenticatorForCurrentMethod( | 112 void NegotiatingClientAuthenticator::CreateAuthenticatorForCurrentMethod( |
| 114 Authenticator::State preferred_initial_state, | 113 Authenticator::State preferred_initial_state, |
| 115 const base::Closure& resume_callback) { | 114 const base::Closure& resume_callback) { |
| 116 DCHECK(current_method_ != AuthenticationMethod::INVALID); | 115 DCHECK(current_method_ != AuthenticationMethod::INVALID); |
| 117 if (current_method_ == AuthenticationMethod::THIRD_PARTY) { | 116 if (current_method_ == AuthenticationMethod::THIRD_PARTY) { |
| 118 // |ThirdPartyClientAuthenticator| takes ownership of |token_fetcher_|. | 117 // |ThirdPartyClientAuthenticator| takes ownership of |token_fetcher_|. |
| 119 // The authentication method negotiation logic should guarantee that only | 118 // The authentication method negotiation logic should guarantee that only |
| 120 // one |ThirdPartyClientAuthenticator| will need to be created per session. | 119 // one |ThirdPartyClientAuthenticator| will need to be created per session. |
| 121 DCHECK(token_fetcher_); | 120 DCHECK(token_fetcher_); |
| 122 current_authenticator_.reset(new ThirdPartyClientAuthenticator( | 121 current_authenticator_.reset(new ThirdPartyClientAuthenticator( |
| 122 base::Bind(&V2Authenticator::CreateForClient), |
| 123 std::move(token_fetcher_))); | 123 std::move(token_fetcher_))); |
| 124 resume_callback.Run(); | 124 resume_callback.Run(); |
| 125 } else { | 125 } else { |
| 126 DCHECK(current_method_ == | 126 DCHECK(current_method_ == |
| 127 AuthenticationMethod::SPAKE2_SHARED_SECRET_PLAIN || | 127 AuthenticationMethod::SPAKE2_SHARED_SECRET_PLAIN || |
| 128 current_method_ == AuthenticationMethod::SPAKE2_SHARED_SECRET_HMAC || | 128 current_method_ == AuthenticationMethod::SPAKE2_SHARED_SECRET_HMAC || |
| 129 current_method_ == AuthenticationMethod::SPAKE2_PAIR); | 129 current_method_ == AuthenticationMethod::SPAKE2_PAIR); |
| 130 bool pairing_supported = | 130 bool pairing_supported = |
| 131 (current_method_ == AuthenticationMethod::SPAKE2_PAIR); | 131 (current_method_ == AuthenticationMethod::SPAKE2_PAIR); |
| 132 SecretFetchedCallback callback = base::Bind( | 132 SecretFetchedCallback callback = base::Bind( |
| 133 &NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret, | 133 &NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret, |
| 134 weak_factory_.GetWeakPtr(), preferred_initial_state, resume_callback); | 134 weak_factory_.GetWeakPtr(), preferred_initial_state, resume_callback); |
| 135 fetch_secret_callback_.Run(pairing_supported, callback); | 135 fetch_secret_callback_.Run(pairing_supported, callback); |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 void NegotiatingClientAuthenticator::CreatePreferredAuthenticator() { | 139 void NegotiatingClientAuthenticator::CreatePreferredAuthenticator() { |
| 140 if (!client_pairing_id_.empty() && !shared_secret_.empty() && | 140 if (!client_pairing_id_.empty() && !shared_secret_.empty() && |
| 141 std::find(methods_.begin(), methods_.end(), | 141 std::find(methods_.begin(), methods_.end(), |
| 142 AuthenticationMethod::SPAKE2_PAIR) != methods_.end()) { | 142 AuthenticationMethod::SPAKE2_PAIR) != methods_.end()) { |
| 143 // If the client specified a pairing id and shared secret, then create a | 143 // If the client specified a pairing id and shared secret, then create a |
| 144 // PairingAuthenticator. | 144 // PairingAuthenticator. |
| 145 current_authenticator_.reset(new PairingClientAuthenticator( | 145 current_authenticator_.reset(new PairingClientAuthenticator( |
| 146 client_pairing_id_, shared_secret_, fetch_secret_callback_, | 146 client_pairing_id_, shared_secret_, |
| 147 base::Bind(&V2Authenticator::CreateForClient), fetch_secret_callback_, |
| 147 authentication_tag_)); | 148 authentication_tag_)); |
| 148 current_method_ = AuthenticationMethod::SPAKE2_PAIR; | 149 current_method_ = AuthenticationMethod::SPAKE2_PAIR; |
| 149 } | 150 } |
| 150 } | 151 } |
| 151 | 152 |
| 152 void NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret( | 153 void NegotiatingClientAuthenticator::CreateV2AuthenticatorWithSecret( |
| 153 Authenticator::State initial_state, | 154 Authenticator::State initial_state, |
| 154 const base::Closure& resume_callback, | 155 const base::Closure& resume_callback, |
| 155 const std::string& shared_secret) { | 156 const std::string& shared_secret) { |
| 156 current_authenticator_ = V2Authenticator::CreateForClient( | 157 current_authenticator_ = V2Authenticator::CreateForClient( |
| 157 ApplySharedSecretHashFunction( | 158 ApplySharedSecretHashFunction( |
| 158 GetHashFunctionForAuthenticationMethod(current_method_), | 159 GetHashFunctionForAuthenticationMethod(current_method_), |
| 159 authentication_tag_, shared_secret), | 160 authentication_tag_, shared_secret), |
| 160 initial_state); | 161 initial_state); |
| 161 resume_callback.Run(); | 162 resume_callback.Run(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 } // namespace protocol | 165 } // namespace protocol |
| 165 } // namespace remoting | 166 } // namespace remoting |
| OLD | NEW |