/src/curl_fuzzer/proto_fuzzer/tls_session_replay.cc
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 Fresh easy-handle and share ownership for TLS session replay. |
9 | | |
10 | | #include "proto_fuzzer/tls_session_replay.h" |
11 | | |
12 | | #include "proto_fuzzer/curl_raii.h" |
13 | | #include "proto_fuzzer/option_apply.h" |
14 | | #include "proto_fuzzer/request_data.h" |
15 | | #include "proto_fuzzer/tls_mock_server.h" |
16 | | #include "proto_fuzzer/transfer_session.h" |
17 | | |
18 | | namespace proto_fuzzer { |
19 | | |
20 | | /// Replay one archived TLS session after the first transfer owner is gone. |
21 | | /// The share is declared before the transfer so the easy handle detaches and |
22 | | /// closes before curl_share_cleanup runs. |
23 | | /// @param scenario Input used to configure the replay transfer. |
24 | | /// @param url URL installed on the replay easy handle. |
25 | | /// @param server TLS peer that owns the archived session. |
26 | | /// @return Public import and transfer results. |
27 | | TlsSessionReplayResult ReplayTlsSession(const curl::fuzzer::proto::Scenario& scenario, const std::string& url, |
28 | 27.0k | TlsMockServer* server) { |
29 | 27.0k | TlsSessionReplayResult result; |
30 | 27.0k | CurlSharePtr share(curl_share_init()); |
31 | 27.0k | if (server == nullptr || share == nullptr || |
32 | 27.0k | curl_share_setopt(share.get(), CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION) != CURLSHE_OK) { |
33 | 62 | return result; |
34 | 62 | } |
35 | | |
36 | 26.9k | TransferSession replay; |
37 | 26.9k | if (!replay.PrepareInputFiles(scenario, ScenarioRunMode::kTlsCoverage) || !replay.Initialize()) { |
38 | 14 | return result; |
39 | 14 | } |
40 | 26.9k | CURL* easy = replay.easy(); |
41 | 26.9k | replay.ApplyBaseline(scenario); |
42 | 26.9k | (void)curl_easy_setopt(easy, CURLOPT_URL, url.c_str()); |
43 | 26.9k | server->Install(easy); |
44 | 26.9k | replay.ApplyInputFiles(); |
45 | 26.9k | (void)ApplyScenarioOptions(easy, scenario); |
46 | 26.9k | replay.ApplyPinnedPublicKeyFile(); |
47 | 26.9k | (void)replay.ApplyTlsClientCredentialProfile(scenario.tls_client_credential_profile()); |
48 | 26.9k | if (curl_easy_setopt(easy, CURLOPT_SHARE, share.get()) != CURLE_OK) { |
49 | 0 | return result; |
50 | 0 | } |
51 | | |
52 | 26.9k | ScenarioRequestData* request_data = replay.InstallRequestData(scenario); |
53 | 26.9k | if (request_data == nullptr) { |
54 | 0 | return result; |
55 | 0 | } |
56 | 26.9k | server->ConfigureRequestData(request_data); |
57 | 26.9k | result.import_result = server->ImportArchivedSession(easy); |
58 | 26.9k | result.transfer_result = server->DriveScenario(easy, scenario); |
59 | 26.9k | return result; |
60 | 26.9k | } |
61 | | |
62 | | } // namespace proto_fuzzer |