Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: remoting/protocol/channel_authenticator.h

Issue 8527018: Refactor ChannelAuthenticator so that it can be used with Authenticator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/protocol/channel_authenticator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_CHANNEL_AUTHENTICATOR_H_ 5 #ifndef REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_
6 #define REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_ 6 #define REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "net/base/completion_callback.h" 13 #include "net/base/completion_callback.h"
14 14
15 namespace net { 15 namespace net {
16 class DrainableIOBuffer; 16 class DrainableIOBuffer;
17 class GrowableIOBuffer; 17 class GrowableIOBuffer;
18 class SSLClientSocket; 18 class SSLSocket;
19 class SSLServerSocket;
20 } // namespace net 19 } // namespace net
21 20
22 namespace remoting { 21 namespace remoting {
23 namespace protocol { 22 namespace protocol {
24 23
25 class ChannelAuthenticator : public base::NonThreadSafe { 24 class ChannelAuthenticator : public base::NonThreadSafe {
26 public: 25 public:
27 enum Result { 26 enum Result {
28 SUCCESS, 27 SUCCESS,
29 FAILURE, 28 FAILURE,
30 }; 29 };
31 30
32 typedef base::Callback<void(Result)> DoneCallback; 31 typedef base::Callback<void(Result)> DoneCallback;
33 32
34 ChannelAuthenticator() { } 33 ChannelAuthenticator() { }
35 virtual ~ChannelAuthenticator() { } 34 virtual ~ChannelAuthenticator() { }
36 35
37 // Starts authentication of the |socket|. |done_callback| is called 36 // Starts authentication of the |socket|. |done_callback| is called
38 // when authentication is finished. Caller retains ownership of 37 // when authentication is finished. Caller retains ownership of
39 // |socket|. |shared_secret| is a shared secret that we use to 38 // |socket|. |shared_secret| is a shared secret that we use to
40 // authenticate the channel. 39 // authenticate the channel.
41 virtual void Authenticate(const std::string& shared_secret, 40 virtual void Authenticate(net::SSLSocket* socket,
42 const DoneCallback& done_callback) = 0; 41 const DoneCallback& done_callback) = 0;
43 42
44 private: 43 private:
45 DISALLOW_COPY_AND_ASSIGN(ChannelAuthenticator); 44 DISALLOW_COPY_AND_ASSIGN(ChannelAuthenticator);
46 }; 45 };
47 46
48 class HostChannelAuthenticator : public ChannelAuthenticator { 47 class HostChannelAuthenticator : public ChannelAuthenticator {
49 public: 48 public:
50 HostChannelAuthenticator(net::SSLServerSocket* socket); 49 HostChannelAuthenticator(const std::string& shared_secret);
51 virtual ~HostChannelAuthenticator(); 50 virtual ~HostChannelAuthenticator();
52 51
53 // ChannelAuthenticator overrides. 52 // ChannelAuthenticator overrides.
54 virtual void Authenticate(const std::string& shared_secret, 53 virtual void Authenticate(net::SSLSocket* socket,
55 const DoneCallback& done_callback) OVERRIDE; 54 const DoneCallback& done_callback) OVERRIDE;
56 55
57 private: 56 private:
58 void DoAuthRead(); 57 void DoAuthRead();
59 void OnAuthBytesRead(int result); 58 void OnAuthBytesRead(int result);
60 bool HandleAuthBytesRead(int result); 59 bool HandleAuthBytesRead(int result);
61 bool VerifyAuthBytes(const std::string& received_auth_bytes); 60 bool VerifyAuthBytes(const std::string& received_auth_bytes);
62 61
62 std::string shared_secret_;
63 std::string auth_bytes_; 63 std::string auth_bytes_;
64 net::SSLServerSocket* socket_; 64 net::SSLSocket* socket_;
65 DoneCallback done_callback_; 65 DoneCallback done_callback_;
66 66
67 scoped_refptr<net::GrowableIOBuffer> auth_read_buf_; 67 scoped_refptr<net::GrowableIOBuffer> auth_read_buf_;
68 68
69 net::OldCompletionCallbackImpl<HostChannelAuthenticator> auth_read_callback_; 69 net::OldCompletionCallbackImpl<HostChannelAuthenticator> auth_read_callback_;
70 70
71 DISALLOW_COPY_AND_ASSIGN(HostChannelAuthenticator); 71 DISALLOW_COPY_AND_ASSIGN(HostChannelAuthenticator);
72 }; 72 };
73 73
74 class ClientChannelAuthenticator : public ChannelAuthenticator { 74 class ClientChannelAuthenticator : public ChannelAuthenticator {
75 public: 75 public:
76 ClientChannelAuthenticator(net::SSLClientSocket* socket); 76 ClientChannelAuthenticator(const std::string& shared_secret);
77 virtual ~ClientChannelAuthenticator(); 77 virtual ~ClientChannelAuthenticator();
78 78
79 // ChannelAuthenticator overrides. 79 // ChannelAuthenticator overrides.
80 virtual void Authenticate(const std::string& shared_secret, 80 virtual void Authenticate(net::SSLSocket* socket,
81 const DoneCallback& done_callback); 81 const DoneCallback& done_callback);
82 82
83 private: 83 private:
84 void DoAuthWrite(); 84 void DoAuthWrite();
85 void OnAuthBytesWritten(int result); 85 void OnAuthBytesWritten(int result);
86 bool HandleAuthBytesWritten(int result); 86 bool HandleAuthBytesWritten(int result);
87 87
88 net::SSLClientSocket* socket_; 88 std::string shared_secret_;
89 net::SSLSocket* socket_;
89 DoneCallback done_callback_; 90 DoneCallback done_callback_;
90 91
91 scoped_refptr<net::DrainableIOBuffer> auth_write_buf_; 92 scoped_refptr<net::DrainableIOBuffer> auth_write_buf_;
92 93
93 net::OldCompletionCallbackImpl<ClientChannelAuthenticator> auth_write_callback _; 94 net::OldCompletionCallbackImpl<ClientChannelAuthenticator>
95 auth_write_callback_;
94 96
95 DISALLOW_COPY_AND_ASSIGN(ClientChannelAuthenticator); 97 DISALLOW_COPY_AND_ASSIGN(ClientChannelAuthenticator);
96 }; 98 };
97 99
98 } // namespace protocol 100 } // namespace protocol
99 } // namespace remoting 101 } // namespace remoting
100 102
101 #endif // REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_ 103 #endif // REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/protocol/channel_authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698