| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_SOCKET_FUZZED_SOCKET_FACTORY_H |
| 6 #define NET_SOCKET_FUZZED_SOCKET_FACTORY_H |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "net/socket/client_socket_factory.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 class FuzzedDataProvider; |
| 16 |
| 17 // A socket factory that creates FuzzedSockets that share the same |
| 18 // FuzzedDataProvider. To behave consistently, the read operations on all |
| 19 // sockets must be the same, and in the same order (both on each socket, and |
| 20 // between sockets). |
| 21 // |
| 22 // Currently doesn't support UDP or SSL sockets - just returns sockets that |
| 23 // synchronously fail to connect when trying to create either type of socket. |
| 24 // TODO(mmenke): Add support for both types of socket. |
| 25 // TODO(mmenke): add fuzzing for generation of valid cryptographically signed |
| 26 // messages. |
| 27 class FuzzedSocketFactory : public ClientSocketFactory { |
| 28 public: |
| 29 // |data_provider| must outlive the FuzzedSocketFactory, and all sockets it |
| 30 // creates. Other objects can also continue to consume |data_provider|, as |
| 31 // long as their calls into it are made on the CLientSocketFactory's thread |
| 32 // and the calls are deterministic. |
| 33 explicit FuzzedSocketFactory(FuzzedDataProvider* data_provider); |
| 34 ~FuzzedSocketFactory() override; |
| 35 |
| 36 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 37 DatagramSocket::BindType bind_type, |
| 38 const RandIntCallback& rand_int_cb, |
| 39 NetLog* net_log, |
| 40 const NetLog::Source& source) override; |
| 41 |
| 42 std::unique_ptr<StreamSocket> CreateTransportClientSocket( |
| 43 const AddressList& addresses, |
| 44 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 45 NetLog* net_log, |
| 46 const NetLog::Source& source) override; |
| 47 |
| 48 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 49 std::unique_ptr<ClientSocketHandle> transport_socket, |
| 50 const HostPortPair& host_and_port, |
| 51 const SSLConfig& ssl_config, |
| 52 const SSLClientSocketContext& context) override; |
| 53 |
| 54 void ClearSSLSessionCache() override; |
| 55 |
| 56 private: |
| 57 FuzzedDataProvider* data_provider_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(FuzzedSocketFactory); |
| 60 }; |
| 61 |
| 62 } // namespace net |
| 63 |
| 64 #endif // NET_SOCKET_FUZZED_SOCKET_FACTORY_H |
| OLD | NEW |