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

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: Simple->V1 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 | « remoting/protocol/auth_util.cc ('k') | 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 "net/base/net_errors.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "net/base/completion_callback.h"
14 12
15 namespace net { 13 namespace net {
16 class DrainableIOBuffer; 14 class StreamSocket;
17 class GrowableIOBuffer;
18 class SSLSocket;
19 } // namespace net 15 } // namespace net
20 16
21 namespace remoting { 17 namespace remoting {
22 namespace protocol { 18 namespace protocol {
23 19
24 class ChannelAuthenticator : public base::NonThreadSafe { 20 // Interface for channel authentications that perform channel-level
21 // authentication. Depending on implementation channel authenticators
22 // may also establish SSL connection. Each instance of this interface
23 // should be used only once for one channel.
24 class ChannelAuthenticator {
25 public: 25 public:
26 enum Result { 26 typedef base::Callback<void(net::Error error, net::StreamSocket*)>
27 SUCCESS, 27 DoneCallback;
28 FAILURE,
29 };
30 28
31 typedef base::Callback<void(Result)> DoneCallback; 29 virtual ~ChannelAuthenticator() {}
32 30
33 ChannelAuthenticator() { } 31 // Start authentication of the given |socket|. Takes ownership of
34 virtual ~ChannelAuthenticator() { } 32 // |socket|, and caller must not use |socket| after calling this
35 33 // method. |done_callback| is called when authentication is
36 // Starts authentication of the |socket|. |done_callback| is called 34 // finished. Callback may be invoked before this method
37 // when authentication is finished. Caller retains ownership of 35 // returns. Callback handler must take ownership of the result.
38 // |socket|. |shared_secret| is a shared secret that we use to 36 virtual void SecureAndAuthenticate(
39 // authenticate the channel. 37 net::StreamSocket* socket, const DoneCallback& done_callback) = 0;
40 virtual void Authenticate(net::SSLSocket* socket,
41 const DoneCallback& done_callback) = 0;
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(ChannelAuthenticator);
45 };
46
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) OVERRIDE;
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 }; 38 };
99 39
100 } // namespace protocol 40 } // namespace protocol
101 } // namespace remoting 41 } // namespace remoting
102 42
103 #endif // REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_ 43 #endif // REMOTING_PROTOCOL_CHANNEL_AUTHENTICATOR_H_
OLDNEW
« no previous file with comments | « remoting/protocol/auth_util.cc ('k') | remoting/protocol/channel_authenticator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698