| 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/pairing_client_authenticator.h" | 5 #include "remoting/protocol/pairing_client_authenticator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/protocol/auth_util.h" | 10 #include "remoting/protocol/auth_util.h" |
| 11 #include "remoting/protocol/channel_authenticator.h" | 11 #include "remoting/protocol/channel_authenticator.h" |
| 12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 12 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 13 | 13 |
| 14 namespace remoting { | 14 namespace remoting { |
| 15 namespace protocol { | 15 namespace protocol { |
| 16 | 16 |
| 17 PairingClientAuthenticator::PairingClientAuthenticator( | 17 PairingClientAuthenticator::PairingClientAuthenticator( |
| 18 const std::string& client_id, | 18 const ClientAuthenticationConfig& client_auth_config, |
| 19 const std::string& paired_secret, | 19 const CreateBaseAuthenticatorCallback& create_base_authenticator_callback) |
| 20 const CreateBaseAuthenticatorCallback& create_base_authenticator_callback, | 20 : client_auth_config_(client_auth_config), |
| 21 const FetchSecretCallback& fetch_pin_callback, | |
| 22 const std::string& host_id) | |
| 23 : client_id_(client_id), | |
| 24 paired_secret_(paired_secret), | |
| 25 create_base_authenticator_callback_(create_base_authenticator_callback), | 21 create_base_authenticator_callback_(create_base_authenticator_callback), |
| 26 fetch_pin_callback_(fetch_pin_callback), | |
| 27 host_id_(host_id), | |
| 28 weak_factory_(this) { | 22 weak_factory_(this) { |
| 29 spake2_authenticator_ = | 23 spake2_authenticator_ = create_base_authenticator_callback_.Run( |
| 30 create_base_authenticator_callback_.Run(paired_secret_, MESSAGE_READY); | 24 client_auth_config.pairing_secret, MESSAGE_READY); |
| 31 using_paired_secret_ = true; | 25 using_paired_secret_ = true; |
| 32 } | 26 } |
| 33 | 27 |
| 34 PairingClientAuthenticator::~PairingClientAuthenticator() {} | 28 PairingClientAuthenticator::~PairingClientAuthenticator() {} |
| 35 | 29 |
| 36 Authenticator::State PairingClientAuthenticator::state() const { | 30 Authenticator::State PairingClientAuthenticator::state() const { |
| 37 if (waiting_for_pin_) | 31 if (waiting_for_pin_) |
| 38 return PROCESSING_MESSAGE; | 32 return PROCESSING_MESSAGE; |
| 39 return PairingAuthenticatorBase::state(); | 33 return PairingAuthenticatorBase::state(); |
| 40 } | 34 } |
| 41 | 35 |
| 42 void PairingClientAuthenticator::CreateSpakeAuthenticatorWithPin( | 36 void PairingClientAuthenticator::CreateSpakeAuthenticatorWithPin( |
| 43 State initial_state, | 37 State initial_state, |
| 44 const base::Closure& resume_callback) { | 38 const base::Closure& resume_callback) { |
| 45 DCHECK(!waiting_for_pin_); | 39 DCHECK(!waiting_for_pin_); |
| 46 waiting_for_pin_ = true; | 40 waiting_for_pin_ = true; |
| 47 fetch_pin_callback_.Run( | 41 client_auth_config_.fetch_secret_callback.Run( |
| 48 true, | 42 true, |
| 49 base::Bind(&PairingClientAuthenticator::OnPinFetched, | 43 base::Bind(&PairingClientAuthenticator::OnPinFetched, |
| 50 weak_factory_.GetWeakPtr(), initial_state, resume_callback)); | 44 weak_factory_.GetWeakPtr(), initial_state, resume_callback)); |
| 51 } | 45 } |
| 52 | 46 |
| 53 void PairingClientAuthenticator::AddPairingElements(buzz::XmlElement* message) { | 47 void PairingClientAuthenticator::AddPairingElements(buzz::XmlElement* message) { |
| 54 // If the client id and secret have not yet been sent, do so now. Note that | 48 // If the client id and secret have not yet been sent, do so now. Note that |
| 55 // in this case the V2Authenticator is being used optimistically to send the | 49 // in this case the V2Authenticator is being used optimistically to send the |
| 56 // first message of the SPAKE exchange since we don't yet know whether or not | 50 // first message of the SPAKE exchange since we don't yet know whether or not |
| 57 // the host will accept the client id or request that we fall back to the PIN. | 51 // the host will accept the client id or request that we fall back to the PIN. |
| 58 if (!sent_client_id_) { | 52 if (!sent_client_id_) { |
| 59 buzz::XmlElement* pairing_tag = new buzz::XmlElement(kPairingInfoTag); | 53 buzz::XmlElement* pairing_tag = new buzz::XmlElement(kPairingInfoTag); |
| 60 pairing_tag->AddAttr(kClientIdAttribute, client_id_); | 54 pairing_tag->AddAttr(kClientIdAttribute, |
| 55 client_auth_config_.pairing_client_id); |
| 61 message->AddElement(pairing_tag); | 56 message->AddElement(pairing_tag); |
| 62 sent_client_id_ = true; | 57 sent_client_id_ = true; |
| 63 } | 58 } |
| 64 } | 59 } |
| 65 | 60 |
| 66 void PairingClientAuthenticator::OnPinFetched( | 61 void PairingClientAuthenticator::OnPinFetched( |
| 67 State initial_state, | 62 State initial_state, |
| 68 const base::Closure& resume_callback, | 63 const base::Closure& resume_callback, |
| 69 const std::string& pin) { | 64 const std::string& pin) { |
| 70 DCHECK(waiting_for_pin_); | 65 DCHECK(waiting_for_pin_); |
| 71 DCHECK(!spake2_authenticator_); | 66 DCHECK(!spake2_authenticator_); |
| 72 waiting_for_pin_ = false; | 67 waiting_for_pin_ = false; |
| 73 spake2_authenticator_ = create_base_authenticator_callback_.Run( | 68 spake2_authenticator_ = create_base_authenticator_callback_.Run( |
| 74 GetSharedSecretHash(host_id_, pin), initial_state); | 69 GetSharedSecretHash(client_auth_config_.host_id, pin), initial_state); |
| 75 resume_callback.Run(); | 70 resume_callback.Run(); |
| 76 } | 71 } |
| 77 | 72 |
| 78 } // namespace protocol | 73 } // namespace protocol |
| 79 } // namespace remoting | 74 } // namespace remoting |
| OLD | NEW |