blob: 4c575f98ec2c8bcea45d9ee6c5e237683dd1667c [file] [log] [blame]
[email protected]9a6361d02013-03-23 16:27:521// 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/third_party_authenticator_base.h"
6
7#include "base/base64.h"
8#include "base/bind.h"
9#include "base/callback.h"
10#include "base/logging.h"
11#include "remoting/base/constants.h"
12#include "remoting/base/rsa_key_pair.h"
13#include "remoting/protocol/channel_authenticator.h"
kjellanderf0e410b2017-01-04 14:45:0114#include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
[email protected]9a6361d02013-03-23 16:27:5215
16namespace remoting {
17namespace protocol {
18
19// static
20const buzz::StaticQName ThirdPartyAuthenticatorBase::kTokenUrlTag =
21 { remoting::kChromotingXmlNamespace, "third-party-token-url" };
22const buzz::StaticQName ThirdPartyAuthenticatorBase::kTokenScopeTag =
23 { remoting::kChromotingXmlNamespace, "third-party-token-scope" };
24const buzz::StaticQName ThirdPartyAuthenticatorBase::kTokenTag =
25 { remoting::kChromotingXmlNamespace, "third-party-token" };
26
27ThirdPartyAuthenticatorBase::ThirdPartyAuthenticatorBase(
28 Authenticator::State initial_state)
29 : token_state_(initial_state),
[email protected]064128c2014-04-07 22:33:2830 started_(false),
[email protected]9a6361d02013-03-23 16:27:5231 rejection_reason_(INVALID_CREDENTIALS) {
32}
33
Chris Watkins6fe52aa2017-11-28 03:24:0534ThirdPartyAuthenticatorBase::~ThirdPartyAuthenticatorBase() = default;
[email protected]9a6361d02013-03-23 16:27:5235
[email protected]064128c2014-04-07 22:33:2836bool ThirdPartyAuthenticatorBase::started() const {
37 return started_;
38}
39
[email protected]9a6361d02013-03-23 16:27:5240Authenticator::State ThirdPartyAuthenticatorBase::state() const {
41 if (token_state_ == ACCEPTED)
42 return underlying_->state();
43 return token_state_;
44}
45
46Authenticator::RejectionReason
47ThirdPartyAuthenticatorBase::rejection_reason() const {
48 DCHECK_EQ(state(), REJECTED);
49
50 if (token_state_ == REJECTED)
51 return rejection_reason_;
52 return underlying_->rejection_reason();
53}
54
55void ThirdPartyAuthenticatorBase::ProcessMessage(
56 const buzz::XmlElement* message,
57 const base::Closure& resume_callback) {
58 DCHECK_EQ(state(), WAITING_MESSAGE);
59
60 if (token_state_ == WAITING_MESSAGE) {
61 ProcessTokenMessage(message, resume_callback);
62 } else {
63 DCHECK_EQ(token_state_, ACCEPTED);
64 DCHECK(underlying_);
65 DCHECK_EQ(underlying_->state(), WAITING_MESSAGE);
66 underlying_->ProcessMessage(message, resume_callback);
67 }
68}
69
dcheng0765c492016-04-06 22:41:5370std::unique_ptr<buzz::XmlElement>
71ThirdPartyAuthenticatorBase::GetNextMessage() {
[email protected]9a6361d02013-03-23 16:27:5272 DCHECK_EQ(state(), MESSAGE_READY);
73
dcheng0765c492016-04-06 22:41:5374 std::unique_ptr<buzz::XmlElement> message;
[email protected]9a6361d02013-03-23 16:27:5275 if (underlying_ && underlying_->state() == MESSAGE_READY) {
sergeyuaa6fa2342015-12-22 23:26:4876 message = underlying_->GetNextMessage();
[email protected]9a6361d02013-03-23 16:27:5277 } else {
78 message = CreateEmptyAuthenticatorMessage();
79 }
80
[email protected]064128c2014-04-07 22:33:2881 if (token_state_ == MESSAGE_READY) {
[email protected]9a6361d02013-03-23 16:27:5282 AddTokenElements(message.get());
[email protected]064128c2014-04-07 22:33:2883 started_ = true;
84 }
sergeyuaa6fa2342015-12-22 23:26:4885 return message;
[email protected]9a6361d02013-03-23 16:27:5286}
87
sergeyu2a640402015-08-14 19:52:1888const std::string& ThirdPartyAuthenticatorBase::GetAuthKey() const {
89 DCHECK_EQ(state(), ACCEPTED);
90
91 return underlying_->GetAuthKey();
92}
93
dcheng0765c492016-04-06 22:41:5394std::unique_ptr<ChannelAuthenticator>
[email protected]9a6361d02013-03-23 16:27:5295ThirdPartyAuthenticatorBase::CreateChannelAuthenticator() const {
96 DCHECK_EQ(state(), ACCEPTED);
97
98 return underlying_->CreateChannelAuthenticator();
99}
100
101} // namespace protocol
102} // namespace remoting