blob: 8983fe9ed1b67d98f4dc2f07f4eaf55e128286cd [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"
kjellanderf0e410b2017-01-04 14:45:0111#include "third_party/libjingle_xmpp/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
sergeyu843ef122016-03-17 01:44:1725void PairingHostAuthenticator::Initialize(
26 const std::string& client_id,
27 Authenticator::State preferred_initial_state,
28 const base::Closure& resume_callback) {
29 DCHECK(!spake2_authenticator_);
30
31 if (client_id.empty()) {
32 using_paired_secret_ = false;
33 error_message_ = "client-id-unknown";
34 spake2_authenticator_ =
35 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY);
36 resume_callback.Run();
37 return;
38 }
39
40 using_paired_secret_ = true;
41 waiting_for_paired_secret_ = true;
42 pairing_registry_->GetPairing(
43 client_id, base::Bind(&PairingHostAuthenticator::InitializeWithPairing,
44 weak_factory_.GetWeakPtr(), preferred_initial_state,
45 resume_callback));
46}
47
Chris Watkins6fe52aa2017-11-28 03:24:0548PairingHostAuthenticator::~PairingHostAuthenticator() = default;
[email protected]6434bfe2013-05-22 09:00:2349
50Authenticator::State PairingHostAuthenticator::state() const {
51 if (protocol_error_) {
52 return REJECTED;
[email protected]40dade32013-06-14 07:08:1153 } else if (waiting_for_paired_secret_) {
54 return PROCESSING_MESSAGE;
[email protected]6434bfe2013-05-22 09:00:2355 }
56 return PairingAuthenticatorBase::state();
57}
58
59Authenticator::RejectionReason
60PairingHostAuthenticator::rejection_reason() const {
61 if (protocol_error_) {
62 return PROTOCOL_ERROR;
63 }
64 return PairingAuthenticatorBase::rejection_reason();
65}
66
sergeyu12e320a2016-03-08 18:10:2867void PairingHostAuthenticator::CreateSpakeAuthenticatorWithPin(
[email protected]6434bfe2013-05-22 09:00:2368 State initial_state,
sergeyu12e320a2016-03-08 18:10:2869 const base::Closure& resume_callback) {
70 spake2_authenticator_ =
71 create_base_authenticator_callback_.Run(pin_, initial_state);
72 resume_callback.Run();
[email protected]6434bfe2013-05-22 09:00:2373}
74
sergeyu843ef122016-03-17 01:44:1775void PairingHostAuthenticator::InitializeWithPairing(
76 Authenticator::State preferred_initial_state,
[email protected]40dade32013-06-14 07:08:1177 const base::Closure& resume_callback,
78 PairingRegistry::Pairing pairing) {
sergeyu843ef122016-03-17 01:44:1779 DCHECK(waiting_for_paired_secret_);
[email protected]40dade32013-06-14 07:08:1180 waiting_for_paired_secret_ = false;
sergeyu843ef122016-03-17 01:44:1781 std::string pairing_secret = pairing.shared_secret();
82 if (pairing_secret.empty()) {
[email protected]5cbe3cf2013-11-25 17:05:0483 VLOG(0) << "Unknown client id";
[email protected]40dade32013-06-14 07:08:1184 error_message_ = "unknown-client-id";
sergeyu843ef122016-03-17 01:44:1785 using_paired_secret_ = false;
86 // If pairing wasn't found then always start in the MESSAGE_READY state.
sergeyu12e320a2016-03-08 18:10:2887 spake2_authenticator_ =
88 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY);
sergeyu843ef122016-03-17 01:44:1789 } else {
90 using_paired_secret_ = true;
91 spake2_authenticator_ = create_base_authenticator_callback_.Run(
92 pairing_secret, preferred_initial_state);
[email protected]40dade32013-06-14 07:08:1193 }
sergeyu843ef122016-03-17 01:44:1794 resume_callback.Run();
[email protected]40dade32013-06-14 07:08:1195}
96
[email protected]6434bfe2013-05-22 09:00:2397} // namespace protocol
98} // namespace remoting