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

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: Refactored common host- and client-side code into common base. 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 }
36 return PairingAuthenticatorBase::state();
37 }
38
39 Authenticator::RejectionReason
40 PairingHostAuthenticator::rejection_reason() const {
41 if (protocol_error_) {
42 return PROTOCOL_ERROR;
43 }
44 return PairingAuthenticatorBase::rejection_reason();
45 }
46
47 void PairingHostAuthenticator::CreateV2AuthenticatorWithPIN(
48 State initial_state,
49 const SetAuthenticatorCallback& callback) {
50 callback.Run(V2Authenticator::CreateForHost(
51 local_cert_, key_pair_, pin_, initial_state));
52 }
53
54 scoped_ptr<Authenticator>
55 PairingHostAuthenticator::CreateV2AuthenticatorFromInitialMessage(
56 const buzz::XmlElement* message) {
57 std::string client_id;
58 std::string paired_secret;
59
60 const buzz::XmlElement* pairing_tag = message->FirstNamed(kPairingInfoTag);
61 if (pairing_tag) {
62 client_id = pairing_tag->Attr(kClientIdAttribute);
63 }
64
65 if (client_id.empty()) {
66 LOG(ERROR) << "No client id specified.";
67 protocol_error_ = true;
68 } else {
69 paired_secret = pairing_registry_->GetSecret(client_id);
70 if (paired_secret.empty()) {
71 LOG(INFO) << "Unknown client id";
72 error_message_ = "unknown-client-id";
73 }
74 }
75
76 using_paired_secret_ = !paired_secret.empty();
77 if (using_paired_secret_) {
78 return scoped_ptr<Authenticator>(V2Authenticator::CreateForHost(
79 local_cert_, key_pair_, paired_secret, WAITING_MESSAGE));
80 } else {
81 return scoped_ptr<Authenticator>(V2Authenticator::CreateForHost(
82 local_cert_, key_pair_, pin_, MESSAGE_READY));
83 }
84 }
85
86 void PairingHostAuthenticator::AmendProtocolMessage(buzz::XmlElement* message) {
87 // Nothing to do here
88 }
89
90 } // namespace protocol
91 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698