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

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

Issue 14793021: PairingAuthenticator implementation and plumbing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments. 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_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 Authenticator::State PairingHostAuthenticator::state() const {
33 if (protocol_error_) {
34 return REJECTED;
35 } else if (!v2_authenticator_) {
36 return WAITING_MESSAGE;
37 }
38 return PairingAuthenticatorBase::state();
39 }
40
41 Authenticator::RejectionReason
42 PairingHostAuthenticator::rejection_reason() const {
43 if (protocol_error_) {
44 return PROTOCOL_ERROR;
45 }
46 return PairingAuthenticatorBase::rejection_reason();
47 }
48
49 void PairingHostAuthenticator::CreateV2AuthenticatorWithPIN(
50 State initial_state,
51 const SetAuthenticatorCallback& callback) {
52 callback.Run(V2Authenticator::CreateForHost(
53 local_cert_, key_pair_, pin_, initial_state));
54 }
55
56 void PairingHostAuthenticator::ProcessMessage(
57 const buzz::XmlElement* message,
58 const base::Closure& resume_callback) {
59 if (!v2_authenticator_) {
60 std::string client_id;
61 std::string paired_secret;
62
63 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag);
64 if (pairing_tag) {
65 client_id = pairing_tag->Attr(kClientIdAttribute);
66 }
67
68 if (client_id.empty()) {
69 LOG(ERROR) << "No client id specified.";
70 protocol_error_ = true;
71 } else {
72 paired_secret = pairing_registry_->GetSecret(client_id);
73 if (paired_secret.empty()) {
74 LOG(INFO) << "Unknown client id";
75 error_message_ = "unknown-client-id";
76 }
77 }
78
79 using_paired_secret_ = !paired_secret.empty();
80 if (using_paired_secret_) {
81 v2_authenticator_ = V2Authenticator::CreateForHost(
82 local_cert_, key_pair_, paired_secret, WAITING_MESSAGE);
83 } else {
84 v2_authenticator_ = V2Authenticator::CreateForHost(
85 local_cert_, key_pair_, pin_, MESSAGE_READY);
86 // The client's optimistic SPAKE message is using a Paired Secret to
87 // which the host doesn't have access, so don't bother processing it.
88 resume_callback.Run();
89 return;
90 }
91 }
92
93 PairingAuthenticatorBase::ProcessMessage(message, resume_callback);
94 }
95
96 void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) {
97 // Nothing to do here
98 }
99
100 } // namespace protocol
101 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698