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_host_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/channel_authenticator.h" |
| 12 #include "remoting/protocol/pairing_registry.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 PairingHostAuthenticator::PairingHostAuthenticator( |
| 20 scoped_refptr<PairingRegistry> pairing_registry, |
| 21 const std::string& local_cert, |
| 22 scoped_refptr<RsaKeyPair> key_pair, |
| 23 const std::string& pin) |
| 24 : pairing_registry_(pairing_registry), |
| 25 local_cert_(local_cert), |
| 26 key_pair_(key_pair), |
| 27 pin_(pin), |
| 28 protocol_error_(false), |
| 29 weak_factory_(this) { |
| 30 } |
| 31 |
| 32 PairingHostAuthenticator::~PairingHostAuthenticator() { |
| 33 } |
| 34 |
| 35 Authenticator::State PairingHostAuthenticator::state() const { |
| 36 if (protocol_error_) { |
| 37 return REJECTED; |
| 38 } else if (!v2_authenticator_) { |
| 39 return WAITING_MESSAGE; |
| 40 } |
| 41 return PairingAuthenticatorBase::state(); |
| 42 } |
| 43 |
| 44 Authenticator::RejectionReason |
| 45 PairingHostAuthenticator::rejection_reason() const { |
| 46 if (protocol_error_) { |
| 47 return PROTOCOL_ERROR; |
| 48 } |
| 49 return PairingAuthenticatorBase::rejection_reason(); |
| 50 } |
| 51 |
| 52 void PairingHostAuthenticator::CreateV2AuthenticatorWithPIN( |
| 53 State initial_state, |
| 54 const SetAuthenticatorCallback& callback) { |
| 55 callback.Run(V2Authenticator::CreateForHost( |
| 56 local_cert_, key_pair_, pin_, initial_state)); |
| 57 } |
| 58 |
| 59 void PairingHostAuthenticator::ProcessMessage( |
| 60 const buzz::XmlElement* message, |
| 61 const base::Closure& resume_callback) { |
| 62 if (!v2_authenticator_) { |
| 63 std::string client_id; |
| 64 std::string paired_secret; |
| 65 |
| 66 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag); |
| 67 if (pairing_tag) { |
| 68 client_id = pairing_tag->Attr(kClientIdAttribute); |
| 69 } |
| 70 |
| 71 if (client_id.empty()) { |
| 72 LOG(ERROR) << "No client id specified."; |
| 73 protocol_error_ = true; |
| 74 } else { |
| 75 paired_secret = pairing_registry_->GetSecret(client_id); |
| 76 if (paired_secret.empty()) { |
| 77 LOG(INFO) << "Unknown client id"; |
| 78 error_message_ = "unknown-client-id"; |
| 79 } |
| 80 } |
| 81 |
| 82 using_paired_secret_ = !paired_secret.empty(); |
| 83 if (using_paired_secret_) { |
| 84 v2_authenticator_ = V2Authenticator::CreateForHost( |
| 85 local_cert_, key_pair_, paired_secret, WAITING_MESSAGE); |
| 86 } else { |
| 87 v2_authenticator_ = V2Authenticator::CreateForHost( |
| 88 local_cert_, key_pair_, pin_, MESSAGE_READY); |
| 89 // The client's optimistic SPAKE message is using a Paired Secret to |
| 90 // which the host doesn't have access, so don't bother processing it. |
| 91 resume_callback.Run(); |
| 92 return; |
| 93 } |
| 94 } |
| 95 |
| 96 PairingAuthenticatorBase::ProcessMessage(message, resume_callback); |
| 97 } |
| 98 |
| 99 void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) { |
| 100 // Nothing to do here |
| 101 } |
| 102 |
| 103 } // namespace protocol |
| 104 } // namespace remoting |
OLD | NEW |