| 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 StreamSocket 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 StreamSocket 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/compiler_specific.h" |
| 23 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
| 24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 25 #include "base/string_piece.h" | 26 #include "base/string_piece.h" |
| 26 #include "net/base/completion_callback.h" | 27 #include "net/base/completion_callback.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 #include "net/socket/stream_socket.h" | 29 #include "net/socket/stream_socket.h" |
| 29 | 30 |
| 30 namespace net { | 31 namespace net { |
| 31 class DrainableIOBuffer; | 32 class DrainableIOBuffer; |
| 32 } // namespace net | 33 } // namespace net |
| 33 | 34 |
| 34 namespace notifier { | 35 namespace notifier { |
| 35 | 36 |
| 36 class FakeSSLClientSocket : public net::StreamSocket { | 37 class FakeSSLClientSocket : public net::StreamSocket { |
| 37 public: | 38 public: |
| 38 // Takes ownership of |transport_socket|. | 39 // Takes ownership of |transport_socket|. |
| 39 explicit FakeSSLClientSocket(net::StreamSocket* transport_socket); | 40 explicit FakeSSLClientSocket(net::StreamSocket* transport_socket); |
| 40 | 41 |
| 41 virtual ~FakeSSLClientSocket(); | 42 virtual ~FakeSSLClientSocket(); |
| 42 | 43 |
| 43 // Exposed for testing. | 44 // Exposed for testing. |
| 44 static base::StringPiece GetSslClientHello(); | 45 static base::StringPiece GetSslClientHello(); |
| 45 static base::StringPiece GetSslServerHello(); | 46 static base::StringPiece GetSslServerHello(); |
| 46 | 47 |
| 47 // net::StreamSocket implementation. | 48 // net::StreamSocket implementation. |
| 48 virtual int Read(net::IOBuffer* buf, int buf_len, | 49 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 49 net::OldCompletionCallback* callback); | 50 net::OldCompletionCallback* callback) OVERRIDE; |
| 50 virtual int Write(net::IOBuffer* buf, int buf_len, | 51 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 51 net::OldCompletionCallback* callback); | 52 net::OldCompletionCallback* callback) OVERRIDE; |
| 52 virtual bool SetReceiveBufferSize(int32 size); | 53 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 53 virtual bool SetSendBufferSize(int32 size); | 54 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 54 virtual int Connect(net::OldCompletionCallback* callback); | 55 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; |
| 55 virtual void Disconnect(); | 56 virtual void Disconnect() OVERRIDE; |
| 56 virtual bool IsConnected() const; | 57 virtual bool IsConnected() const OVERRIDE; |
| 57 virtual bool IsConnectedAndIdle() const; | 58 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 58 virtual int GetPeerAddress(net::AddressList* address) const; | 59 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; |
| 59 virtual int GetLocalAddress(net::IPEndPoint* address) const; | 60 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; |
| 60 virtual const net::BoundNetLog& NetLog() const; | 61 virtual const net::BoundNetLog& NetLog() const OVERRIDE; |
| 61 virtual void SetSubresourceSpeculation(); | 62 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 62 virtual void SetOmniboxSpeculation(); | 63 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 63 virtual bool WasEverUsed() const; | 64 virtual bool WasEverUsed() const OVERRIDE; |
| 64 virtual bool UsingTCPFastOpen() const; | 65 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 65 virtual int64 NumBytesRead() const; | 66 virtual int64 NumBytesRead() const OVERRIDE; |
| 66 virtual base::TimeDelta GetConnectTimeMicros() const; | 67 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 67 | 68 |
| 68 private: | 69 private: |
| 69 enum HandshakeState { | 70 enum HandshakeState { |
| 70 STATE_NONE, | 71 STATE_NONE, |
| 71 STATE_CONNECT, | 72 STATE_CONNECT, |
| 72 STATE_SEND_CLIENT_HELLO, | 73 STATE_SEND_CLIENT_HELLO, |
| 73 STATE_VERIFY_SERVER_HELLO, | 74 STATE_VERIFY_SERVER_HELLO, |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 int DoHandshakeLoop(); | 77 int DoHandshakeLoop(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // The callback passed to Connect(). | 109 // The callback passed to Connect(). |
| 109 net::OldCompletionCallback* user_connect_callback_; | 110 net::OldCompletionCallback* user_connect_callback_; |
| 110 | 111 |
| 111 scoped_refptr<net::DrainableIOBuffer> write_buf_; | 112 scoped_refptr<net::DrainableIOBuffer> write_buf_; |
| 112 scoped_refptr<net::DrainableIOBuffer> read_buf_; | 113 scoped_refptr<net::DrainableIOBuffer> read_buf_; |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 } // namespace notifier | 116 } // namespace notifier |
| 116 | 117 |
| 117 #endif // JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ | 118 #endif // JINGLE_NOTIFIER_BASE_FAKE_SSL_CLIENT_SOCKET_H_ |
| OLD | NEW |