curl-fuzzer C++ reference
Loading...
Searching...
No Matches
h2_origin_mock_server.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al.
3 *
4 * SPDX-License-Identifier: curl
5 */
6
9
11
12#include <utility>
13
14namespace proto_fuzzer {
15
16namespace {
17
20TlsGroupPolicy GroupPolicyFor(curl::fuzzer::proto::TlsGroupProfile profile) {
21 return profile == curl::fuzzer::proto::TLS_GROUP_PROVIDER_DEFAULT ? TlsGroupPolicy::kProviderDefault
23}
24
25} // namespace
26
30H2OriginMockServer::H2OriginMockServer(curl::fuzzer::proto::TlsCertificateChainProfile certificate_chain,
31 curl::fuzzer::proto::TlsGroupProfile group_profile)
32 : TlsMockServer(TlsApplicationProtocol::kHttp2, certificate_chain, GroupPolicyFor(group_profile)) {}
33
34H2OriginMockServer::~H2OriginMockServer() {
35 // The multi borrows runtime_ for push callbacks, and connections borrow its
36 // client-frame observer. Release both while that member is still alive.
37 retained_multi_.reset();
39}
40
49 (void)curl_easy_setopt(easy, CURLOPT_SSL_EC_CURVES, "X25519");
50 }
51 (void)curl_easy_setopt(easy, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
52 (void)curl_easy_setopt(easy, CURLOPT_UPKEEP_INTERVAL_MS, 0L);
53}
54
57std::unique_ptr<MockConnection> H2OriginMockServer::CreateConnection() {
58 std::unique_ptr<MockConnection> connection = TlsMockServer::CreateConnection();
59 runtime_.AttachConnection(connection.get());
60 return connection;
61}
62
67void H2OriginMockServer::RunLoop(CURLM* multi, CURL* easy, const curl::fuzzer::proto::Scenario& scenario) {
68 runtime_.PrepareMulti(multi, scenario.accept_h2_push());
69 if (!scenario.has_http2_plan()) {
70 MockServer::RunLoop(multi, easy, scenario);
71 } else {
72 SetScripts(scenario);
73 runtime_.ResetPlan(scenario.http2_plan(), "https");
74 runtime_.DrivePlan(multi, *this, kMaxIdleIterations, kMaxDriveIterations, [this, easy] {
77 runtime_.ApplyPostHeadersTransition(easy);
78 });
79 }
80 runtime_.FinishTransfer(easy, connection());
81}
82
86void H2OriginMockServer::HandleDetachedMulti(CurlMultiPtr multi) { retained_multi_ = std::move(multi); }
87
90const H2Runtime& H2OriginMockServer::runtime() const { return runtime_; }
91
94
95} // namespace proto_fuzzer
H2OriginMockServer(curl::fuzzer::proto::TlsCertificateChainProfile certificate_chain=curl::fuzzer::proto::TLS_CERTIFICATE_CHAIN_DEFAULT_EC, curl::fuzzer::proto::TlsGroupProfile group_profile=curl::fuzzer::proto::TLS_GROUP_X25519)
Construct an HTTP/2 TLS peer with the selected certificate chain.
const H2Runtime & runtime() const
Expose shared protocol observations without allowing carrier state changes.
void RunLoop(CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
Run the raw HTTP/2 response driver and probe server push and upkeep APIs.
void HandleDetachedMulti(CurlMultiPtr multi) override
Keep the connection cache alive until this mock is destroyed, after the caller has cleaned the detach...
void Install(CURL *easy) override
Keep transport selection out of the mutation grammar.
std::unique_ptr< MockConnection > CreateConnection() override
Attach the reusable H2 client-frame tracker after TLS decryption.
Protocol state shared by TLS and plaintext HTTP/2 origin peers.
Definition h2_runtime.h:33
std::size_t additional_handle_cleanup_count() const
static constexpr int kMaxDriveIterations
Hard operation budget for one scenario.
void ResumeResponseIfRequested(CURL *easy)
Resume receive-side callback output at one bounded drive boundary when the dedicated API plan request...
static constexpr int kMaxIdleIterations
Consecutive no-progress budget for ordinary scenarios.
void ResetConnections()
Release all current and retired socketpairs before resetting transport- specific state.
void RunLoop(CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
Seed the mock from the scenario, then drive the perform loop until curl is done or a deterministic op...
void SetScripts(const curl::fuzzer::proto::Scenario &scenario)
Build the complete borrowed script table before entering curl.
void Install(CURL *easy) override
Install common socket callbacks and a stable local trust anchor.
TlsMockServer()
Build one reusable in-process server context per fuzz iteration.
TlsGroupPolicy group_policy() const
void ObserveActiveTransfer(CURL *easy) override
Query while the connection filters are attached.
std::unique_ptr< MockConnection > CreateConnection() override
Wrap one socketpair server endpoint in an OpenSSL acceptor consumed by MockServer.
std::unique_ptr< CURLM, CurlMultiDeleter > CurlMultiPtr
Unique ownership of a CURL multi handle.
Definition curl_raii.h:58
HTTPS origin peer with a fixed HTTP/2 application protocol.
TlsGroupPolicy
Key-exchange group policy fixed when a TLS peer is constructed.
@ kProviderDefault
Retain the linked OpenSSL provider's preferred group ordering.
@ kX25519
Restrict negotiation to the inexpensive X25519 group.
TlsApplicationProtocol
Application protocol selected by the in-process TLS peer.
@ kHttp2
The dedicated proxy peer exchanges HTTP/2 frames after its handshake.