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