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