Chromium Code Reviews| 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_host_authenticator.h" | 5 #include "remoting/protocol/pairing_host_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" | |
| 11 #include "remoting/protocol/channel_authenticator.h" | 10 #include "remoting/protocol/channel_authenticator.h" |
| 12 #include "remoting/protocol/v2_authenticator.h" | |
| 13 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 11 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| 14 | 12 |
| 15 namespace remoting { | 13 namespace remoting { |
| 16 namespace protocol { | 14 namespace protocol { |
| 17 | 15 |
| 18 PairingHostAuthenticator::PairingHostAuthenticator( | 16 PairingHostAuthenticator::PairingHostAuthenticator( |
| 19 scoped_refptr<PairingRegistry> pairing_registry, | 17 scoped_refptr<PairingRegistry> pairing_registry, |
| 20 const std::string& local_cert, | 18 const CreateBaseAuthenticatorCallback& create_base_authenticator_callback, |
| 21 scoped_refptr<RsaKeyPair> key_pair, | |
| 22 const std::string& pin) | 19 const std::string& pin) |
| 23 : pairing_registry_(pairing_registry), | 20 : pairing_registry_(pairing_registry), |
| 24 local_cert_(local_cert), | 21 create_base_authenticator_callback_(create_base_authenticator_callback), |
| 25 key_pair_(key_pair), | |
| 26 pin_(pin), | 22 pin_(pin), |
| 27 protocol_error_(false), | 23 weak_factory_(this) {} |
| 28 waiting_for_paired_secret_(false), | |
| 29 weak_factory_(this) { | |
| 30 } | |
| 31 | 24 |
| 32 PairingHostAuthenticator::~PairingHostAuthenticator() { | 25 PairingHostAuthenticator::~PairingHostAuthenticator() {} |
| 33 } | |
| 34 | 26 |
| 35 Authenticator::State PairingHostAuthenticator::state() const { | 27 Authenticator::State PairingHostAuthenticator::state() const { |
| 36 if (protocol_error_) { | 28 if (protocol_error_) { |
| 37 return REJECTED; | 29 return REJECTED; |
| 38 } else if (waiting_for_paired_secret_) { | 30 } else if (waiting_for_paired_secret_) { |
| 39 return PROCESSING_MESSAGE; | 31 return PROCESSING_MESSAGE; |
| 40 } else if (!v2_authenticator_) { | 32 } else if (!spake2_authenticator_) { |
| 41 return WAITING_MESSAGE; | 33 return WAITING_MESSAGE; |
| 42 } | 34 } |
| 43 return PairingAuthenticatorBase::state(); | 35 return PairingAuthenticatorBase::state(); |
| 44 } | 36 } |
| 45 | 37 |
| 46 Authenticator::RejectionReason | 38 Authenticator::RejectionReason |
| 47 PairingHostAuthenticator::rejection_reason() const { | 39 PairingHostAuthenticator::rejection_reason() const { |
| 48 if (protocol_error_) { | 40 if (protocol_error_) { |
| 49 return PROTOCOL_ERROR; | 41 return PROTOCOL_ERROR; |
| 50 } | 42 } |
| 51 return PairingAuthenticatorBase::rejection_reason(); | 43 return PairingAuthenticatorBase::rejection_reason(); |
| 52 } | 44 } |
| 53 | 45 |
| 54 void PairingHostAuthenticator::CreateV2AuthenticatorWithPIN( | 46 void PairingHostAuthenticator::CreateSpakeAuthenticatorWithPin( |
| 55 State initial_state, | 47 State initial_state, |
| 56 const SetAuthenticatorCallback& callback) { | 48 const base::Closure& resume_callback) { |
| 57 callback.Run(V2Authenticator::CreateForHost( | 49 spake2_authenticator_ = |
| 58 local_cert_, key_pair_, pin_, initial_state)); | 50 create_base_authenticator_callback_.Run(pin_, initial_state); |
| 51 resume_callback.Run(); | |
| 59 } | 52 } |
| 60 | 53 |
| 61 void PairingHostAuthenticator::ProcessMessage( | 54 void PairingHostAuthenticator::ProcessMessage( |
| 62 const buzz::XmlElement* message, | 55 const buzz::XmlElement* message, |
| 63 const base::Closure& resume_callback) { | 56 const base::Closure& resume_callback) { |
| 64 if (!v2_authenticator_) { | 57 if (!spake2_authenticator_) { |
| 65 std::string client_id; | 58 std::string client_id; |
| 66 | 59 |
| 67 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag); | 60 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag); |
| 68 if (pairing_tag) { | 61 if (pairing_tag) { |
| 69 client_id = pairing_tag->Attr(kClientIdAttribute); | 62 client_id = pairing_tag->Attr(kClientIdAttribute); |
| 70 } | 63 } |
| 71 | 64 |
| 72 if (client_id.empty()) { | 65 if (client_id.empty()) { |
| 73 LOG(ERROR) << "No client id specified."; | 66 LOG(ERROR) << "No client id specified."; |
| 74 protocol_error_ = true; | 67 protocol_error_ = true; |
| 75 } else { | |
| 76 waiting_for_paired_secret_ = true; | |
| 77 pairing_registry_->GetPairing( | |
| 78 client_id, | |
| 79 base::Bind(&PairingHostAuthenticator::ProcessMessageWithPairing, | |
| 80 weak_factory_.GetWeakPtr(), | |
| 81 base::Owned(new buzz::XmlElement(*message)), | |
| 82 resume_callback)); | |
| 83 return; | 68 return; |
|
Jamie
2016/03/07 21:40:19
This is a change in semantics: if there is no clie
Sergey Ulanov
2016/03/07 22:45:05
Yes, it's intentional. It doesn't make sense to ca
| |
| 84 } | 69 } |
| 70 | |
| 71 waiting_for_paired_secret_ = true; | |
| 72 pairing_registry_->GetPairing( | |
| 73 client_id, | |
| 74 base::Bind(&PairingHostAuthenticator::ProcessMessageWithPairing, | |
| 75 weak_factory_.GetWeakPtr(), | |
| 76 base::Owned(new buzz::XmlElement(*message)), | |
| 77 resume_callback)); | |
| 78 return; | |
| 85 } | 79 } |
| 86 | 80 |
| 87 PairingAuthenticatorBase::ProcessMessage(message, resume_callback); | 81 PairingAuthenticatorBase::ProcessMessage(message, resume_callback); |
| 88 } | 82 } |
| 89 | 83 |
| 90 void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) { | 84 void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) { |
| 91 // Nothing to do here | 85 // Nothing to do here |
| 92 } | 86 } |
| 93 | 87 |
| 94 void PairingHostAuthenticator::ProcessMessageWithPairing( | 88 void PairingHostAuthenticator::ProcessMessageWithPairing( |
| 95 const buzz::XmlElement* message, | 89 const buzz::XmlElement* message, |
| 96 const base::Closure& resume_callback, | 90 const base::Closure& resume_callback, |
| 97 PairingRegistry::Pairing pairing) { | 91 PairingRegistry::Pairing pairing) { |
| 98 waiting_for_paired_secret_ = false; | 92 waiting_for_paired_secret_ = false; |
| 99 std::string paired_secret = pairing.shared_secret(); | 93 std::string paired_secret = pairing.shared_secret(); |
| 100 if (paired_secret.empty()) { | 94 if (paired_secret.empty()) { |
| 101 VLOG(0) << "Unknown client id"; | 95 VLOG(0) << "Unknown client id"; |
| 102 error_message_ = "unknown-client-id"; | 96 error_message_ = "unknown-client-id"; |
| 103 } | 97 } |
| 104 | 98 |
| 105 using_paired_secret_ = !paired_secret.empty(); | 99 using_paired_secret_ = !paired_secret.empty(); |
| 106 if (using_paired_secret_) { | 100 if (using_paired_secret_) { |
| 107 v2_authenticator_ = V2Authenticator::CreateForHost( | 101 spake2_authenticator_ = |
| 108 local_cert_, key_pair_, paired_secret, WAITING_MESSAGE); | 102 create_base_authenticator_callback_.Run(paired_secret, WAITING_MESSAGE); |
| 109 PairingAuthenticatorBase::ProcessMessage(message, resume_callback); | 103 PairingAuthenticatorBase::ProcessMessage(message, resume_callback); |
| 110 } else { | 104 } else { |
| 111 v2_authenticator_ = V2Authenticator::CreateForHost( | 105 spake2_authenticator_ = |
| 112 local_cert_, key_pair_, pin_, MESSAGE_READY); | 106 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY); |
| 113 // The client's optimistic SPAKE message is using a Paired Secret to | 107 // The client's optimistic SPAKE message is using a Paired Secret to |
| 114 // which the host doesn't have access, so don't bother processing it. | 108 // which the host doesn't have access, so don't bother processing it. |
| 115 resume_callback.Run(); | 109 resume_callback.Run(); |
| 116 } | 110 } |
| 117 } | 111 } |
| 118 | 112 |
| 119 } // namespace protocol | 113 } // namespace protocol |
| 120 } // namespace remoting | 114 } // namespace remoting |
| OLD | NEW |