blob: b7e7e5f6b87281bd670837ac37e16a5925d548b3 [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
Daniel Cheng28a5ac482021-02-22 21:03:087#include <utility>
8
[email protected]6434bfe2013-05-22 09:00:239#include "base/bind.h"
10#include "base/logging.h"
11#include "remoting/base/constants.h"
[email protected]6434bfe2013-05-22 09:00:2312#include "remoting/protocol/channel_authenticator.h"
kjellanderf0e410b2017-01-04 14:45:0113#include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
[email protected]6434bfe2013-05-22 09:00:2314
15namespace remoting {
16namespace protocol {
17
18PairingHostAuthenticator::PairingHostAuthenticator(
19 scoped_refptr<PairingRegistry> pairing_registry,
sergeyu12e320a2016-03-08 18:10:2820 const CreateBaseAuthenticatorCallback& create_base_authenticator_callback,
[email protected]6434bfe2013-05-22 09:00:2321 const std::string& pin)
22 : pairing_registry_(pairing_registry),
sergeyu12e320a2016-03-08 18:10:2823 create_base_authenticator_callback_(create_base_authenticator_callback),
Jeremy Roman7c5cfabd2019-08-12 15:45:2724 pin_(pin) {}
[email protected]6434bfe2013-05-22 09:00:2325
sergeyu843ef122016-03-17 01:44:1726void PairingHostAuthenticator::Initialize(
27 const std::string& client_id,
28 Authenticator::State preferred_initial_state,
Evan Stadece9372b2020-03-12 01:28:1629 base::OnceClosure resume_callback) {
sergeyu843ef122016-03-17 01:44:1730 DCHECK(!spake2_authenticator_);
31
32 if (client_id.empty()) {
33 using_paired_secret_ = false;
34 error_message_ = "client-id-unknown";
35 spake2_authenticator_ =
36 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY);
Evan Stadece9372b2020-03-12 01:28:1637 std::move(resume_callback).Run();
sergeyu843ef122016-03-17 01:44:1738 return;
39 }
40
41 using_paired_secret_ = true;
42 waiting_for_paired_secret_ = true;
43 pairing_registry_->GetPairing(
Jan Wilken Dörriea0e772a2020-04-01 18:28:1944 client_id,
45 base::BindOnce(&PairingHostAuthenticator::InitializeWithPairing,
46 weak_factory_.GetWeakPtr(), preferred_initial_state,
Daniel Cheng28a5ac482021-02-22 21:03:0847 std::move(resume_callback)));
sergeyu843ef122016-03-17 01:44:1748}
49
Chris Watkins6fe52aa2017-11-28 03:24:0550PairingHostAuthenticator::~PairingHostAuthenticator() = default;
[email protected]6434bfe2013-05-22 09:00:2351
52Authenticator::State PairingHostAuthenticator::state() const {
53 if (protocol_error_) {
54 return REJECTED;
[email protected]40dade32013-06-14 07:08:1155 } else if (waiting_for_paired_secret_) {
56 return PROCESSING_MESSAGE;
[email protected]6434bfe2013-05-22 09:00:2357 }
58 return PairingAuthenticatorBase::state();
59}
60
61Authenticator::RejectionReason
62PairingHostAuthenticator::rejection_reason() const {
63 if (protocol_error_) {
64 return PROTOCOL_ERROR;
65 }
66 return PairingAuthenticatorBase::rejection_reason();
67}
68
sergeyu12e320a2016-03-08 18:10:2869void PairingHostAuthenticator::CreateSpakeAuthenticatorWithPin(
[email protected]6434bfe2013-05-22 09:00:2370 State initial_state,
Evan Stadece9372b2020-03-12 01:28:1671 base::OnceClosure resume_callback) {
sergeyu12e320a2016-03-08 18:10:2872 spake2_authenticator_ =
73 create_base_authenticator_callback_.Run(pin_, initial_state);
Evan Stadece9372b2020-03-12 01:28:1674 std::move(resume_callback).Run();
[email protected]6434bfe2013-05-22 09:00:2375}
76
sergeyu843ef122016-03-17 01:44:1777void PairingHostAuthenticator::InitializeWithPairing(
78 Authenticator::State preferred_initial_state,
Evan Stadece9372b2020-03-12 01:28:1679 base::OnceClosure resume_callback,
[email protected]40dade32013-06-14 07:08:1180 PairingRegistry::Pairing pairing) {
sergeyu843ef122016-03-17 01:44:1781 DCHECK(waiting_for_paired_secret_);
[email protected]40dade32013-06-14 07:08:1182 waiting_for_paired_secret_ = false;
sergeyu843ef122016-03-17 01:44:1783 std::string pairing_secret = pairing.shared_secret();
84 if (pairing_secret.empty()) {
[email protected]5cbe3cf2013-11-25 17:05:0485 VLOG(0) << "Unknown client id";
[email protected]40dade32013-06-14 07:08:1186 error_message_ = "unknown-client-id";
sergeyu843ef122016-03-17 01:44:1787 using_paired_secret_ = false;
88 // If pairing wasn't found then always start in the MESSAGE_READY state.
sergeyu12e320a2016-03-08 18:10:2889 spake2_authenticator_ =
90 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY);
sergeyu843ef122016-03-17 01:44:1791 } else {
92 using_paired_secret_ = true;
93 spake2_authenticator_ = create_base_authenticator_callback_.Run(
94 pairing_secret, preferred_initial_state);
[email protected]40dade32013-06-14 07:08:1195 }
Evan Stadece9372b2020-03-12 01:28:1696 std::move(resume_callback).Run();
[email protected]40dade32013-06-14 07:08:1197}
98
[email protected]6434bfe2013-05-22 09:00:2399} // namespace protocol
100} // namespace remoting