| 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_host_authenticator.h" | 5 #include "remoting/protocol/negotiating_host_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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return std::move(result); | 71 return std::move(result); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 scoped_ptr<Authenticator> | 75 scoped_ptr<Authenticator> |
| 76 NegotiatingHostAuthenticator::CreateWithThirdPartyAuth( | 76 NegotiatingHostAuthenticator::CreateWithThirdPartyAuth( |
| 77 const std::string& local_id, | 77 const std::string& local_id, |
| 78 const std::string& remote_id, | 78 const std::string& remote_id, |
| 79 const std::string& local_cert, | 79 const std::string& local_cert, |
| 80 scoped_refptr<RsaKeyPair> key_pair, | 80 scoped_refptr<RsaKeyPair> key_pair, |
| 81 scoped_ptr<TokenValidator> token_validator) { | 81 scoped_refptr<TokenValidatorFactory> token_validator_factory) { |
| 82 scoped_ptr<NegotiatingHostAuthenticator> result( | 82 scoped_ptr<NegotiatingHostAuthenticator> result( |
| 83 new NegotiatingHostAuthenticator(local_id, remote_id, local_cert, | 83 new NegotiatingHostAuthenticator(local_id, remote_id, local_cert, |
| 84 key_pair)); | 84 key_pair)); |
| 85 result->token_validator_ = std::move(token_validator); | 85 result->token_validator_factory_ = token_validator_factory; |
| 86 result->AddMethod(Method::THIRD_PARTY_SPAKE2_CURVE25519); | 86 result->AddMethod(Method::THIRD_PARTY_SPAKE2_CURVE25519); |
| 87 result->AddMethod(Method::THIRD_PARTY_SPAKE2_P224); | 87 result->AddMethod(Method::THIRD_PARTY_SPAKE2_P224); |
| 88 return std::move(result); | 88 return std::move(result); |
| 89 } | 89 } |
| 90 | 90 |
| 91 NegotiatingHostAuthenticator::~NegotiatingHostAuthenticator() {} | 91 NegotiatingHostAuthenticator::~NegotiatingHostAuthenticator() {} |
| 92 | 92 |
| 93 void NegotiatingHostAuthenticator::ProcessMessage( | 93 void NegotiatingHostAuthenticator::ProcessMessage( |
| 94 const buzz::XmlElement* message, | 94 const buzz::XmlElement* message, |
| 95 const base::Closure& resume_callback) { | 95 const base::Closure& resume_callback) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 scoped_ptr<buzz::XmlElement> NegotiatingHostAuthenticator::GetNextMessage() { | 176 scoped_ptr<buzz::XmlElement> NegotiatingHostAuthenticator::GetNextMessage() { |
| 177 return GetNextMessageInternal(); | 177 return GetNextMessageInternal(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void NegotiatingHostAuthenticator::CreateAuthenticator( | 180 void NegotiatingHostAuthenticator::CreateAuthenticator( |
| 181 Authenticator::State preferred_initial_state, | 181 Authenticator::State preferred_initial_state, |
| 182 const base::Closure& resume_callback) { | 182 const base::Closure& resume_callback) { |
| 183 DCHECK(current_method_ != Method::INVALID); | 183 DCHECK(current_method_ != Method::INVALID); |
| 184 | 184 |
| 185 if (current_method_ == Method::THIRD_PARTY_SPAKE2_P224) { | 185 if (current_method_ == Method::THIRD_PARTY_SPAKE2_P224) { |
| 186 // |ThirdPartyHostAuthenticator| takes ownership of |token_validator_|. | |
| 187 // The authentication method negotiation logic should guarantee that only | |
| 188 // one |ThirdPartyHostAuthenticator| will need to be created per session. | |
| 189 DCHECK(token_validator_); | |
| 190 current_authenticator_.reset(new ThirdPartyHostAuthenticator( | 186 current_authenticator_.reset(new ThirdPartyHostAuthenticator( |
| 191 base::Bind(&V2Authenticator::CreateForHost, local_cert_, | 187 base::Bind(&V2Authenticator::CreateForHost, local_cert_, |
| 192 local_key_pair_), | 188 local_key_pair_), |
| 193 std::move(token_validator_))); | 189 token_validator_factory_->CreateTokenValidator(local_id_, remote_id_))); |
| 194 } else if (current_method_ == Method::THIRD_PARTY_SPAKE2_CURVE25519) { | 190 } else if (current_method_ == Method::THIRD_PARTY_SPAKE2_CURVE25519) { |
| 195 // |ThirdPartyHostAuthenticator| takes ownership of |token_validator_|. | |
| 196 // The authentication method negotiation logic should guarantee that only | |
| 197 // one |ThirdPartyHostAuthenticator| will need to be created per session. | |
| 198 DCHECK(token_validator_); | |
| 199 current_authenticator_.reset(new ThirdPartyHostAuthenticator( | 191 current_authenticator_.reset(new ThirdPartyHostAuthenticator( |
| 200 base::Bind(&Spake2Authenticator::CreateForHost, local_id_, remote_id_, | 192 base::Bind(&Spake2Authenticator::CreateForHost, local_id_, remote_id_, |
| 201 local_cert_, local_key_pair_), | 193 local_cert_, local_key_pair_), |
| 202 std::move(token_validator_))); | 194 token_validator_factory_->CreateTokenValidator(local_id_, remote_id_))); |
| 203 } else if (current_method_ == Method::SHARED_SECRET_SPAKE2_CURVE25519) { | 195 } else if (current_method_ == Method::SHARED_SECRET_SPAKE2_CURVE25519) { |
| 204 current_authenticator_ = Spake2Authenticator::CreateForHost( | 196 current_authenticator_ = Spake2Authenticator::CreateForHost( |
| 205 local_id_, remote_id_, local_cert_, local_key_pair_, | 197 local_id_, remote_id_, local_cert_, local_key_pair_, |
| 206 shared_secret_hash_, preferred_initial_state); | 198 shared_secret_hash_, preferred_initial_state); |
| 207 } else if (current_method_ == Method::PAIRED_SPAKE2_P224 && | 199 } else if (current_method_ == Method::PAIRED_SPAKE2_P224 && |
| 208 preferred_initial_state == WAITING_MESSAGE) { | 200 preferred_initial_state == WAITING_MESSAGE) { |
| 209 // If the client requested Spake2Pair and sent an initial message, attempt | 201 // If the client requested Spake2Pair and sent an initial message, attempt |
| 210 // the paired connection protocol. | 202 // the paired connection protocol. |
| 211 current_authenticator_.reset(new PairingHostAuthenticator( | 203 current_authenticator_.reset(new PairingHostAuthenticator( |
| 212 pairing_registry_, base::Bind(&V2Authenticator::CreateForHost, | 204 pairing_registry_, base::Bind(&V2Authenticator::CreateForHost, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 224 current_method_ == Method::PAIRED_SPAKE2_P224); | 216 current_method_ == Method::PAIRED_SPAKE2_P224); |
| 225 current_authenticator_ = V2Authenticator::CreateForHost( | 217 current_authenticator_ = V2Authenticator::CreateForHost( |
| 226 local_cert_, local_key_pair_, shared_secret_hash_, | 218 local_cert_, local_key_pair_, shared_secret_hash_, |
| 227 preferred_initial_state); | 219 preferred_initial_state); |
| 228 } | 220 } |
| 229 resume_callback.Run(); | 221 resume_callback.Run(); |
| 230 } | 222 } |
| 231 | 223 |
| 232 } // namespace protocol | 224 } // namespace protocol |
| 233 } // namespace remoting | 225 } // namespace remoting |
| OLD | NEW |