Revert of Update V8 to version 4.5.70. (patchset #1 id:1 of https://codereview.chromi...
[chromium-blink-merge.git] / jingle / glue / fake_ssl_client_socket.h
blob8f904298de1fff71215eda4e5f3dddbda601dab1
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.
4 //
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
11 // SSL connection.
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_
19 #include <cstddef>
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/strings/string_piece.h"
26 #include "net/base/completion_callback.h"
27 #include "net/base/net_errors.h"
28 #include "net/socket/stream_socket.h"
30 namespace net {
31 class DrainableIOBuffer;
32 class SSLInfo;
33 } // namespace net
35 namespace jingle_glue {
37 class FakeSSLClientSocket : public net::StreamSocket {
38 public:
39 explicit FakeSSLClientSocket(scoped_ptr<net::StreamSocket> transport_socket);
41 ~FakeSSLClientSocket() override;
43 // Exposed for testing.
44 static base::StringPiece GetSslClientHello();
45 static base::StringPiece GetSslServerHello();
47 // net::StreamSocket implementation.
48 int Read(net::IOBuffer* buf,
49 int buf_len,
50 const net::CompletionCallback& callback) override;
51 int Write(net::IOBuffer* buf,
52 int buf_len,
53 const net::CompletionCallback& callback) override;
54 int SetReceiveBufferSize(int32 size) override;
55 int SetSendBufferSize(int32 size) override;
56 int Connect(const net::CompletionCallback& callback) override;
57 void Disconnect() override;
58 bool IsConnected() const override;
59 bool IsConnectedAndIdle() const override;
60 int GetPeerAddress(net::IPEndPoint* address) const override;
61 int GetLocalAddress(net::IPEndPoint* address) const override;
62 const net::BoundNetLog& NetLog() const override;
63 void SetSubresourceSpeculation() override;
64 void SetOmniboxSpeculation() override;
65 bool WasEverUsed() const override;
66 bool UsingTCPFastOpen() const override;
67 bool WasNpnNegotiated() const override;
68 net::NextProto GetNegotiatedProtocol() const override;
69 bool GetSSLInfo(net::SSLInfo* ssl_info) override;
70 void GetConnectionAttempts(net::ConnectionAttempts* out) const override;
71 void ClearConnectionAttempts() override {}
72 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override {
75 private:
76 enum HandshakeState {
77 STATE_NONE,
78 STATE_CONNECT,
79 STATE_SEND_CLIENT_HELLO,
80 STATE_VERIFY_SERVER_HELLO,
83 int DoHandshakeLoop();
84 void RunUserConnectCallback(int status);
85 void DoHandshakeLoopWithUserConnectCallback();
87 int DoConnect();
88 void OnConnectDone(int status);
89 void ProcessConnectDone();
91 int DoSendClientHello();
92 void OnSendClientHelloDone(int status);
93 void ProcessSendClientHelloDone(size_t written);
95 int DoVerifyServerHello();
96 void OnVerifyServerHelloDone(int status);
97 net::Error ProcessVerifyServerHelloDone(size_t read);
99 scoped_ptr<net::StreamSocket> transport_socket_;
101 // During the handshake process, holds a value from HandshakeState.
102 // STATE_NONE otherwise.
103 HandshakeState next_handshake_state_;
105 // True iff we're connected and we've finished the handshake.
106 bool handshake_completed_;
108 // The callback passed to Connect().
109 net::CompletionCallback user_connect_callback_;
111 scoped_refptr<net::DrainableIOBuffer> write_buf_;
112 scoped_refptr<net::DrainableIOBuffer> read_buf_;
115 } // namespace jingle_glue
117 #endif // JINGLE_GLUE_FAKE_SSL_CLIENT_SOCKET_H_