1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This StreamSocket implementation is to be used with servers that
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
8 // connection is upgraded to TLS as part of the XMPP negotiation, so
9 // security is preserved.) A "fake" SSL handshake is done immediately
10 // after connection to fool proxies into thinking that this is a real
13 // NOTE: This StreamSocket implementation does *not* do a real SSL
14 // handshake nor does it do any encryption!
16 #ifndef JINGLE_GLUE_FAKE_SSL_CLIENT_SOCKET_H_
17 #define JINGLE_GLUE_FAKE_SSL_CLIENT_SOCKET_H_
21 #include "base/basictypes.h"
22 #include "base/compiler_specific.h"
23 #include "base/memory/ref_counted.h"
24 #include "base/memory/scoped_ptr.h"
25 #include "base/string_piece.h"
26 #include "net/base/completion_callback.h"
27 #include "net/base/net_errors.h"
28 #include "net/socket/stream_socket.h"
31 class DrainableIOBuffer
;
35 namespace jingle_glue
{
37 class FakeSSLClientSocket
: public net::StreamSocket
{
39 // Takes ownership of |transport_socket|.
40 explicit FakeSSLClientSocket(net::StreamSocket
* transport_socket
);
42 virtual ~FakeSSLClientSocket();
44 // Exposed for testing.
45 static base::StringPiece
GetSslClientHello();
46 static base::StringPiece
GetSslServerHello();
48 // net::StreamSocket implementation.
49 virtual int Read(net::IOBuffer
* buf
, int buf_len
,
50 const net::CompletionCallback
& callback
) OVERRIDE
;
51 virtual int Write(net::IOBuffer
* buf
, int buf_len
,
52 const net::CompletionCallback
& callback
) OVERRIDE
;
53 virtual bool SetReceiveBufferSize(int32 size
) OVERRIDE
;
54 virtual bool SetSendBufferSize(int32 size
) OVERRIDE
;
55 virtual int Connect(const net::CompletionCallback
& callback
) OVERRIDE
;
56 virtual void Disconnect() OVERRIDE
;
57 virtual bool IsConnected() const OVERRIDE
;
58 virtual bool IsConnectedAndIdle() const OVERRIDE
;
59 virtual int GetPeerAddress(net::IPEndPoint
* address
) const OVERRIDE
;
60 virtual int GetLocalAddress(net::IPEndPoint
* address
) const OVERRIDE
;
61 virtual const net::BoundNetLog
& NetLog() const OVERRIDE
;
62 virtual void SetSubresourceSpeculation() OVERRIDE
;
63 virtual void SetOmniboxSpeculation() OVERRIDE
;
64 virtual bool WasEverUsed() const OVERRIDE
;
65 virtual bool UsingTCPFastOpen() const OVERRIDE
;
66 virtual int64
NumBytesRead() const OVERRIDE
;
67 virtual base::TimeDelta
GetConnectTimeMicros() const OVERRIDE
;
68 virtual bool WasNpnNegotiated() const OVERRIDE
;
69 virtual net::NextProto
GetNegotiatedProtocol() const OVERRIDE
;
70 virtual bool GetSSLInfo(net::SSLInfo
* ssl_info
) OVERRIDE
;
76 STATE_SEND_CLIENT_HELLO
,
77 STATE_VERIFY_SERVER_HELLO
,
80 int DoHandshakeLoop();
81 void RunUserConnectCallback(int status
);
82 void DoHandshakeLoopWithUserConnectCallback();
85 void OnConnectDone(int status
);
86 void ProcessConnectDone();
88 int DoSendClientHello();
89 void OnSendClientHelloDone(int status
);
90 void ProcessSendClientHelloDone(size_t written
);
92 int DoVerifyServerHello();
93 void OnVerifyServerHelloDone(int status
);
94 net::Error
ProcessVerifyServerHelloDone(size_t read
);
96 scoped_ptr
<net::StreamSocket
> transport_socket_
;
98 // During the handshake process, holds a value from HandshakeState.
99 // STATE_NONE otherwise.
100 HandshakeState next_handshake_state_
;
102 // True iff we're connected and we've finished the handshake.
103 bool handshake_completed_
;
105 // The callback passed to Connect().
106 net::CompletionCallback user_connect_callback_
;
108 scoped_refptr
<net::DrainableIOBuffer
> write_buf_
;
109 scoped_refptr
<net::DrainableIOBuffer
> read_buf_
;
112 } // namespace jingle_glue
114 #endif // JINGLE_GLUE_FAKE_SSL_CLIENT_SOCKET_H_