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

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

Issue 16893002: Make the mapping from client id -> secret asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang errors. Created 7 years, 6 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
« no previous file with comments | « remoting/protocol/pairing_host_authenticator.h ('k') | remoting/protocol/pairing_registry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 10 #include "remoting/base/rsa_key_pair.h"
11 #include "remoting/protocol/channel_authenticator.h" 11 #include "remoting/protocol/channel_authenticator.h"
12 #include "remoting/protocol/pairing_registry.h"
13 #include "remoting/protocol/v2_authenticator.h" 12 #include "remoting/protocol/v2_authenticator.h"
14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
15 14
16 namespace remoting { 15 namespace remoting {
17 namespace protocol { 16 namespace protocol {
18 17
19 PairingHostAuthenticator::PairingHostAuthenticator( 18 PairingHostAuthenticator::PairingHostAuthenticator(
20 scoped_refptr<PairingRegistry> pairing_registry, 19 scoped_refptr<PairingRegistry> pairing_registry,
21 const std::string& local_cert, 20 const std::string& local_cert,
22 scoped_refptr<RsaKeyPair> key_pair, 21 scoped_refptr<RsaKeyPair> key_pair,
23 const std::string& pin) 22 const std::string& pin)
24 : pairing_registry_(pairing_registry), 23 : pairing_registry_(pairing_registry),
25 local_cert_(local_cert), 24 local_cert_(local_cert),
26 key_pair_(key_pair), 25 key_pair_(key_pair),
27 pin_(pin), 26 pin_(pin),
28 protocol_error_(false), 27 protocol_error_(false),
28 waiting_for_paired_secret_(false),
29 weak_factory_(this) { 29 weak_factory_(this) {
30 } 30 }
31 31
32 PairingHostAuthenticator::~PairingHostAuthenticator() { 32 PairingHostAuthenticator::~PairingHostAuthenticator() {
33 } 33 }
34 34
35 Authenticator::State PairingHostAuthenticator::state() const { 35 Authenticator::State PairingHostAuthenticator::state() const {
36 if (protocol_error_) { 36 if (protocol_error_) {
37 return REJECTED; 37 return REJECTED;
38 } else if (waiting_for_paired_secret_) {
39 return PROCESSING_MESSAGE;
38 } else if (!v2_authenticator_) { 40 } else if (!v2_authenticator_) {
39 return WAITING_MESSAGE; 41 return WAITING_MESSAGE;
40 } 42 }
41 return PairingAuthenticatorBase::state(); 43 return PairingAuthenticatorBase::state();
42 } 44 }
43 45
44 Authenticator::RejectionReason 46 Authenticator::RejectionReason
45 PairingHostAuthenticator::rejection_reason() const { 47 PairingHostAuthenticator::rejection_reason() const {
46 if (protocol_error_) { 48 if (protocol_error_) {
47 return PROTOCOL_ERROR; 49 return PROTOCOL_ERROR;
(...skipping 17 matching lines...) Expand all
65 67
66 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag); 68 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag);
67 if (pairing_tag) { 69 if (pairing_tag) {
68 client_id = pairing_tag->Attr(kClientIdAttribute); 70 client_id = pairing_tag->Attr(kClientIdAttribute);
69 } 71 }
70 72
71 if (client_id.empty()) { 73 if (client_id.empty()) {
72 LOG(ERROR) << "No client id specified."; 74 LOG(ERROR) << "No client id specified.";
73 protocol_error_ = true; 75 protocol_error_ = true;
74 } else { 76 } else {
75 paired_secret = pairing_registry_->GetSecret(client_id); 77 waiting_for_paired_secret_ = true;
76 if (paired_secret.empty()) { 78 pairing_registry_->GetPairing(
77 LOG(INFO) << "Unknown client id"; 79 client_id,
78 error_message_ = "unknown-client-id"; 80 base::Bind(&PairingHostAuthenticator::ProcessMessageWithPairing,
79 } 81 weak_factory_.GetWeakPtr(),
80 } 82 base::Owned(new buzz::XmlElement(*message)),
81 83 resume_callback));
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; 84 return;
93 } 85 }
94 } 86 }
95 87
96 PairingAuthenticatorBase::ProcessMessage(message, resume_callback); 88 PairingAuthenticatorBase::ProcessMessage(message, resume_callback);
97 } 89 }
98 90
99 void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) { 91 void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) {
100 // Nothing to do here 92 // Nothing to do here
101 } 93 }
102 94
95 void PairingHostAuthenticator::ProcessMessageWithPairing(
96 const buzz::XmlElement* message,
97 const base::Closure& resume_callback,
98 PairingRegistry::Pairing pairing) {
99 waiting_for_paired_secret_ = false;
100 std::string paired_secret = pairing.shared_secret;
101 if (paired_secret.empty()) {
102 LOG(INFO) << "Unknown client id";
103 error_message_ = "unknown-client-id";
104 }
105
106 using_paired_secret_ = !paired_secret.empty();
107 if (using_paired_secret_) {
108 v2_authenticator_ = V2Authenticator::CreateForHost(
109 local_cert_, key_pair_, paired_secret, WAITING_MESSAGE);
110 PairingAuthenticatorBase::ProcessMessage(message, resume_callback);
111 } else {
112 v2_authenticator_ = V2Authenticator::CreateForHost(
113 local_cert_, key_pair_, pin_, MESSAGE_READY);
114 // The client's optimistic SPAKE message is using a Paired Secret to
115 // which the host doesn't have access, so don't bother processing it.
116 resume_callback.Run();
117 }
118 }
119
103 } // namespace protocol 120 } // namespace protocol
104 } // namespace remoting 121 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/pairing_host_authenticator.h ('k') | remoting/protocol/pairing_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698