Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: remoting/protocol/pairing_client_authenticator.cc

Issue 14793021: PairingAuthenticator implementation and plumbing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 namespace {
20 const buzz::StaticQName kPairingQName =
rmsousa 2013/05/15 01:25:16 Nit: We use kPairingTag for tags inside an authent
rmsousa 2013/05/15 01:25:16 Nit: I'd prefer if these were in a shared place, a
Jamie 2013/05/15 23:41:08 Done.
Jamie 2013/05/15 23:41:08 Done.
21 { kChromotingXmlNamespace, "pairing-info" };
22 const buzz::StaticQName kClientIdAttributeQName =
23 { "", "client-id" };
24 const buzz::StaticQName kPairingFailedQName =
25 { kChromotingXmlNamespace, "pairing-failed" };
26 const buzz::StaticQName kPairingErrorQName =
27 { "", "error" };
28 }
29
30 PairingClientAuthenticator::PairingClientAuthenticator(
31 const std::string& client_id,
32 const std::string& shared_secret,
33 const FetchSecretCallback& fetch_secret_callback,
34 const std::string& authentication_tag)
35 : initial_message_sent_(false),
36 client_id_(client_id),
37 shared_secret_(shared_secret),
38 fetch_secret_callback_(fetch_secret_callback),
39 authentication_tag_(authentication_tag),
40 pairing_failed_(false),
41 weak_factory_(this) {
42 v2_authenticator_ = V2Authenticator::CreateForClient(
rmsousa 2013/05/15 01:25:16 There is no need to create this underlying authent
Jamie 2013/05/15 23:41:08 Done.
43 shared_secret_, WAITING_MESSAGE);
44 }
45
46 Authenticator::State PairingClientAuthenticator::state() const {
47 if (!initial_message_sent_) {
48 return MESSAGE_READY;
49 } else if (!v2_authenticator_) {
50 return PROCESSING_MESSAGE;
51 }
52 return v2_authenticator_->state();
53 }
54
55 Authenticator::RejectionReason
56 PairingClientAuthenticator::rejection_reason() const {
57 DCHECK(v2_authenticator_);
58 return v2_authenticator_->rejection_reason();
59 }
60
61 void PairingClientAuthenticator::ProcessMessage(
62 const buzz::XmlElement* message,
63 const base::Closure& resume_callback) {
64 const buzz::XmlElement* pairing_failed_tag =
65 message->FirstNamed(kPairingFailedQName);
66 if (pairing_failed_tag) {
67 // If pairing failed, prompt the user for the PIN and try again.
68 std::string error = pairing_failed_tag->Attr(kPairingErrorQName);
69 LOG(INFO) << "Pairing failed: " << error;
70 v2_authenticator_.reset();
71 SecretFetchedCallback callback = base::Bind(
72 &PairingClientAuthenticator::CreateV2AuthenticatorWithSecret,
73 weak_factory_.GetWeakPtr(), resume_callback);
rmsousa 2013/05/16 22:16:37 (Comment for a future CL, when you implement the U
Jamie 2013/05/16 22:57:46 Good point.
74 fetch_secret_callback_.Run(callback);
75 return;
76 }
77 v2_authenticator_->ProcessMessage(message, resume_callback);
78 }
79
80 scoped_ptr<buzz::XmlElement> PairingClientAuthenticator::GetNextMessage() {
81 // If the initial message has not yet been sent, return it now.
82 if (!initial_message_sent_) {
rmsousa 2013/05/15 01:25:16 This is wrong when the host sends the first messag
Jamie 2013/05/15 23:41:08 My understanding is that the client always sends t
rmsousa 2013/05/16 00:46:25 No. If the client does not have a client ID, the c
Jamie 2013/05/16 19:30:16 Okay, I think we're talking at cross-purposes here
rmsousa 2013/05/16 20:12:59 Oh. I just realized that - CreateAuthenticator wil
Jamie 2013/05/16 21:09:09 I don't think that's true. The PairingSupportedBut
rmsousa 2013/05/16 22:16:37 Oh, I think I misunderstood your design. I was ass
Jamie 2013/05/16 22:57:46 That's correct.
rmsousa 2013/05/16 23:22:24 Oh, OK, we're in the same page, then.
Jamie 2013/05/17 17:55:45 I tried using the pairing authenticator for the ex
83 scoped_ptr<buzz::XmlElement> result = CreateEmptyAuthenticatorMessage();
84 buzz::XmlElement* pairing_tag = new buzz::XmlElement(kPairingQName);
85 pairing_tag->AddAttr(kClientIdAttributeQName, client_id_);
86 result->AddElement(pairing_tag);
87 initial_message_sent_ = true;
88 return result.Pass();
89 }
90 // In all other cases, defer to the underlying authenticator.
91 return v2_authenticator_->GetNextMessage();
92 }
93
94 scoped_ptr<ChannelAuthenticator>
95 PairingClientAuthenticator::CreateChannelAuthenticator() const {
96 return v2_authenticator_->CreateChannelAuthenticator();
97 }
98
99 void PairingClientAuthenticator::CreateV2AuthenticatorWithSecret(
100 const base::Closure& resume_callback,
101 const std::string& shared_secret) {
102 v2_authenticator_ = V2Authenticator::CreateForClient(
103 AuthenticationMethod::ApplyHashFunction(
104 AuthenticationMethod::HMAC_SHA256,
105 authentication_tag_, shared_secret),
106 MESSAGE_READY);
107 resume_callback.Run();
108 }
109
110 } // namespace protocol
111 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698