1 // 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.
5 #include "remoting/protocol/third_party_authenticator_base.h"
7 #include "base/base64.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"
14 #include "remoting/protocol/v2_authenticator.h"
15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
21 const buzz::StaticQName
ThirdPartyAuthenticatorBase::kTokenUrlTag
=
22 { remoting::kChromotingXmlNamespace
, "third-party-token-url" };
23 const buzz::StaticQName
ThirdPartyAuthenticatorBase::kTokenScopeTag
=
24 { remoting::kChromotingXmlNamespace
, "third-party-token-scope" };
25 const buzz::StaticQName
ThirdPartyAuthenticatorBase::kTokenTag
=
26 { remoting::kChromotingXmlNamespace
, "third-party-token" };
28 ThirdPartyAuthenticatorBase::ThirdPartyAuthenticatorBase(
29 Authenticator::State initial_state
)
30 : token_state_(initial_state
),
31 rejection_reason_(INVALID_CREDENTIALS
) {
34 ThirdPartyAuthenticatorBase::~ThirdPartyAuthenticatorBase() {
37 Authenticator::State
ThirdPartyAuthenticatorBase::state() const {
38 if (token_state_
== ACCEPTED
)
39 return underlying_
->state();
43 Authenticator::RejectionReason
44 ThirdPartyAuthenticatorBase::rejection_reason() const {
45 DCHECK_EQ(state(), REJECTED
);
47 if (token_state_
== REJECTED
)
48 return rejection_reason_
;
49 return underlying_
->rejection_reason();
52 void ThirdPartyAuthenticatorBase::ProcessMessage(
53 const buzz::XmlElement
* message
,
54 const base::Closure
& resume_callback
) {
55 DCHECK_EQ(state(), WAITING_MESSAGE
);
57 if (token_state_
== WAITING_MESSAGE
) {
58 ProcessTokenMessage(message
, resume_callback
);
60 DCHECK_EQ(token_state_
, ACCEPTED
);
62 DCHECK_EQ(underlying_
->state(), WAITING_MESSAGE
);
63 underlying_
->ProcessMessage(message
, resume_callback
);
67 scoped_ptr
<buzz::XmlElement
> ThirdPartyAuthenticatorBase::GetNextMessage() {
68 DCHECK_EQ(state(), MESSAGE_READY
);
70 scoped_ptr
<buzz::XmlElement
> message
;
71 if (underlying_
&& underlying_
->state() == MESSAGE_READY
) {
72 message
= underlying_
->GetNextMessage().Pass();
74 message
= CreateEmptyAuthenticatorMessage();
77 if (token_state_
== MESSAGE_READY
)
78 AddTokenElements(message
.get());
80 return message
.Pass();
83 scoped_ptr
<ChannelAuthenticator
>
84 ThirdPartyAuthenticatorBase::CreateChannelAuthenticator() const {
85 DCHECK_EQ(state(), ACCEPTED
);
87 return underlying_
->CreateChannelAuthenticator();
90 } // namespace protocol
91 } // namespace remoting