blob: b00a5c76f4104408ba73c67fcd779d9b71b3ff26 [file] [log] [blame]
[email protected]6434bfe2013-05-22 09:00:231// 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"
[email protected]6434bfe2013-05-22 09:00:2310#include "remoting/protocol/channel_authenticator.h"
niklaseaf726f12014-09-08 18:43:0211#include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
[email protected]6434bfe2013-05-22 09:00:2312
13namespace remoting {
14namespace protocol {
15
16PairingHostAuthenticator::PairingHostAuthenticator(
17 scoped_refptr<PairingRegistry> pairing_registry,
sergeyu12e320a2016-03-08 18:10:2818 const CreateBaseAuthenticatorCallback& create_base_authenticator_callback,
[email protected]6434bfe2013-05-22 09:00:2319 const std::string& pin)
20 : pairing_registry_(pairing_registry),
sergeyu12e320a2016-03-08 18:10:2821 create_base_authenticator_callback_(create_base_authenticator_callback),
[email protected]6434bfe2013-05-22 09:00:2322 pin_(pin),
sergeyu12e320a2016-03-08 18:10:2823 weak_factory_(this) {}
[email protected]6434bfe2013-05-22 09:00:2324
sergeyu12e320a2016-03-08 18:10:2825PairingHostAuthenticator::~PairingHostAuthenticator() {}
[email protected]6434bfe2013-05-22 09:00:2326
27Authenticator::State PairingHostAuthenticator::state() const {
28 if (protocol_error_) {
29 return REJECTED;
[email protected]40dade32013-06-14 07:08:1130 } else if (waiting_for_paired_secret_) {
31 return PROCESSING_MESSAGE;
sergeyu12e320a2016-03-08 18:10:2832 } else if (!spake2_authenticator_) {
[email protected]6434bfe2013-05-22 09:00:2333 return WAITING_MESSAGE;
34 }
35 return PairingAuthenticatorBase::state();
36}
37
38Authenticator::RejectionReason
39PairingHostAuthenticator::rejection_reason() const {
40 if (protocol_error_) {
41 return PROTOCOL_ERROR;
42 }
43 return PairingAuthenticatorBase::rejection_reason();
44}
45
sergeyu12e320a2016-03-08 18:10:2846void PairingHostAuthenticator::CreateSpakeAuthenticatorWithPin(
[email protected]6434bfe2013-05-22 09:00:2347 State initial_state,
sergeyu12e320a2016-03-08 18:10:2848 const base::Closure& resume_callback) {
49 spake2_authenticator_ =
50 create_base_authenticator_callback_.Run(pin_, initial_state);
51 resume_callback.Run();
[email protected]6434bfe2013-05-22 09:00:2352}
53
54void PairingHostAuthenticator::ProcessMessage(
55 const buzz::XmlElement* message,
56 const base::Closure& resume_callback) {
sergeyu12e320a2016-03-08 18:10:2857 if (!spake2_authenticator_) {
[email protected]6434bfe2013-05-22 09:00:2358 std::string client_id;
[email protected]6434bfe2013-05-22 09:00:2359
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;
[email protected]6434bfe2013-05-22 09:00:2368 return;
69 }
sergeyu12e320a2016-03-08 18:10:2870
71 waiting_for_paired_secret_ = true;
72 pairing_registry_->GetPairing(
73 client_id,
74 base::Bind(&PairingHostAuthenticator::ProcessMessageWithPairing,
75 weak_factory_.GetWeakPtr(),
76 base::Owned(new buzz::XmlElement(*message)),
77 resume_callback));
78 return;
[email protected]6434bfe2013-05-22 09:00:2379 }
80
81 PairingAuthenticatorBase::ProcessMessage(message, resume_callback);
82}
83
84void PairingHostAuthenticator::AddPairingElements(buzz::XmlElement* message) {
85 // Nothing to do here
86}
87
[email protected]40dade32013-06-14 07:08:1188void PairingHostAuthenticator::ProcessMessageWithPairing(
89 const buzz::XmlElement* message,
90 const base::Closure& resume_callback,
91 PairingRegistry::Pairing pairing) {
92 waiting_for_paired_secret_ = false;
[email protected]df5189f2013-06-18 12:12:0593 std::string paired_secret = pairing.shared_secret();
[email protected]40dade32013-06-14 07:08:1194 if (paired_secret.empty()) {
[email protected]5cbe3cf2013-11-25 17:05:0495 VLOG(0) << "Unknown client id";
[email protected]40dade32013-06-14 07:08:1196 error_message_ = "unknown-client-id";
97 }
98
99 using_paired_secret_ = !paired_secret.empty();
100 if (using_paired_secret_) {
sergeyu12e320a2016-03-08 18:10:28101 spake2_authenticator_ =
102 create_base_authenticator_callback_.Run(paired_secret, WAITING_MESSAGE);
[email protected]40dade32013-06-14 07:08:11103 PairingAuthenticatorBase::ProcessMessage(message, resume_callback);
104 } else {
sergeyu12e320a2016-03-08 18:10:28105 spake2_authenticator_ =
106 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY);
[email protected]40dade32013-06-14 07:08:11107 // The client's optimistic SPAKE message is using a Paired Secret to
108 // which the host doesn't have access, so don't bother processing it.
109 resume_callback.Run();
110 }
111}
112
[email protected]6434bfe2013-05-22 09:00:23113} // namespace protocol
114} // namespace remoting