OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 | 12 |
13 namespace buzz { | 13 namespace buzz { |
14 class XmlElement; | 14 class XmlElement; |
15 } // namespace buzz | 15 } // namespace buzz |
16 | 16 |
17 namespace remoting { | 17 namespace remoting { |
18 namespace protocol { | 18 namespace protocol { |
19 | 19 |
20 class Authenticator; | 20 class Authenticator; |
21 class ChannelAuthenticator; | 21 class ChannelAuthenticator; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 }; | 64 }; |
65 | 65 |
66 enum RejectionReason { | 66 enum RejectionReason { |
67 INVALID_CREDENTIALS, | 67 INVALID_CREDENTIALS, |
68 PROTOCOL_ERROR, | 68 PROTOCOL_ERROR, |
69 }; | 69 }; |
70 | 70 |
71 // Callback used for layered Authenticator implementations, particularly | 71 // Callback used for layered Authenticator implementations, particularly |
72 // third-party and pairing authenticators. They use this callback to create | 72 // third-party and pairing authenticators. They use this callback to create |
73 // base SPAKE2 authenticators. | 73 // base SPAKE2 authenticators. |
74 typedef base::Callback<scoped_ptr<Authenticator>( | 74 typedef base::Callback<std::unique_ptr<Authenticator>( |
75 const std::string& shared_secret, | 75 const std::string& shared_secret, |
76 Authenticator::State initial_state)> | 76 Authenticator::State initial_state)> |
77 CreateBaseAuthenticatorCallback; | 77 CreateBaseAuthenticatorCallback; |
78 | 78 |
79 // Returns true if |message| is an Authenticator message. | 79 // Returns true if |message| is an Authenticator message. |
80 static bool IsAuthenticatorMessage(const buzz::XmlElement* message); | 80 static bool IsAuthenticatorMessage(const buzz::XmlElement* message); |
81 | 81 |
82 // Creates an empty Authenticator message, owned by the caller. | 82 // Creates an empty Authenticator message, owned by the caller. |
83 static scoped_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage(); | 83 static std::unique_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage(); |
84 | 84 |
85 // Finds Authenticator message among child elements of |message|, or | 85 // Finds Authenticator message among child elements of |message|, or |
86 // returns nullptr otherwise. | 86 // returns nullptr otherwise. |
87 static const buzz::XmlElement* FindAuthenticatorMessage( | 87 static const buzz::XmlElement* FindAuthenticatorMessage( |
88 const buzz::XmlElement* message); | 88 const buzz::XmlElement* message); |
89 | 89 |
90 Authenticator() {} | 90 Authenticator() {} |
91 virtual ~Authenticator() {} | 91 virtual ~Authenticator() {} |
92 | 92 |
93 // Returns current state of the authenticator. | 93 // Returns current state of the authenticator. |
(...skipping 10 matching lines...) Expand all Loading... |
104 // Called in response to incoming message received from the peer. | 104 // Called in response to incoming message received from the peer. |
105 // Should only be called when in WAITING_MESSAGE state. Caller retains | 105 // Should only be called when in WAITING_MESSAGE state. Caller retains |
106 // ownership of |message|. |resume_callback| will be called when processing is | 106 // ownership of |message|. |resume_callback| will be called when processing is |
107 // finished. The implementation must guarantee that |resume_callback| is not | 107 // finished. The implementation must guarantee that |resume_callback| is not |
108 // called after the Authenticator is destroyed. | 108 // called after the Authenticator is destroyed. |
109 virtual void ProcessMessage(const buzz::XmlElement* message, | 109 virtual void ProcessMessage(const buzz::XmlElement* message, |
110 const base::Closure& resume_callback) = 0; | 110 const base::Closure& resume_callback) = 0; |
111 | 111 |
112 // Must be called when in MESSAGE_READY state. Returns next | 112 // Must be called when in MESSAGE_READY state. Returns next |
113 // authentication message that needs to be sent to the peer. | 113 // authentication message that needs to be sent to the peer. |
114 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() = 0; | 114 virtual std::unique_ptr<buzz::XmlElement> GetNextMessage() = 0; |
115 | 115 |
116 // Returns the auth key received as result of the authentication handshake. | 116 // Returns the auth key received as result of the authentication handshake. |
117 virtual const std::string& GetAuthKey() const = 0; | 117 virtual const std::string& GetAuthKey() const = 0; |
118 | 118 |
119 // Creates new authenticator for a channel. Can be called only in | 119 // Creates new authenticator for a channel. Can be called only in |
120 // the ACCEPTED state. | 120 // the ACCEPTED state. |
121 virtual scoped_ptr<ChannelAuthenticator> | 121 virtual std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator() |
122 CreateChannelAuthenticator() const = 0; | 122 const = 0; |
123 }; | 123 }; |
124 | 124 |
125 // Factory for Authenticator instances. | 125 // Factory for Authenticator instances. |
126 class AuthenticatorFactory { | 126 class AuthenticatorFactory { |
127 public: | 127 public: |
128 AuthenticatorFactory() {} | 128 AuthenticatorFactory() {} |
129 virtual ~AuthenticatorFactory() {} | 129 virtual ~AuthenticatorFactory() {} |
130 | 130 |
131 // Called when session-initiate stanza is received to create | 131 // Called when session-initiate stanza is received to create |
132 // authenticator for the new session. |first_message| specifies | 132 // authenticator for the new session. |first_message| specifies |
133 // authentication part of the session-initiate stanza so that | 133 // authentication part of the session-initiate stanza so that |
134 // appropriate type of Authenticator can be chosen for the session | 134 // appropriate type of Authenticator can be chosen for the session |
135 // (useful when multiple authenticators is supported). Returns nullptr | 135 // (useful when multiple authenticators is supported). Returns nullptr |
136 // if the |first_message| is invalid and the session should be | 136 // if the |first_message| is invalid and the session should be |
137 // rejected. ProcessMessage() should be called with |first_message| | 137 // rejected. ProcessMessage() should be called with |first_message| |
138 // for the result of this method. | 138 // for the result of this method. |
139 virtual scoped_ptr<Authenticator> CreateAuthenticator( | 139 virtual std::unique_ptr<Authenticator> CreateAuthenticator( |
140 const std::string& local_jid, | 140 const std::string& local_jid, |
141 const std::string& remote_jid) = 0; | 141 const std::string& remote_jid) = 0; |
142 }; | 142 }; |
143 | 143 |
144 } // namespace protocol | 144 } // namespace protocol |
145 } // namespace remoting | 145 } // namespace remoting |
146 | 146 |
147 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ | 147 #endif // REMOTING_PROTOCOL_AUTHENTICATOR_H_ |
OLD | NEW |