Coverage Report

Created: 2026-12-01 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/curl_fuzzer/proto_fuzzer/tls_session_archive.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 Owns one bounded session copied through curl's public TLS APIs.
9
10
#ifndef PROTO_FUZZER_TLS_SESSION_ARCHIVE_H_
11
#define PROTO_FUZZER_TLS_SESSION_ARCHIVE_H_
12
13
#include <curl/curl.h>
14
15
#include <cstddef>
16
#include <string>
17
#include <vector>
18
19
namespace proto_fuzzer {
20
21
/// Own every value from one curl_easy_ssls_export callback. Curl owns the
22
/// callback pointers, so the archive copies them before the callback returns.
23
class TlsSessionArchive {
24
 public:
25
  /// Create an empty archive.
26
96.5k
  TlsSessionArchive() = default;
27
28
  /// The archive has unique ownership of its copied session data.
29
  TlsSessionArchive(const TlsSessionArchive&) = delete;
30
  /// The archive has unique ownership of its copied session data.
31
  TlsSessionArchive& operator=(const TlsSessionArchive&) = delete;
32
  /// Move all copied session data into a new archive.
33
  TlsSessionArchive(TlsSessionArchive&&) = default;
34
  /// Replace this archive with moved session data.
35
  /// @return this archive after the replacement.
36
  TlsSessionArchive& operator=(TlsSessionArchive&&) = default;
37
38
  CURLcode CaptureFrom(CURL* easy);
39
40
  CURLcode ImportBySaltedHash(CURL* easy) const;
41
  CURLcode ImportBySessionKey(CURL* easy) const;
42
  CURLcode ImportMalformedSaltedHash(CURL* easy) const;
43
44
  bool empty() const;
45
  const std::string& session_key() const;
46
  const std::vector<unsigned char>& salted_hash() const;
47
  const std::vector<unsigned char>& session_data() const;
48
  curl_off_t valid_until() const;
49
  int ietf_tls_id() const;
50
  const std::string& alpn() const;
51
  std::size_t early_data_max() const;
52
53
 private:
54
  static CURLcode Capture(CURL* easy, void* user_data, const char* session_key, const unsigned char* salted_hash,
55
                          std::size_t salted_hash_size, const unsigned char* session_data,
56
                          std::size_t session_data_size, curl_off_t valid_until, int ietf_tls_id, const char* alpn,
57
                          std::size_t early_data_max);
58
59
  std::string session_key_;
60
  std::vector<unsigned char> salted_hash_;
61
  std::vector<unsigned char> session_data_;
62
  curl_off_t valid_until_ = 0;
63
  int ietf_tls_id_ = 0;
64
  std::string alpn_;
65
  std::size_t early_data_max_ = 0;
66
};
67
68
}  // namespace proto_fuzzer
69
70
#endif  // PROTO_FUZZER_TLS_SESSION_ARCHIVE_H_