OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/protocol/pairing_client_authenticator.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/base/rsa_key_pair.h" |
| 11 #include "remoting/protocol/authentication_method.h" |
| 12 #include "remoting/protocol/channel_authenticator.h" |
| 13 #include "remoting/protocol/v2_authenticator.h" |
| 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 15 |
| 16 namespace remoting { |
| 17 namespace protocol { |
| 18 |
| 19 PairingClientAuthenticator::PairingClientAuthenticator( |
| 20 const std::string& client_id, |
| 21 const std::string& paired_secret, |
| 22 const FetchSecretCallback& fetch_pin_callback, |
| 23 const std::string& authentication_tag) |
| 24 : sent_client_id_(false), |
| 25 client_id_(client_id), |
| 26 paired_secret_(paired_secret), |
| 27 fetch_pin_callback_(fetch_pin_callback), |
| 28 authentication_tag_(authentication_tag), |
| 29 weak_factory_(this) { |
| 30 v2_authenticator_ = V2Authenticator::CreateForClient( |
| 31 paired_secret_, MESSAGE_READY); |
| 32 using_paired_secret_ = true; |
| 33 } |
| 34 |
| 35 void PairingClientAuthenticator::CreateV2AuthenticatorWithPIN( |
| 36 State initial_state, |
| 37 const SetAuthenticatorCallback& set_authenticator_callback) { |
| 38 SecretFetchedCallback callback = base::Bind( |
| 39 &PairingClientAuthenticator::OnPinFetched, |
| 40 weak_factory_.GetWeakPtr(), initial_state, set_authenticator_callback); |
| 41 fetch_pin_callback_.Run(callback); |
| 42 } |
| 43 |
| 44 scoped_ptr<Authenticator> |
| 45 PairingClientAuthenticator::CreateV2AuthenticatorFromInitialMessage( |
| 46 const buzz::XmlElement* message) { |
| 47 // The client always initiates the pairing protocol, so it will never be |
| 48 // asked to create a V2 authenticator based on the first message. |
| 49 NOTREACHED(); |
| 50 return scoped_ptr<Authenticator>(); |
| 51 } |
| 52 |
| 53 void PairingClientAuthenticator::AmendProtocolMessage( |
| 54 buzz::XmlElement* message) { |
| 55 // If the client id and secret have not yet been sent, do so now. Note that |
| 56 // in this case the V2Authenticator is being used optimistically to send the |
| 57 // first message of the SPAKE exchange since we don't yet know whether or not |
| 58 // the host will accept the client id or request that we fall back to the PIN. |
| 59 if (!sent_client_id_) { |
| 60 buzz::XmlElement* pairing_tag = new buzz::XmlElement(kPairingInfoTag); |
| 61 pairing_tag->AddAttr(kClientIdAttribute, client_id_); |
| 62 message->AddElement(pairing_tag); |
| 63 sent_client_id_ = true; |
| 64 } |
| 65 } |
| 66 |
| 67 void PairingClientAuthenticator::OnPinFetched( |
| 68 State initial_state, |
| 69 const SetAuthenticatorCallback& callback, |
| 70 const std::string& pin) { |
| 71 callback.Run(V2Authenticator::CreateForClient( |
| 72 AuthenticationMethod::ApplyHashFunction( |
| 73 AuthenticationMethod::HMAC_SHA256, |
| 74 authentication_tag_, pin), |
| 75 initial_state)); |
| 76 } |
| 77 |
| 78 } // namespace protocol |
| 79 } // namespace remoting |
OLD | NEW |