Chromium Code Reviews| 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/logging.h" | |
| 8 #include "remoting/base/constants.h" | |
| 9 #include "remoting/base/rsa_key_pair.h" | |
| 10 #include "remoting/protocol/channel_authenticator.h" | |
| 11 #include "remoting/protocol/pairing_registry.h" | |
| 12 #include "remoting/protocol/v2_authenticator.h" | |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | |
| 14 | |
| 15 namespace remoting { | |
| 16 namespace protocol { | |
| 17 | |
| 18 namespace { | |
| 19 const buzz::StaticQName kPairingInfoQName = | |
| 20 { kChromotingXmlNamespace, "pairing-info" }; | |
| 21 const buzz::StaticQName kClientIdAttributeQName = | |
| 22 { "", "client-id" }; | |
| 23 const buzz::StaticQName kPairingFailedQName = | |
| 24 { kChromotingXmlNamespace, "pairing-failed" }; | |
| 25 const buzz::StaticQName kPairingErrorQName = | |
| 26 { "", "error" }; | |
| 27 } | |
| 28 | |
| 29 PairingHostAuthenticator::PairingHostAuthenticator( | |
| 30 scoped_refptr<PairingRegistry> pairing_registry, | |
| 31 const std::string& local_cert, | |
| 32 scoped_refptr<RsaKeyPair> key_pair, | |
| 33 const std::string& shared_secret, | |
| 34 State initial_state) | |
| 35 : pairing_registry_(pairing_registry), | |
| 36 local_cert_(local_cert), | |
| 37 key_pair_(key_pair), | |
| 38 shared_secret_(shared_secret), | |
| 39 initial_state_(initial_state) { | |
| 40 // If the client didn't specify an initial message, use the PIN as the shared | |
|
rmsousa
2013/05/15 01:25:16
This implies a stronger protocol requirement (i.e.
Jamie
2013/05/15 23:41:08
Do my changes to the header comments address this
| |
| 41 // secret. If it did, the authenticator will be created in ProcessMessage with | |
| 42 // the appropriate secret from the pairing registry. | |
| 43 if (initial_state_ != WAITING_MESSAGE) { | |
|
rmsousa
2013/05/15 01:25:16
Nit: please DCHECK_EQ(initial_state_, MESSAGE_READ
Jamie
2013/05/15 23:41:08
Done.
| |
| 44 CreateV2AuthenticatorWithPIN(); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 Authenticator::State PairingHostAuthenticator::state() const { | |
| 49 if (!error_message_.empty()) { | |
| 50 return MESSAGE_READY; | |
| 51 } | |
| 52 if (v2_authenticator_) { | |
| 53 return v2_authenticator_->state(); | |
| 54 } | |
| 55 return initial_state_; | |
|
rmsousa
2013/05/15 01:25:16
Please either have an actual state_ variable, or u
Jamie
2013/05/15 23:41:08
An explicit state variable makes less sense that i
| |
| 56 } | |
| 57 | |
| 58 Authenticator::RejectionReason | |
| 59 PairingHostAuthenticator::rejection_reason() const { | |
| 60 DCHECK(v2_authenticator_); | |
| 61 return v2_authenticator_->rejection_reason(); | |
| 62 } | |
| 63 | |
| 64 void PairingHostAuthenticator::ProcessMessage( | |
| 65 const buzz::XmlElement* message, | |
| 66 const base::Closure& resume_callback) { | |
|
rmsousa
2013/05/15 01:25:16
DCHECK_EQ(state(), WAITING_MESSAGE)
Jamie
2013/05/15 23:41:08
Done.
| |
| 67 // If there's already an underlying authenticator, defer to it. | |
| 68 if (v2_authenticator_) { | |
| 69 v2_authenticator_->ProcessMessage(message, resume_callback); | |
|
rmsousa
2013/05/15 01:25:16
please DCHECK the v2_authenticator_ state here.
Jamie
2013/05/15 23:41:08
Done.
| |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 // If not, then create one based on the contents of the first message. | |
| 74 std::string client_id; | |
| 75 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoQName); | |
| 76 if (pairing_tag) { | |
| 77 client_id = pairing_tag->Attr(kClientIdAttributeQName); | |
| 78 } | |
| 79 | |
| 80 if (client_id.empty()) { | |
| 81 error_message_ = "missing-client-id"; | |
| 82 CreateV2AuthenticatorWithPIN(); | |
| 83 resume_callback.Run(); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 std::string paired_secret = pairing_registry_->GetSecret(client_id); | |
| 88 | |
| 89 if (paired_secret.empty()) { | |
| 90 error_message_ = "unknown-client-id"; | |
| 91 CreateV2AuthenticatorWithPIN(); | |
| 92 resume_callback.Run(); | |
| 93 return; | |
| 94 } | |
| 95 | |
| 96 v2_authenticator_ = V2Authenticator::CreateForHost( | |
| 97 local_cert_, key_pair_, paired_secret, MESSAGE_READY); | |
| 98 resume_callback.Run(); | |
| 99 } | |
| 100 | |
| 101 scoped_ptr<buzz::XmlElement> PairingHostAuthenticator::GetNextMessage() { | |
|
rmsousa
2013/05/15 01:25:16
DCHECK_EQ(state(), MESSAGE_READY)
Jamie
2013/05/15 23:41:08
Done.
| |
| 102 if (!error_message_.empty()) { | |
| 103 scoped_ptr<buzz::XmlElement> result = CreateEmptyAuthenticatorMessage(); | |
| 104 buzz::XmlElement* pairing_failed_tag = | |
| 105 new buzz::XmlElement(kPairingFailedQName); | |
| 106 pairing_failed_tag->AddAttr(kPairingErrorQName, error_message_); | |
| 107 result->AddElement(pairing_failed_tag); | |
| 108 error_message_.clear(); | |
| 109 return result.Pass(); | |
| 110 } else { | |
| 111 DCHECK(v2_authenticator_); | |
| 112 return v2_authenticator_->GetNextMessage(); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 scoped_ptr<ChannelAuthenticator> | |
| 117 PairingHostAuthenticator::CreateChannelAuthenticator() const { | |
| 118 DCHECK(v2_authenticator_); | |
| 119 return v2_authenticator_->CreateChannelAuthenticator(); | |
| 120 } | |
| 121 | |
| 122 void PairingHostAuthenticator::CreateV2AuthenticatorWithPIN() { | |
| 123 DCHECK(!v2_authenticator_); | |
| 124 v2_authenticator_ = V2Authenticator::CreateForHost( | |
| 125 local_cert_, key_pair_, shared_secret_, initial_state_); | |
|
rmsousa
2013/05/15 01:25:16
Using initial_state_ is weird here. There are seve
Jamie
2013/05/15 23:41:08
It doesn't always send the first message. If the c
rmsousa
2013/05/16 00:46:25
Yes, I was saying that this variation was confusin
Jamie
2013/05/16 19:30:16
Okay, I understand now. I agree, your approach is
| |
| 126 } | |
| 127 | |
| 128 } // namespace protocol | |
| 129 } // namespace remoting | |
| OLD | NEW |