/src/curl_fuzzer/proto_fuzzer/socks4_mock_server.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | /// @file |
8 | | /// @brief Deterministic SOCKS/HAProxy transport for HTTP scenarios. |
9 | | |
10 | | #ifndef PROTO_FUZZER_SOCKS4_MOCK_SERVER_H_ |
11 | | #define PROTO_FUZZER_SOCKS4_MOCK_SERVER_H_ |
12 | | |
13 | | #include <cstddef> |
14 | | #include <memory> |
15 | | #include <string> |
16 | | |
17 | | #include "proto_fuzzer/incoming_data_observer.h" |
18 | | #include "proto_fuzzer/mock_server.h" |
19 | | |
20 | | namespace proto_fuzzer { |
21 | | |
22 | | /// Reuses MockServer's request-triggered raw chunk delivery: the first chunks |
23 | | /// become SOCKS negotiation replies and later chunks become the tunneled HTTP |
24 | | /// response. Routing is fixed to a numeric loopback proxy whose socket is |
25 | | /// replaced by MockServer's socketpair, so neither proxy nor origin can reach |
26 | | /// the network. The historical source filename follows the packaged target |
27 | | /// basename; the class name reflects the broader append-only transport lane. |
28 | | class ProxyTransportMockServer final : public MockServer, public IncomingDataObserver { |
29 | | public: |
30 | | ProxyTransportMockServer(curl::fuzzer::proto::SocksProxyMode mode, bool haproxy_protocol); |
31 | 7.95k | ~ProxyTransportMockServer() override = default; |
32 | | |
33 | | ProxyTransportMockServer(const ProxyTransportMockServer&) = delete; |
34 | | ProxyTransportMockServer& operator=(const ProxyTransportMockServer&) = delete; |
35 | | |
36 | | void Install(CURL* easy) override; |
37 | | |
38 | | // Bounded raw client bytes from SOCKS negotiation through tunneled HTTP. |
39 | | // Tests use this to assert exact handshake and HAProxy prefix ordering. |
40 | | const std::string& client_transcript() const; |
41 | | |
42 | | protected: |
43 | | std::unique_ptr<MockConnection> CreateConnection() override; |
44 | | |
45 | | void ObserveIncomingData(const unsigned char* data, std::size_t size) override; |
46 | | |
47 | | bool SupportsRepeatedPollsetProbe() const override; |
48 | | |
49 | | private: |
50 | | static constexpr std::size_t kMaxTranscriptBytes = 64 * 1024; |
51 | | |
52 | | curl::fuzzer::proto::SocksProxyMode mode_; |
53 | | bool haproxy_protocol_; |
54 | | std::string client_transcript_; |
55 | | }; |
56 | | |
57 | | } // namespace proto_fuzzer |
58 | | |
59 | | #endif // PROTO_FUZZER_SOCKS4_MOCK_SERVER_H_ |