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

randombit / botan / 20304984263

17 Dec 2025 01:46PM UTC coverage: 90.528% (+0.2%) from 90.358%
20304984263

Pull #5167

github

web-flow
Merge fc6e5fe09 into 3d96b675e
Pull Request #5167: Changes to reduce unnecessary inclusions

101179 of 111766 relevant lines covered (90.53%)

12666117.35 hits per line

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

79.59
/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&, const std::string&) override { return "psk_hint"; }
×
18

19
      std::string psk_identity(const std::string&, const std::string&, const std::string&) override { return "psk_id"; }
1✔
20

21
      Botan::secure_vector<uint8_t> session_ticket_key() override {
×
22
         return Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899");
×
23
      }
24

25
      Botan::secure_vector<uint8_t> dtls_cookie_secret() override {
×
26
         return Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899");
×
27
      }
28

29
      std::vector<Botan::TLS::ExternalPSK> find_preshared_keys(
1✔
30
         std::string_view host,
31
         Botan::TLS::Connection_Side whoami,
32
         const std::vector<std::string>& identities = {},
33
         const std::optional<std::string>& prf = std::nullopt) override {
34
         if(!identities.empty() && std::find(identities.begin(), identities.end(), "psk_id") == identities.end()) {
1✔
35
            return Botan::Credentials_Manager::find_preshared_keys(host, whoami, identities, prf);
×
36
         }
37

38
         std::vector<Botan::TLS::ExternalPSK> psks;
1✔
39
         psks.emplace_back("psk_id", "SHA-256", Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899"));
1✔
40
         return psks;
1✔
41
      }
1✔
42
};
43

44
class Fuzzer_TLS_Policy : public Botan::TLS::Policy {
1,962✔
45
   public:
46
      std::vector<uint16_t> ciphersuite_list(Botan::TLS::Protocol_Version) const override {
1,962✔
47
         std::vector<uint16_t> ciphersuites;
1,962✔
48

49
         for(auto&& suite : Botan::TLS::Ciphersuite::all_known_ciphersuites()) {
202,086✔
50
            if(suite.valid()) {
200,124✔
51
               ciphersuites.push_back(suite.ciphersuite_code());
200,124✔
52
            }
53
         }
54

55
         return ciphersuites;
1,962✔
56
      }
×
57
};
58

59
class Fuzzer_TLS_Client_Callbacks : public Botan::TLS::Callbacks {
1,962✔
60
   public:
61
      void tls_emit_data(std::span<const uint8_t>) override {
3,981✔
62
         // discard
63
      }
3,981✔
64

65
      void tls_record_received(uint64_t, std::span<const uint8_t>) override {
×
66
         // ignore peer data
67
      }
×
68

69
      void tls_alert(Botan::TLS::Alert) override {
4✔
70
         // ignore alert
71
      }
4✔
72

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

89
void fuzz(std::span<const uint8_t> in) {
1,962✔
90
   if(in.empty()) {
1,962✔
91
      return;
×
92
   }
93

94
   auto session_manager = std::make_shared<Botan::TLS::Session_Manager_Noop>();
1,962✔
95
   auto policy = std::make_shared<Fuzzer_TLS_Policy>();
1,962✔
96
   const Botan::TLS::Protocol_Version client_offer = Botan::TLS::Protocol_Version::TLS_V12;
1,962✔
97
   const Botan::TLS::Server_Information info("server.name", 443);
1,962✔
98
   auto callbacks = std::make_shared<Fuzzer_TLS_Client_Callbacks>();
1,962✔
99
   auto creds = std::make_shared<Fuzzer_TLS_Client_Creds>();
1,962✔
100

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

103
   try {
1,962✔
104
      client.received_data(in);
1,962✔
105
   } catch(std::exception& e) {}
1,938✔
106
}
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