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

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

Issue 8604001: Move SSL layer initialization into ChannelAuthenticator implementations. (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
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"
12 #include "base/threading/non_thread_safe.h" 11 #include "base/threading/non_thread_safe.h"
13 #include "net/base/completion_callback.h" 12 #include "net/base/net_errors.h"
14 13
15 namespace net { 14 namespace net {
16 class DrainableIOBuffer; 15 class StreamSocket;
17 class GrowableIOBuffer;
18 class SSLSocket;
19 } // namespace net 16 } // namespace net
20 17
21 namespace remoting { 18 namespace remoting {
22 namespace protocol { 19 namespace protocol {
23 20
24 class ChannelAuthenticator : public base::NonThreadSafe { 21 class ChannelAuthenticator : public base::NonThreadSafe {
Wez 2011/11/22 22:29:48 Should this interface really derive from NonThread
Wez 2011/11/22 22:29:48 Give a short description of what this interface is
Sergey Ulanov 2011/11/23 01:23:42 Done.
Sergey Ulanov 2011/11/23 01:23:42 Done.
25 public: 22 public:
26 enum Result { 23 typedef base::Callback<void(net::Error error, net::StreamSocket*)>
27 SUCCESS, 24 DoneCallback;
28 FAILURE,
29 };
30 25
31 typedef base::Callback<void(Result)> DoneCallback; 26 ChannelAuthenticator() {}
Wez 2011/11/22 22:29:48 Make this protected, since it doesn't make sense t
Sergey Ulanov 2011/11/23 01:23:42 Just removed this constructor.
27 virtual ~ChannelAuthenticator() {}
32 28
33 ChannelAuthenticator() { } 29 // Starts SSL on the |socket| and authenticates it. Takes ownership
Wez 2011/11/22 22:29:48 Indicate that the caller must not attempt to use |
Sergey Ulanov 2011/11/23 01:23:42 Done.
34 virtual ~ChannelAuthenticator() { } 30 // of |socket|. |done_callback| is called when authentication is
Wez 2011/11/22 22:29:48 Is this always the case? Surely whether SSL is st
Sergey Ulanov 2011/11/23 01:23:42 Done.
35 31 // finished. Callback handler must take ownership of the result.
Wez 2011/11/22 22:29:48 Indicate that the callback may be invoked before S
Sergey Ulanov 2011/11/23 01:23:42 Done.
36 // Starts authentication of the |socket|. |done_callback| is called 32 virtual void SecureAndAuthenticate(
37 // when authentication is finished. Caller retains ownership of 33 net::StreamSocket* socket, const DoneCallback& done_callback) = 0;
38 // |socket|. |shared_secret| is a shared secret that we use to
39 // authenticate the channel.
40 virtual void Authenticate(net::SSLSocket* socket,
41 const DoneCallback& done_callback) = 0;
42 34
43 private: 35 private:
44 DISALLOW_COPY_AND_ASSIGN(ChannelAuthenticator); 36 DISALLOW_COPY_AND_ASSIGN(ChannelAuthenticator);
45 }; 37 };
46 38
47 class HostChannelAuthenticator : public ChannelAuthenticator {
48 public:
49 HostChannelAuthenticator(const std::string& shared_secret);
50 virtual ~HostChannelAuthenticator();
51
52 // ChannelAuthenticator overrides.
53 virtual void Authenticate(net::SSLSocket* socket,
54 const DoneCallback& done_callback) OVERRIDE;
55
56 private:
57 void DoAuthRead();
58 void OnAuthBytesRead(int result);
59 bool HandleAuthBytesRead(int result);
60 bool VerifyAuthBytes(const std::string& received_auth_bytes);
61
62 std::string shared_secret_;
63 std::string auth_bytes_;
64 net::SSLSocket* socket_;
65 DoneCallback done_callback_;
66
67 scoped_refptr<net::GrowableIOBuffer> auth_read_buf_;
68
69 net::OldCompletionCallbackImpl<HostChannelAuthenticator> auth_read_callback_;
70
71 DISALLOW_COPY_AND_ASSIGN(HostChannelAuthenticator);
72 };
73
74 class ClientChannelAuthenticator : public ChannelAuthenticator {
75 public:
76 ClientChannelAuthenticator(const std::string& shared_secret);
77 virtual ~ClientChannelAuthenticator();
78
79 // ChannelAuthenticator overrides.
80 virtual void Authenticate(net::SSLSocket* socket,
81 const DoneCallback& done_callback);
82
83 private:
84 void DoAuthWrite();
85 void OnAuthBytesWritten(int result);
86 bool HandleAuthBytesWritten(int result);
87
88 std::string shared_secret_;
89 net::SSLSocket* socket_;
90 DoneCallback done_callback_;
91
92 scoped_refptr<net::DrainableIOBuffer> auth_write_buf_;
93
94 net::OldCompletionCallbackImpl<ClientChannelAuthenticator>
95 auth_write_callback_;
96
97 DISALLOW_COPY_AND_ASSIGN(ClientChannelAuthenticator);
98 };
99
100 } // namespace protocol 39 } // namespace protocol
101 } // namespace remoting 40 } // namespace remoting
102 41
103 #endif // REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_ 42 #endif // REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698