| 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 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 AuthenticationMethod::HashFunction hash_function, | 38 AuthenticationMethod::HashFunction hash_function, |
| 39 scoped_refptr<PairingRegistry> pairing_registry) { | 39 scoped_refptr<PairingRegistry> pairing_registry) { |
| 40 scoped_ptr<NegotiatingHostAuthenticator> result( | 40 scoped_ptr<NegotiatingHostAuthenticator> result( |
| 41 new NegotiatingHostAuthenticator(local_cert, key_pair)); | 41 new NegotiatingHostAuthenticator(local_cert, key_pair)); |
| 42 result->shared_secret_hash_ = shared_secret_hash; | 42 result->shared_secret_hash_ = shared_secret_hash; |
| 43 result->pairing_registry_ = pairing_registry; | 43 result->pairing_registry_ = pairing_registry; |
| 44 result->AddMethod(AuthenticationMethod::Spake2(hash_function)); | 44 result->AddMethod(AuthenticationMethod::Spake2(hash_function)); |
| 45 if (pairing_registry.get()) { | 45 if (pairing_registry.get()) { |
| 46 result->AddMethod(AuthenticationMethod::Spake2Pair()); | 46 result->AddMethod(AuthenticationMethod::Spake2Pair()); |
| 47 } | 47 } |
| 48 return result.Pass(); | 48 return std::move(result); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 scoped_ptr<Authenticator> | 52 scoped_ptr<Authenticator> |
| 53 NegotiatingHostAuthenticator::CreateWithThirdPartyAuth( | 53 NegotiatingHostAuthenticator::CreateWithThirdPartyAuth( |
| 54 const std::string& local_cert, | 54 const std::string& local_cert, |
| 55 scoped_refptr<RsaKeyPair> key_pair, | 55 scoped_refptr<RsaKeyPair> key_pair, |
| 56 scoped_ptr<TokenValidator> token_validator) { | 56 scoped_ptr<TokenValidator> token_validator) { |
| 57 scoped_ptr<NegotiatingHostAuthenticator> result( | 57 scoped_ptr<NegotiatingHostAuthenticator> result( |
| 58 new NegotiatingHostAuthenticator(local_cert, key_pair)); | 58 new NegotiatingHostAuthenticator(local_cert, key_pair)); |
| 59 result->token_validator_ = token_validator.Pass(); | 59 result->token_validator_ = std::move(token_validator); |
| 60 result->AddMethod(AuthenticationMethod::ThirdParty()); | 60 result->AddMethod(AuthenticationMethod::ThirdParty()); |
| 61 return result.Pass(); | 61 return std::move(result); |
| 62 } | 62 } |
| 63 | 63 |
| 64 NegotiatingHostAuthenticator::~NegotiatingHostAuthenticator() { | 64 NegotiatingHostAuthenticator::~NegotiatingHostAuthenticator() { |
| 65 } | 65 } |
| 66 | 66 |
| 67 void NegotiatingHostAuthenticator::ProcessMessage( | 67 void NegotiatingHostAuthenticator::ProcessMessage( |
| 68 const buzz::XmlElement* message, | 68 const buzz::XmlElement* message, |
| 69 const base::Closure& resume_callback) { | 69 const base::Closure& resume_callback) { |
| 70 DCHECK_EQ(state(), WAITING_MESSAGE); | 70 DCHECK_EQ(state(), WAITING_MESSAGE); |
| 71 | 71 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 Authenticator::State preferred_initial_state, | 156 Authenticator::State preferred_initial_state, |
| 157 const base::Closure& resume_callback) { | 157 const base::Closure& resume_callback) { |
| 158 DCHECK(current_method_.is_valid()); | 158 DCHECK(current_method_.is_valid()); |
| 159 | 159 |
| 160 if (current_method_.type() == AuthenticationMethod::THIRD_PARTY) { | 160 if (current_method_.type() == AuthenticationMethod::THIRD_PARTY) { |
| 161 // |ThirdPartyHostAuthenticator| takes ownership of |token_validator_|. | 161 // |ThirdPartyHostAuthenticator| takes ownership of |token_validator_|. |
| 162 // The authentication method negotiation logic should guarantee that only | 162 // The authentication method negotiation logic should guarantee that only |
| 163 // one |ThirdPartyHostAuthenticator| will need to be created per session. | 163 // one |ThirdPartyHostAuthenticator| will need to be created per session. |
| 164 DCHECK(token_validator_); | 164 DCHECK(token_validator_); |
| 165 current_authenticator_.reset(new ThirdPartyHostAuthenticator( | 165 current_authenticator_.reset(new ThirdPartyHostAuthenticator( |
| 166 local_cert_, local_key_pair_, token_validator_.Pass())); | 166 local_cert_, local_key_pair_, std::move(token_validator_))); |
| 167 } else if (current_method_ == AuthenticationMethod::Spake2Pair() && | 167 } else if (current_method_ == AuthenticationMethod::Spake2Pair() && |
| 168 preferred_initial_state == WAITING_MESSAGE) { | 168 preferred_initial_state == WAITING_MESSAGE) { |
| 169 // If the client requested Spake2Pair and sent an initial message, attempt | 169 // If the client requested Spake2Pair and sent an initial message, attempt |
| 170 // the paired connection protocol. | 170 // the paired connection protocol. |
| 171 current_authenticator_.reset(new PairingHostAuthenticator( | 171 current_authenticator_.reset(new PairingHostAuthenticator( |
| 172 pairing_registry_, local_cert_, local_key_pair_, shared_secret_hash_)); | 172 pairing_registry_, local_cert_, local_key_pair_, shared_secret_hash_)); |
| 173 } else { | 173 } else { |
| 174 // In all other cases, use the V2 protocol. Note that this includes the | 174 // In all other cases, use the V2 protocol. Note that this includes the |
| 175 // case where the protocol is Spake2Pair but the client is not yet paired. | 175 // case where the protocol is Spake2Pair but the client is not yet paired. |
| 176 // In this case, the on-the-wire protocol is plain Spake2, advertised as | 176 // In this case, the on-the-wire protocol is plain Spake2, advertised as |
| 177 // Spake2Pair so that the client knows that the host supports pairing and | 177 // Spake2Pair so that the client knows that the host supports pairing and |
| 178 // that it can therefore present the option to the user when they enter | 178 // that it can therefore present the option to the user when they enter |
| 179 // the PIN. | 179 // the PIN. |
| 180 DCHECK(current_method_.type() == AuthenticationMethod::SPAKE2 || | 180 DCHECK(current_method_.type() == AuthenticationMethod::SPAKE2 || |
| 181 current_method_.type() == AuthenticationMethod::SPAKE2_PAIR); | 181 current_method_.type() == AuthenticationMethod::SPAKE2_PAIR); |
| 182 current_authenticator_ = V2Authenticator::CreateForHost( | 182 current_authenticator_ = V2Authenticator::CreateForHost( |
| 183 local_cert_, local_key_pair_, shared_secret_hash_, | 183 local_cert_, local_key_pair_, shared_secret_hash_, |
| 184 preferred_initial_state); | 184 preferred_initial_state); |
| 185 } | 185 } |
| 186 resume_callback.Run(); | 186 resume_callback.Run(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 } // namespace protocol | 189 } // namespace protocol |
| 190 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |