OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "net/socket/fuzzed_socket_factory.h" | 5 #include "net/socket/fuzzed_socket_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/base/network_change_notifier.h" | 12 #include "net/base/network_change_notifier.h" |
13 #include "net/log/net_log.h" | 13 #include "net/log/net_log.h" |
14 #include "net/socket/client_socket_handle.h" | 14 #include "net/socket/client_socket_handle.h" |
15 #include "net/socket/connection_attempts.h" | 15 #include "net/socket/connection_attempts.h" |
16 #include "net/socket/fuzzed_socket.h" | 16 #include "net/socket/fuzzed_socket.h" |
17 #include "net/socket/ssl_client_socket.h" | 17 #include "net/socket/ssl_client_socket.h" |
18 #include "net/ssl/ssl_failure_state.h" | 18 #include "net/ssl/ssl_failure_state.h" |
19 #include "net/udp/datagram_client_socket.h" | 19 #include "net/udp/fuzzed_datagram_client_socket.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Datagram ClientSocket implementation that always failed to connect. | |
26 class FailingUDPClientSocket : public DatagramClientSocket { | |
27 public: | |
28 FailingUDPClientSocket() {} | |
29 ~FailingUDPClientSocket() override {} | |
30 | |
31 // DatagramClientSocket implementation: | |
32 int Connect(const IPEndPoint& address) override { return ERR_FAILED; } | |
33 | |
34 int ConnectUsingNetwork(NetworkChangeNotifier::NetworkHandle network, | |
35 const IPEndPoint& address) override { | |
36 return ERR_FAILED; | |
37 } | |
38 | |
39 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override { | |
40 return ERR_FAILED; | |
41 } | |
42 | |
43 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override { | |
44 return -1; | |
45 } | |
46 | |
47 // DatagramSocket implementation: | |
48 void Close() override {} | |
49 | |
50 int GetPeerAddress(IPEndPoint* address) const override { | |
51 return ERR_SOCKET_NOT_CONNECTED; | |
52 } | |
53 | |
54 int GetLocalAddress(IPEndPoint* address) const override { | |
55 return ERR_SOCKET_NOT_CONNECTED; | |
56 } | |
57 | |
58 const BoundNetLog& NetLog() const override { return net_log_; } | |
59 | |
60 // Socket implementation: | |
61 int Read(IOBuffer* buf, | |
62 int buf_len, | |
63 const CompletionCallback& callback) override { | |
64 NOTREACHED(); | |
65 return ERR_UNEXPECTED; | |
66 } | |
67 | |
68 int Write(IOBuffer* buf, | |
69 int buf_len, | |
70 const CompletionCallback& callback) override { | |
71 NOTREACHED(); | |
72 return ERR_UNEXPECTED; | |
73 } | |
74 | |
75 int SetReceiveBufferSize(int32_t size) override { | |
76 NOTREACHED(); | |
77 return ERR_UNEXPECTED; | |
78 } | |
79 | |
80 int SetSendBufferSize(int32_t size) override { | |
81 NOTREACHED(); | |
82 return ERR_UNEXPECTED; | |
83 } | |
84 | |
85 BoundNetLog net_log_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(FailingUDPClientSocket); | |
88 }; | |
89 | |
90 // SSLClientSocket implementation that always fails to connect. | 25 // SSLClientSocket implementation that always fails to connect. |
91 class FailingSSLClientSocket : public SSLClientSocket { | 26 class FailingSSLClientSocket : public SSLClientSocket { |
92 public: | 27 public: |
93 FailingSSLClientSocket() {} | 28 FailingSSLClientSocket() {} |
94 ~FailingSSLClientSocket() override {} | 29 ~FailingSSLClientSocket() override {} |
95 | 30 |
96 // Socket implementation: | 31 // Socket implementation: |
97 int Read(IOBuffer* buf, | 32 int Read(IOBuffer* buf, |
98 int buf_len, | 33 int buf_len, |
99 const CompletionCallback& callback) override { | 34 const CompletionCallback& callback) override { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 : data_provider_(data_provider) {} | 136 : data_provider_(data_provider) {} |
202 | 137 |
203 FuzzedSocketFactory::~FuzzedSocketFactory() {} | 138 FuzzedSocketFactory::~FuzzedSocketFactory() {} |
204 | 139 |
205 std::unique_ptr<DatagramClientSocket> | 140 std::unique_ptr<DatagramClientSocket> |
206 FuzzedSocketFactory::CreateDatagramClientSocket( | 141 FuzzedSocketFactory::CreateDatagramClientSocket( |
207 DatagramSocket::BindType bind_type, | 142 DatagramSocket::BindType bind_type, |
208 const RandIntCallback& rand_int_cb, | 143 const RandIntCallback& rand_int_cb, |
209 NetLog* net_log, | 144 NetLog* net_log, |
210 const NetLog::Source& source) { | 145 const NetLog::Source& source) { |
211 return base::WrapUnique(new FailingUDPClientSocket()); | 146 return base::WrapUnique(new FuzzedDatagramClientSocket(data_provider_)); |
212 } | 147 } |
213 | 148 |
214 std::unique_ptr<StreamSocket> FuzzedSocketFactory::CreateTransportClientSocket( | 149 std::unique_ptr<StreamSocket> FuzzedSocketFactory::CreateTransportClientSocket( |
215 const AddressList& addresses, | 150 const AddressList& addresses, |
216 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 151 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
217 NetLog* net_log, | 152 NetLog* net_log, |
218 const NetLog::Source& source) { | 153 const NetLog::Source& source) { |
219 std::unique_ptr<FuzzedSocket> socket( | 154 std::unique_ptr<FuzzedSocket> socket( |
220 new FuzzedSocket(data_provider_, net_log)); | 155 new FuzzedSocket(data_provider_, net_log)); |
221 socket->set_fuzz_connect_result(true); | 156 socket->set_fuzz_connect_result(true); |
222 // Just use the first address. | 157 // Just use the first address. |
223 socket->set_remote_address(*addresses.begin()); | 158 socket->set_remote_address(*addresses.begin()); |
224 return std::move(socket); | 159 return std::move(socket); |
225 } | 160 } |
226 | 161 |
227 std::unique_ptr<SSLClientSocket> FuzzedSocketFactory::CreateSSLClientSocket( | 162 std::unique_ptr<SSLClientSocket> FuzzedSocketFactory::CreateSSLClientSocket( |
228 std::unique_ptr<ClientSocketHandle> transport_socket, | 163 std::unique_ptr<ClientSocketHandle> transport_socket, |
229 const HostPortPair& host_and_port, | 164 const HostPortPair& host_and_port, |
230 const SSLConfig& ssl_config, | 165 const SSLConfig& ssl_config, |
231 const SSLClientSocketContext& context) { | 166 const SSLClientSocketContext& context) { |
232 return base::WrapUnique(new FailingSSLClientSocket()); | 167 return base::WrapUnique(new FailingSSLClientSocket()); |
233 } | 168 } |
234 | 169 |
235 void FuzzedSocketFactory::ClearSSLSessionCache() {} | 170 void FuzzedSocketFactory::ClearSSLSessionCache() {} |
236 | 171 |
237 } // namespace net | 172 } // namespace net |
OLD | NEW |