50b12e957d2463e974d500951c138fba15a90d90
[platform/framework/web/crosswalk.git] / src / remoting / protocol / third_party_authenticator_base.h
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.
4
5 #ifndef REMOTING_PROTOCOL_THIRD_PARTY_AUTHENTICATOR_BASE_H_
6 #define REMOTING_PROTOCOL_THIRD_PARTY_AUTHENTICATOR_BASE_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "remoting/protocol/authenticator.h"
13 #include "third_party/webrtc/libjingle/xmllite/qname.h"
14
15 namespace buzz {
16
17 class XmlElement;
18
19 }  // namespace buzz
20
21 namespace remoting {
22 namespace protocol {
23
24 // Implements an authentication method that relies on a third party server for
25 // authentication of both client and host.
26 // When third party authentication is being used, the client must request both a
27 // token and a shared secret from a third-party server (which may require the
28 // user to authenticate themselves). The client then sends only the token to the
29 // host. The host signs the token, then contacts the third-party server to
30 // exchange the token for the shared secret. Once both client and host have the
31 // shared secret, they use an underlying |V2Authenticator| (SPAKE2) to negotiate
32 // an authentication key, which is used to establish the connection.
33 class ThirdPartyAuthenticatorBase : public Authenticator {
34  public:
35   ~ThirdPartyAuthenticatorBase() override;
36
37   // Authenticator interface.
38   State state() const override;
39   bool started() const override;
40   RejectionReason rejection_reason() const override;
41   void ProcessMessage(const buzz::XmlElement* message,
42                       const base::Closure& resume_callback) override;
43   scoped_ptr<buzz::XmlElement> GetNextMessage() override;
44   scoped_ptr<ChannelAuthenticator> CreateChannelAuthenticator() const override;
45
46  protected:
47   // XML tag names for third party authentication fields.
48   static const buzz::StaticQName kTokenUrlTag;
49   static const buzz::StaticQName kTokenScopeTag;
50   static const buzz::StaticQName kTokenTag;
51
52   explicit ThirdPartyAuthenticatorBase(State initial_state);
53
54   // Gives the message to the underlying authenticator for processing.
55   void ProcessUnderlyingMessage(
56       const buzz::XmlElement* message,
57       const base::Closure& resume_callback);
58
59   // Processes the token-related elements of the message.
60   virtual void ProcessTokenMessage(
61       const buzz::XmlElement* message,
62       const base::Closure& resume_callback) = 0;
63
64   // Adds the token related XML elements to the message.
65   virtual void AddTokenElements(buzz::XmlElement* message) = 0;
66
67   scoped_ptr<Authenticator> underlying_;
68   State token_state_;
69   bool started_;
70   RejectionReason rejection_reason_;
71
72  private:
73   DISALLOW_COPY_AND_ASSIGN(ThirdPartyAuthenticatorBase);
74 };
75
76 }  // namespace protocol
77 }  // namespace remoting
78
79 #endif  // REMOTING_PROTOCOL_THIRD_PARTY_AUTHENTICATOR_BASE_H_