• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 20579846577

29 Dec 2025 06:24PM UTC coverage: 90.415% (+0.2%) from 90.243%
20579846577

push

github

web-flow
Merge pull request #5167 from randombit/jack/src-size-reductions

Changes to reduce unnecessary inclusions

101523 of 112285 relevant lines covered (90.42%)

12817276.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.43
/src/fuzzer/tls_client.cpp
1
/*
2
* (C) 2015,2016 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "fuzzers.h"
8

9
#include <botan/hex.h>
10
#include <botan/tls_callbacks.h>
11
#include <botan/tls_client.h>
12
#include <botan/tls_policy.h>
13
#include <botan/tls_session_manager_noop.h>
14

15
class Fuzzer_TLS_Client_Creds : public Botan::Credentials_Manager {
1,962✔
16
   public:
17
      std::string psk_identity_hint(const std::string& /*type*/, const std::string& /*context*/) override {
×
18
         return "psk_hint";
×
19
      }
20

21
      std::string psk_identity(const std::string& /*type*/,
1✔
22
                               const std::string& /*context*/,
23
                               const std::string& /*hint*/) override {
24
         return "psk_id";
1✔
25
      }
26

27
      Botan::secure_vector<uint8_t> session_ticket_key() override {
×
28
         return Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899");
×
29
      }
30

31
      Botan::secure_vector<uint8_t> dtls_cookie_secret() override {
×
32
         return Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899");
×
33
      }
34

35
      std::vector<Botan::TLS::ExternalPSK> find_preshared_keys(
1✔
36
         std::string_view host,
37
         Botan::TLS::Connection_Side whoami,
38
         const std::vector<std::string>& identities = {},
39
         const std::optional<std::string>& prf = std::nullopt) override {
40
         if(!identities.empty() && std::find(identities.begin(), identities.end(), "psk_id") == identities.end()) {
1✔
41
            return Botan::Credentials_Manager::find_preshared_keys(host, whoami, identities, prf);
×
42
         }
43

44
         std::vector<Botan::TLS::ExternalPSK> psks;
1✔
45
         psks.emplace_back("psk_id", "SHA-256", Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899"));
1✔
46
         return psks;
1✔
47
      }
1✔
48
};
49

50
class Fuzzer_TLS_Policy : public Botan::TLS::Policy {
1,962✔
51
   public:
52
      std::vector<uint16_t> ciphersuite_list(Botan::TLS::Protocol_Version version) const override {
1,962✔
53
         std::vector<uint16_t> ciphersuites;
1,962✔
54

55
         for(auto&& suite : Botan::TLS::Ciphersuite::all_known_ciphersuites()) {
202,086✔
56
            if(suite.valid() && suite.usable_in_version(version)) {
200,124✔
57
               ciphersuites.push_back(suite.ciphersuite_code());
190,314✔
58
            }
59
         }
60

61
         return ciphersuites;
1,962✔
62
      }
×
63
};
64

65
class Fuzzer_TLS_Client_Callbacks : public Botan::TLS::Callbacks {
1,962✔
66
   public:
67
      void tls_emit_data(std::span<const uint8_t> /*data*/) override {
3,981✔
68
         // discard
69
      }
3,981✔
70

71
      void tls_record_received(uint64_t /*rec*/, std::span<const uint8_t> /*data*/) override {
×
72
         // ignore peer data
73
      }
×
74

75
      void tls_alert(Botan::TLS::Alert /*alert*/) override {
4✔
76
         // ignore alert
77
      }
4✔
78

79
      void tls_verify_cert_chain(const std::vector<Botan::X509_Certificate>& cert_chain,
258✔
80
                                 const std::vector<std::optional<Botan::OCSP::Response>>& ocsp_responses,
81
                                 const std::vector<Botan::Certificate_Store*>& trusted_roots,
82
                                 Botan::Usage_Type usage,
83
                                 std::string_view hostname,
84
                                 const Botan::TLS::Policy& policy) override {
85
         try {
258✔
86
            // try to validate to exercise those code paths
87
            Botan::TLS::Callbacks::tls_verify_cert_chain(
258✔
88
               cert_chain, ocsp_responses, trusted_roots, usage, hostname, policy);
89
         } catch(...) {
258✔
90
            // ignore validation result
91
         }
258✔
92
      }
258✔
93
};
94

95
void fuzz(std::span<const uint8_t> in) {
1,962✔
96
   if(in.empty()) {
1,962✔
97
      return;
×
98
   }
99

100
   auto session_manager = std::make_shared<Botan::TLS::Session_Manager_Noop>();
1,962✔
101
   auto policy = std::make_shared<Fuzzer_TLS_Policy>();
1,962✔
102
   const Botan::TLS::Protocol_Version client_offer = Botan::TLS::Protocol_Version::TLS_V12;
1,962✔
103
   const Botan::TLS::Server_Information info("server.name", 443);
1,962✔
104
   auto callbacks = std::make_shared<Fuzzer_TLS_Client_Callbacks>();
1,962✔
105
   auto creds = std::make_shared<Fuzzer_TLS_Client_Creds>();
1,962✔
106

107
   Botan::TLS::Client client(callbacks, session_manager, creds, policy, fuzzer_rng_as_shared(), info, client_offer);
15,696✔
108

109
   try {
1,962✔
110
      client.received_data(in);
1,962✔
111
   } catch(std::exception& e) {}
1,938✔
112
}
11,772✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc