OLD | NEW |
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 // This ClientSocket implementation is to be used with servers that | 5 // This StreamSocket implementation is to be used with servers that |
6 // accept connections on port 443 but don't really use SSL. For | 6 // accept connections on port 443 but don't really use SSL. For |
7 // example, the Google Talk servers do this to bypass proxies. (The | 7 // example, the Google Talk servers do this to bypass proxies. (The |
8 // connection is upgraded to TLS as part of the XMPP negotiation, so | 8 // connection is upgraded to TLS as part of the XMPP negotiation, so |
9 // security is preserved.) A "fake" SSL handshake is done immediately | 9 // security is preserved.) A "fake" SSL handshake is done immediately |
10 // after connection to fool proxies into thinking that this is a real | 10 // after connection to fool proxies into thinking that this is a real |
11 // SSL connection. | 11 // SSL connection. |
12 // | 12 // |
13 // NOTE: This ClientSocket implementation does *not* do a real SSL | 13 // NOTE: This StreamSocket implementation does *not* do a real SSL |
14 // handshake nor does it do any encryption! | 14 // handshake nor does it do any encryption! |
15 | 15 |
16 #ifndef JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ | 16 #ifndef JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ |
17 #define JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ | 17 #define JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ |
18 #pragma once | 18 #pragma once |
19 | 19 |
20 #include <cstddef> | 20 #include <cstddef> |
21 | 21 |
22 #include "base/basictypes.h" | 22 #include "base/basictypes.h" |
23 #include "base/memory/ref_counted.h" | 23 #include "base/memory/ref_counted.h" |
24 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
25 #include "base/string_piece.h" | 25 #include "base/string_piece.h" |
26 #include "net/base/completion_callback.h" | 26 #include "net/base/completion_callback.h" |
27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
28 #include "net/socket/client_socket.h" | 28 #include "net/socket/stream_socket.h" |
29 | 29 |
30 namespace net { | 30 namespace net { |
31 class DrainableIOBuffer; | 31 class DrainableIOBuffer; |
32 } // namespace net | 32 } // namespace net |
33 | 33 |
34 namespace notifier { | 34 namespace notifier { |
35 | 35 |
36 class FakeSSLClientSocket : public net::ClientSocket { | 36 class FakeSSLClientSocket : public net::StreamSocket { |
37 public: | 37 public: |
38 // Takes ownership of |transport_socket|. | 38 // Takes ownership of |transport_socket|. |
39 explicit FakeSSLClientSocket(net::ClientSocket* transport_socket); | 39 explicit FakeSSLClientSocket(net::StreamSocket* transport_socket); |
40 | 40 |
41 virtual ~FakeSSLClientSocket(); | 41 virtual ~FakeSSLClientSocket(); |
42 | 42 |
43 // Exposed for testing. | 43 // Exposed for testing. |
44 static base::StringPiece GetSslClientHello(); | 44 static base::StringPiece GetSslClientHello(); |
45 static base::StringPiece GetSslServerHello(); | 45 static base::StringPiece GetSslServerHello(); |
46 | 46 |
47 // net::ClientSocket implementation. | 47 // net::StreamSocket implementation. |
48 virtual int Read(net::IOBuffer* buf, int buf_len, | 48 virtual int Read(net::IOBuffer* buf, int buf_len, |
49 net::CompletionCallback* callback); | 49 net::CompletionCallback* callback); |
50 virtual int Write(net::IOBuffer* buf, int buf_len, | 50 virtual int Write(net::IOBuffer* buf, int buf_len, |
51 net::CompletionCallback* callback); | 51 net::CompletionCallback* callback); |
52 virtual bool SetReceiveBufferSize(int32 size); | 52 virtual bool SetReceiveBufferSize(int32 size); |
53 virtual bool SetSendBufferSize(int32 size); | 53 virtual bool SetSendBufferSize(int32 size); |
54 virtual int Connect(net::CompletionCallback* callback); | 54 virtual int Connect(net::CompletionCallback* callback); |
55 virtual void Disconnect(); | 55 virtual void Disconnect(); |
56 virtual bool IsConnected() const; | 56 virtual bool IsConnected() const; |
57 virtual bool IsConnectedAndIdle() const; | 57 virtual bool IsConnectedAndIdle() const; |
(...skipping 29 matching lines...) Expand all Loading... |
87 void OnVerifyServerHelloDone(int status); | 87 void OnVerifyServerHelloDone(int status); |
88 net::Error ProcessVerifyServerHelloDone(size_t read); | 88 net::Error ProcessVerifyServerHelloDone(size_t read); |
89 | 89 |
90 // Callbacks passed to |transport_socket_|. | 90 // Callbacks passed to |transport_socket_|. |
91 net::CompletionCallbackImpl<FakeSSLClientSocket> connect_callback_; | 91 net::CompletionCallbackImpl<FakeSSLClientSocket> connect_callback_; |
92 net::CompletionCallbackImpl<FakeSSLClientSocket> | 92 net::CompletionCallbackImpl<FakeSSLClientSocket> |
93 send_client_hello_callback_; | 93 send_client_hello_callback_; |
94 net::CompletionCallbackImpl<FakeSSLClientSocket> | 94 net::CompletionCallbackImpl<FakeSSLClientSocket> |
95 verify_server_hello_callback_; | 95 verify_server_hello_callback_; |
96 | 96 |
97 scoped_ptr<net::ClientSocket> transport_socket_; | 97 scoped_ptr<net::StreamSocket> transport_socket_; |
98 | 98 |
99 // During the handshake process, holds a value from HandshakeState. | 99 // During the handshake process, holds a value from HandshakeState. |
100 // STATE_NONE otherwise. | 100 // STATE_NONE otherwise. |
101 HandshakeState next_handshake_state_; | 101 HandshakeState next_handshake_state_; |
102 | 102 |
103 // True iff we're connected and we've finished the handshake. | 103 // True iff we're connected and we've finished the handshake. |
104 bool handshake_completed_; | 104 bool handshake_completed_; |
105 | 105 |
106 // The callback passed to Connect(). | 106 // The callback passed to Connect(). |
107 net::CompletionCallback* user_connect_callback_; | 107 net::CompletionCallback* user_connect_callback_; |
108 | 108 |
109 scoped_refptr<net::DrainableIOBuffer> write_buf_; | 109 scoped_refptr<net::DrainableIOBuffer> write_buf_; |
110 scoped_refptr<net::DrainableIOBuffer> read_buf_; | 110 scoped_refptr<net::DrainableIOBuffer> read_buf_; |
111 }; | 111 }; |
112 | 112 |
113 } // namespace notifier | 113 } // namespace notifier |
114 | 114 |
115 #endif // JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ | 115 #endif // JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ |
OLD | NEW |