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

randombit / botan / 20512202773

25 Dec 2025 11:09PM UTC coverage: 90.326% (-0.002%) from 90.328%
20512202773

push

github

web-flow
Merge pull request #5169 from randombit/jack/clang-tidy-config-updates

Some configuration updates for clang-tidy

101306 of 112156 relevant lines covered (90.33%)

12877185.6 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_client.h>
11
#include <botan/tls_session_manager_noop.h>
12

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

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

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

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

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

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

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

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

59
         return ciphersuites;
1,962✔
60
      }
×
61
};
62

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

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

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

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

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

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

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

107
   try {
1,962✔
108
      client.received_data(in);
1,962✔
109
   } catch(std::exception& e) {}
1,938✔
110
}
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