OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 5 #ifndef REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
6 #define REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 6 #define REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 namespace buzz { | 10 namespace buzz { |
11 class XmlElement; | 11 class XmlElement; |
12 } // namespace buzz | 12 } // namespace buzz |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 namespace protocol { | 15 namespace protocol { |
16 | 16 |
| 17 class ChannelAuthenticator; |
| 18 |
17 // Authenticator is an abstract interface for authentication protocol | 19 // Authenticator is an abstract interface for authentication protocol |
18 // implementations. Different implementations of this interface may be | 20 // implementations. Different implementations of this interface may be |
19 // used on each side of the connection depending of type of the auth | 21 // used on each side of the connection depending of type of the auth |
20 // protocol. Client and host will repeatedly call their Authenticators | 22 // protocol. Client and host will repeatedly call their Authenticators |
21 // and deliver the messages they generate, until successful | 23 // and deliver the messages they generate, until successful |
22 // authentication is reported. | 24 // authentication is reported. |
23 // | 25 // |
24 // Authenticator may exchange multiple messages before session is | 26 // Authenticator may exchange multiple messages before session is |
25 // authenticated. Each message sent/received by an Authenticator is | 27 // authenticated. Each message sent/received by an Authenticator is |
26 // delivered either in a session description inside session-initiate | 28 // delivered either in a session description inside session-initiate |
27 // and session-accept messages or in a session-info | 29 // and session-accept messages or in a session-info |
28 // message. Session-info messages are used only if authenticators need | 30 // message. Session-info messages are used only if authenticators need |
29 // to exchange more than one message. | 31 // to exchange more than one message. |
30 class Authenticator { | 32 class Authenticator { |
31 public: | 33 public: |
32 // Allowed state transitions: | 34 // Allowed state transitions: |
33 // When ProcessMessage() is called: | 35 // When ProcessMessage() is called: |
34 // WAITING_MESSAGE -> MESSAGE_READY | 36 // WAITING_MESSAGE -> MESSAGE_READY |
35 // WAITING_MESSAGE -> ACCEPTED | 37 // WAITING_MESSAGE -> ACCEPTED |
36 // WAITING_MESSAGE -> REJECTED | 38 // WAITING_MESSAGE -> REJECTED |
37 // When GetNextMessage() is called: | 39 // When GetNextMessage() is called: |
38 // MESSAGE_READY -> WAITING_MESSAGE | 40 // MESSAGE_READY -> WAITING_MESSAGE |
39 // MESSAGE_READY -> ACCEPTED | 41 // MESSAGE_READY -> ACCEPTED |
40 // MESSAGE_READY -> REJECTED | |
41 enum State { | 42 enum State { |
42 // Waiting for the next message from the peer. | 43 // Waiting for the next message from the peer. |
43 WAITING_MESSAGE, | 44 WAITING_MESSAGE, |
44 | 45 |
45 // Next message is ready to be sent to the peer. | 46 // Next message is ready to be sent to the peer. |
46 MESSAGE_READY, | 47 MESSAGE_READY, |
47 | 48 |
48 // Session is authenticated successufully. | 49 // Session is authenticated successufully. |
49 ACCEPTED, | 50 ACCEPTED, |
50 | 51 |
51 // Session is rejected. | 52 // Session is rejected. |
52 REJECTED, | 53 REJECTED, |
53 }; | 54 }; |
54 | 55 |
55 Authenticator() {} | 56 Authenticator() {} |
56 virtual ~Authenticator() {} | 57 virtual ~Authenticator() {} |
57 | 58 |
58 // Returns current state of the authenticator. | 59 // Returns current state of the authenticator. |
59 virtual State state() const = 0; | 60 virtual State state() const = 0; |
60 | 61 |
61 // Called in response to incoming message received from the peer. | 62 // Called in response to incoming message received from the peer. |
62 // Should only be called when in WAITING_MESSAGE state. | 63 // Should only be called when in WAITING_MESSAGE state. Caller |
63 virtual void ProcessMessage(talk_base::XmlElement* message) = 0; | 64 // retains ownership of |message|. |
| 65 virtual void ProcessMessage(const buzz::XmlElement* message) = 0; |
64 | 66 |
65 // Must be called when in MESSAGE_READY state. Returns next | 67 // Must be called when in MESSAGE_READY state. Returns next |
66 // authentication message that needs to be sent to the peer. | 68 // authentication message that needs to be sent to the peer. |
67 virtual talk_base::XmlElement* GetNextMessage() = 0; | 69 virtual buzz::XmlElement* GetNextMessage() = 0; |
68 | 70 |
69 // Creates new authenticator for a channel. Caller must take | 71 // Creates new authenticator for a channel. Caller must take |
70 // ownership of the result. Can be called only in the ACCEPTED | 72 // ownership of the result. Can be called only in the ACCEPTED |
71 // state. | 73 // state. |
72 virtual ChannelAuthenticator* CreateChannelAuthenticator() const = 0; | 74 virtual ChannelAuthenticator* CreateChannelAuthenticator() const = 0; |
73 }; | 75 }; |
74 | 76 |
75 // Factory for Authenticator instances. | 77 // Factory for Authenticator instances. |
76 class AuthenticatorFactory { | 78 class AuthenticatorFactory { |
| 79 public: |
| 80 AuthenticatorFactory() {} |
| 81 virtual ~AuthenticatorFactory() {} |
| 82 |
77 // Called when session-initiate stanza is received to create | 83 // Called when session-initiate stanza is received to create |
78 // authenticator for the new session. |first_message| specifies | 84 // authenticator for the new session. |first_message| specifies |
79 // authentication part of the session-initiate stanza so that | 85 // authentication part of the session-initiate stanza so that |
80 // appropriate type of Authenticator can be chosen for the session | 86 // appropriate type of Authenticator can be chosen for the session |
81 // (useful when multiple authenticators is supported). Returns NULL | 87 // (useful when multiple authenticators is supported). Returns NULL |
82 // if the |first_message| is invalid and the session should be | 88 // if the |first_message| is invalid and the session should be |
83 // rejected. ProcessMessage() should be called with |first_message| | 89 // rejected. ProcessMessage() should be called with |first_message| |
84 // for the result of this method. | 90 // for the result of this method. |
85 virtual Authenticator* CreateAuthenticator( | 91 virtual Authenticator* CreateAuthenticator( |
86 const talk_base::XmlElement* first_message) = 0; | 92 const std::string& remote_jid, |
| 93 const buzz::XmlElement* first_message) = 0; |
87 }; | 94 }; |
88 | 95 |
89 } // namespace protocol | 96 } // namespace protocol |
90 } // namespace remoting | 97 } // namespace remoting |
91 | 98 |
92 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 99 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
OLD | NEW |