blob: 0b6682abaf1d4c955749da1f85912f2e09299c3e [file] [log] [blame]
Avi Drissmand6cdf9b2022-09-15 19:52:531// Copyright 2013 The Chromium Authors
[email protected]6434bfe2013-05-22 09:00:232// 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
Avi Drissman135261e2023-01-11 22:43:159#include "base/functional/bind.h"
[email protected]6434bfe2013-05-22 09:00:2310#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
Joe Downing39d710e2022-08-25 20:11:4515namespace remoting::protocol {
[email protected]6434bfe2013-05-22 09:00:2316
17PairingHostAuthenticator::PairingHostAuthenticator(
18 scoped_refptr<PairingRegistry> pairing_registry,
sergeyu12e320a2016-03-08 18:10:2819 const CreateBaseAuthenticatorCallback& create_base_authenticator_callback,
[email protected]6434bfe2013-05-22 09:00:2320 const std::string& pin)
21 : pairing_registry_(pairing_registry),
sergeyu12e320a2016-03-08 18:10:2822 create_base_authenticator_callback_(create_base_authenticator_callback),
Jeremy Roman7c5cfabd2019-08-12 15:45:2723 pin_(pin) {}
[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,
Evan Stadece9372b2020-03-12 01:28:1628 base::OnceClosure resume_callback) {
sergeyu843ef122016-03-17 01:44:1729 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);
Evan Stadece9372b2020-03-12 01:28:1636 std::move(resume_callback).Run();
sergeyu843ef122016-03-17 01:44:1737 return;
38 }
39
40 using_paired_secret_ = true;
41 waiting_for_paired_secret_ = true;
42 pairing_registry_->GetPairing(
Jan Wilken Dörriea0e772a2020-04-01 18:28:1943 client_id,
44 base::BindOnce(&PairingHostAuthenticator::InitializeWithPairing,
45 weak_factory_.GetWeakPtr(), preferred_initial_state,
Daniel Cheng28a5ac482021-02-22 21:03:0846 std::move(resume_callback)));
sergeyu843ef122016-03-17 01:44:1747}
48
Chris Watkins6fe52aa2017-11-28 03:24:0549PairingHostAuthenticator::~PairingHostAuthenticator() = default;
[email protected]6434bfe2013-05-22 09:00:2350
51Authenticator::State PairingHostAuthenticator::state() const {
52 if (protocol_error_) {
53 return REJECTED;
[email protected]40dade32013-06-14 07:08:1154 } else if (waiting_for_paired_secret_) {
55 return PROCESSING_MESSAGE;
[email protected]6434bfe2013-05-22 09:00:2356 }
57 return PairingAuthenticatorBase::state();
58}
59
Joe Downing353ba2c72023-01-11 22:37:3460Authenticator::RejectionReason PairingHostAuthenticator::rejection_reason()
61 const {
[email protected]6434bfe2013-05-22 09:00:2362 if (protocol_error_) {
Lei Zhang8dea4712022-07-22 16:28:2563 return RejectionReason::PROTOCOL_ERROR;
[email protected]6434bfe2013-05-22 09:00:2364 }
65 return PairingAuthenticatorBase::rejection_reason();
66}
67
sergeyu12e320a2016-03-08 18:10:2868void PairingHostAuthenticator::CreateSpakeAuthenticatorWithPin(
[email protected]6434bfe2013-05-22 09:00:2369 State initial_state,
Evan Stadece9372b2020-03-12 01:28:1670 base::OnceClosure resume_callback) {
sergeyu12e320a2016-03-08 18:10:2871 spake2_authenticator_ =
72 create_base_authenticator_callback_.Run(pin_, initial_state);
Evan Stadece9372b2020-03-12 01:28:1673 std::move(resume_callback).Run();
[email protected]6434bfe2013-05-22 09:00:2374}
75
sergeyu843ef122016-03-17 01:44:1776void PairingHostAuthenticator::InitializeWithPairing(
77 Authenticator::State preferred_initial_state,
Evan Stadece9372b2020-03-12 01:28:1678 base::OnceClosure resume_callback,
[email protected]40dade32013-06-14 07:08:1179 PairingRegistry::Pairing pairing) {
sergeyu843ef122016-03-17 01:44:1780 DCHECK(waiting_for_paired_secret_);
[email protected]40dade32013-06-14 07:08:1181 waiting_for_paired_secret_ = false;
sergeyu843ef122016-03-17 01:44:1782 std::string pairing_secret = pairing.shared_secret();
83 if (pairing_secret.empty()) {
[email protected]5cbe3cf2013-11-25 17:05:0484 VLOG(0) << "Unknown client id";
[email protected]40dade32013-06-14 07:08:1185 error_message_ = "unknown-client-id";
sergeyu843ef122016-03-17 01:44:1786 using_paired_secret_ = false;
87 // If pairing wasn't found then always start in the MESSAGE_READY state.
sergeyu12e320a2016-03-08 18:10:2888 spake2_authenticator_ =
89 create_base_authenticator_callback_.Run(pin_, MESSAGE_READY);
sergeyu843ef122016-03-17 01:44:1790 } else {
91 using_paired_secret_ = true;
92 spake2_authenticator_ = create_base_authenticator_callback_.Run(
93 pairing_secret, preferred_initial_state);
[email protected]40dade32013-06-14 07:08:1194 }
Evan Stadece9372b2020-03-12 01:28:1695 std::move(resume_callback).Run();
[email protected]40dade32013-06-14 07:08:1196}
97
Joe Downing39d710e2022-08-25 20:11:4598} // namespace remoting::protocol