| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_authenticator.h" | 5 #include "remoting/protocol/negotiating_authenticator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 12 #include "crypto/rsa_private_key.h" | |
| 13 #include "remoting/protocol/channel_authenticator.h" | 14 #include "remoting/protocol/channel_authenticator.h" |
| 15 #include "remoting/protocol/key_pair.h" |
| 14 #include "remoting/protocol/v2_authenticator.h" | 16 #include "remoting/protocol/v2_authenticator.h" |
| 15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 16 | 18 |
| 17 namespace remoting { | 19 namespace remoting { |
| 18 namespace protocol { | 20 namespace protocol { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 const buzz::StaticQName kMethodAttributeQName = { "", "method" }; | 24 const buzz::StaticQName kMethodAttributeQName = { "", "method" }; |
| 23 const buzz::StaticQName kSupportedMethodsAttributeQName = | 25 const buzz::StaticQName kSupportedMethodsAttributeQName = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 it != methods.end(); ++it) { | 50 it != methods.end(); ++it) { |
| 49 result->AddMethod(*it); | 51 result->AddMethod(*it); |
| 50 } | 52 } |
| 51 | 53 |
| 52 return scoped_ptr<Authenticator>(result.Pass()); | 54 return scoped_ptr<Authenticator>(result.Pass()); |
| 53 } | 55 } |
| 54 | 56 |
| 55 // static | 57 // static |
| 56 scoped_ptr<Authenticator> NegotiatingAuthenticator::CreateForHost( | 58 scoped_ptr<Authenticator> NegotiatingAuthenticator::CreateForHost( |
| 57 const std::string& local_cert, | 59 const std::string& local_cert, |
| 58 const crypto::RSAPrivateKey& local_private_key, | 60 scoped_ptr<KeyPair> key_pair, |
| 59 const std::string& shared_secret_hash, | 61 const std::string& shared_secret_hash, |
| 60 AuthenticationMethod::HashFunction hash_function) { | 62 AuthenticationMethod::HashFunction hash_function) { |
| 61 scoped_ptr<NegotiatingAuthenticator> result( | 63 scoped_ptr<NegotiatingAuthenticator> result( |
| 62 new NegotiatingAuthenticator(WAITING_MESSAGE)); | 64 new NegotiatingAuthenticator(WAITING_MESSAGE)); |
| 63 result->local_cert_ = local_cert; | 65 result->local_cert_ = local_cert; |
| 64 result->local_private_key_.reset(local_private_key.Copy()); | 66 result->key_pair_ = key_pair.Pass(); |
| 65 result->shared_secret_hash_ = shared_secret_hash; | 67 result->shared_secret_hash_ = shared_secret_hash; |
| 66 | 68 |
| 67 result->AddMethod(AuthenticationMethod::Spake2(hash_function)); | 69 result->AddMethod(AuthenticationMethod::Spake2(hash_function)); |
| 68 | 70 |
| 69 return scoped_ptr<Authenticator>(result.Pass()); | 71 return scoped_ptr<Authenticator>(result.Pass()); |
| 70 } | 72 } |
| 71 | 73 |
| 72 | |
| 73 NegotiatingAuthenticator::NegotiatingAuthenticator( | 74 NegotiatingAuthenticator::NegotiatingAuthenticator( |
| 74 Authenticator::State initial_state) | 75 Authenticator::State initial_state) |
| 75 : certificate_sent_(false), | 76 : current_method_(AuthenticationMethod::Invalid()), |
| 76 current_method_(AuthenticationMethod::Invalid()), | |
| 77 state_(initial_state), | 77 state_(initial_state), |
| 78 rejection_reason_(INVALID_CREDENTIALS) { | 78 rejection_reason_(INVALID_CREDENTIALS) { |
| 79 } | 79 } |
| 80 | 80 |
| 81 NegotiatingAuthenticator::~NegotiatingAuthenticator() { | 81 NegotiatingAuthenticator::~NegotiatingAuthenticator() { |
| 82 } | 82 } |
| 83 | 83 |
| 84 Authenticator::State NegotiatingAuthenticator::state() const { | 84 Authenticator::State NegotiatingAuthenticator::state() const { |
| 85 return state_; | 85 return state_; |
| 86 } | 86 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 methods_.push_back(method); | 202 methods_.push_back(method); |
| 203 } | 203 } |
| 204 | 204 |
| 205 scoped_ptr<ChannelAuthenticator> | 205 scoped_ptr<ChannelAuthenticator> |
| 206 NegotiatingAuthenticator::CreateChannelAuthenticator() const { | 206 NegotiatingAuthenticator::CreateChannelAuthenticator() const { |
| 207 DCHECK_EQ(state(), ACCEPTED); | 207 DCHECK_EQ(state(), ACCEPTED); |
| 208 return current_authenticator_->CreateChannelAuthenticator(); | 208 return current_authenticator_->CreateChannelAuthenticator(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool NegotiatingAuthenticator::is_host_side() const { | 211 bool NegotiatingAuthenticator::is_host_side() const { |
| 212 return local_private_key_.get() != NULL; | 212 return key_pair_.get() != NULL; |
| 213 } | 213 } |
| 214 | 214 |
| 215 void NegotiatingAuthenticator::CreateAuthenticator(State initial_state) { | 215 void NegotiatingAuthenticator::CreateAuthenticator(State initial_state) { |
| 216 if (is_host_side()) { | 216 if (is_host_side()) { |
| 217 current_authenticator_ = V2Authenticator::CreateForHost( | 217 current_authenticator_ = V2Authenticator::CreateForHost( |
| 218 local_cert_, *local_private_key_.get(), | 218 local_cert_, key_pair_->Copy(), |
| 219 shared_secret_hash_, initial_state); | 219 shared_secret_hash_, initial_state); |
| 220 } else { | 220 } else { |
| 221 current_authenticator_ = V2Authenticator::CreateForClient( | 221 current_authenticator_ = V2Authenticator::CreateForClient( |
| 222 AuthenticationMethod::ApplyHashFunction( | 222 AuthenticationMethod::ApplyHashFunction( |
| 223 current_method_.hash_function(), | 223 current_method_.hash_function(), |
| 224 authentication_tag_, shared_secret_), | 224 authentication_tag_, shared_secret_), initial_state); |
| 225 initial_state); | |
| 226 } | 225 } |
| 227 } | 226 } |
| 228 | 227 |
| 229 } // namespace protocol | 228 } // namespace protocol |
| 230 } // namespace remoting | 229 } // namespace remoting |
| OLD | NEW |