• 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

33.8
/src/fuzzer/tls_server.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/data_src.h>
10
#include <botan/hex.h>
11
#include <botan/pkcs8.h>
12
#include <botan/tls_server.h>
13
#include <botan/tls_session_manager_noop.h>
14

15
#include <memory>
16

17
namespace {
18

19
const char* const fixed_ecdsa_key =
20
   "-----BEGIN PRIVATE KEY-----"
21
   "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgfUjnfxgvrIyrqa5N"
22
   "47X1W50cVStDPbASwRcY6zqehjyhRANCAAQTNF0poMBM4tuCY50NrDJU8za/SK45"
23
   "erOdFpGK7KRWtBE9zNj6J0f1UB+K8GdekFD2me+iL63v+uBqo/PHRPT9"
24
   "-----END PRIVATE KEY-----";
25

26
const char* const fixed_ecdsa_cert =
27
   "-----BEGIN CERTIFICATE-----"
28
   "MIIB3zCCAYWgAwIBAgIRAPFi6dun9OY7YLuZHqKzdEMwCgYIKoZIzj0EAwIwOTEa"
29
   "MBgGA1UEAwwRSXQncyBGdXp6aW5nIFRpbWUxCzAJBgNVBAYTAlZUMQ4wDAYDVQQK"
30
   "EwVCb3RhbjAeFw0yNTAxMjAxMzI0MjdaFw0zODAxMTgxMzI0MjdaMDkxGjAYBgNV"
31
   "BAMMEUl0J3MgRnV6emluZyBUaW1lMQswCQYDVQQGEwJWVDEOMAwGA1UEChMFQm90"
32
   "YW4wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQTNF0poMBM4tuCY50NrDJU8za/"
33
   "SK45erOdFpGK7KRWtBE9zNj6J0f1UB+K8GdekFD2me+iL63v+uBqo/PHRPT9o24w"
34
   "bDAhBgNVHQ4EGgQYevp/SCkZVWPKNAUSez17HTOyneXEWwpEMBQGA1UdEQQNMAuC"
35
   "CWxvY2FsaG9zdDAMBgNVHRMBAf8EAjAAMCMGA1UdIwQcMBqAGHr6f0gpGVVjyjQF"
36
   "Ens9ex0zsp3lxFsKRDAKBggqhkjOPQQDAgNIADBFAiEApqVCYhySxK/8GLq8wlPh"
37
   "MeBg8CwKO83s1h/GYQZD4CUCID5Mzh5mwrkkAuSENjLXAD4dtiu91Zsoye5J0uuU"
38
   "60v7"
39
   "-----END CERTIFICATE-----";
40

41
class Fuzzer_TLS_Server_Creds : public Botan::Credentials_Manager {
42
   public:
43
      Fuzzer_TLS_Server_Creds() {
1,128✔
44
         Botan::DataSource_Memory cert_in(fixed_ecdsa_cert);
1,128✔
45
         m_ecdsa_cert = std::make_unique<Botan::X509_Certificate>(cert_in);
1,128✔
46

47
         Botan::DataSource_Memory key_in(fixed_ecdsa_key);
1,128✔
48
         m_ecdsa_key.reset(Botan::PKCS8::load_key(key_in).release());
2,256✔
49
      }
2,256✔
50

51
      std::vector<Botan::X509_Certificate> cert_chain(
×
52
         const std::vector<std::string>& algos,
53
         const std::vector<Botan::AlgorithmIdentifier>& /*signature_schemes*/,
54
         const std::string& /*type*/,
55
         const std::string& /*hostname*/) override {
56
         std::vector<Botan::X509_Certificate> v;
×
57

58
         for(const auto& algo : algos) {
×
59
            if(algo == "ECDSA") {
×
60
               v.push_back(*m_ecdsa_cert);
×
61
               break;
62
            }
63
         }
64

65
         return v;
×
66
      }
×
67

68
      std::shared_ptr<Botan::Private_Key> private_key_for(const Botan::X509_Certificate& /*cert*/,
×
69
                                                          const std::string& type,
70
                                                          const std::string& /*context*/) override {
71
         if(type == "ECDSA") {
×
72
            return m_ecdsa_key;
×
73
         }
74
         return nullptr;
×
75
      }
76

77
      Botan::secure_vector<uint8_t> session_ticket_key() override {
×
78
         return Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899");
×
79
      }
80

81
      Botan::secure_vector<uint8_t> dtls_cookie_secret() override {
×
82
         return Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899");
×
83
      }
84

85
      std::string psk_identity_hint(const std::string& /*type*/, const std::string& /*context*/) override {
×
86
         return "psk_hint";
×
87
      }
88

89
      std::string psk_identity(const std::string& /*type*/,
×
90
                               const std::string& /*context*/,
91
                               const std::string& /*hint*/) override {
92
         return "psk_id";
×
93
      }
94

95
      std::vector<Botan::TLS::ExternalPSK> find_preshared_keys(
×
96
         std::string_view host,
97
         Botan::TLS::Connection_Side whoami,
98
         const std::vector<std::string>& identities = {},
99
         const std::optional<std::string>& prf = std::nullopt) override {
100
         if(!identities.empty() && std::find(identities.begin(), identities.end(), "psk_id") == identities.end()) {
×
101
            return Botan::Credentials_Manager::find_preshared_keys(host, whoami, identities, prf);
×
102
         }
103

104
         std::vector<Botan::TLS::ExternalPSK> psks;
×
105
         psks.emplace_back("psk_id", "SHA-256", Botan::hex_decode_locked("AABBCCDDEEFF00112233445566778899"));
×
106
         return psks;
×
107
      }
×
108

109
   private:
110
      std::unique_ptr<Botan::X509_Certificate> m_ecdsa_cert;
111
      std::shared_ptr<Botan::Private_Key> m_ecdsa_key;
112
};
113

114
class Fuzzer_TLS_Policy : public Botan::TLS::Policy {
2,256✔
115
   public:
116
      std::vector<uint16_t> ciphersuite_list(Botan::TLS::Protocol_Version version) const override {
×
117
         std::vector<uint16_t> ciphersuites;
×
118

119
         for(auto&& suite : Botan::TLS::Ciphersuite::all_known_ciphersuites()) {
×
120
            if(suite.valid() and suite.usable_in_version(version)) {
×
121
               ciphersuites.push_back(suite.ciphersuite_code());
×
122
            }
123
         }
124

125
         return ciphersuites;
×
126
      }
×
127
};
128

129
class Fuzzer_TLS_Server_Callbacks : public Botan::TLS::Callbacks {
2,256✔
130
   public:
131
      void tls_emit_data(std::span<const uint8_t> /*data*/) override {
1,105✔
132
         // discard
133
      }
1,105✔
134

135
      void tls_record_received(uint64_t /*rec*/, std::span<const uint8_t> /*data*/) override {
×
136
         // ignore peer data
137
      }
×
138

139
      void tls_alert(Botan::TLS::Alert /*alert*/) override {
×
140
         // ignore alert
141
      }
×
142

143
      std::string tls_server_choose_app_protocol(const std::vector<std::string>& client_protos) override {
×
144
         if(client_protos.size() > 1) {
×
145
            return client_protos[0];
×
146
         } else {
147
            return "fuzzy";
×
148
         }
149
      }
150

151
      void tls_verify_cert_chain(const std::vector<Botan::X509_Certificate>& cert_chain,
×
152
                                 const std::vector<std::optional<Botan::OCSP::Response>>& ocsp_responses,
153
                                 const std::vector<Botan::Certificate_Store*>& trusted_roots,
154
                                 Botan::Usage_Type usage,
155
                                 std::string_view hostname,
156
                                 const Botan::TLS::Policy& policy) override {
157
         try {
×
158
            // try to validate to exercise those code paths
159
            Botan::TLS::Callbacks::tls_verify_cert_chain(
×
160
               cert_chain, ocsp_responses, trusted_roots, usage, hostname, policy);
161
         } catch(...) {
×
162
            // ignore validation result
163
         }
×
164
      }
×
165
};
166

167
}  // namespace
168

169
void fuzz(std::span<const uint8_t> in) {
1,131✔
170
   if(in.size() <= 1) {
1,131✔
171
      return;
3✔
172
   }
173

174
   auto session_manager = std::make_shared<Botan::TLS::Session_Manager_Noop>();
1,128✔
175
   auto policy = std::make_shared<Fuzzer_TLS_Policy>();
1,128✔
176
   const Botan::TLS::Server_Information info("server.name", 443);
1,128✔
177
   auto creds = std::make_shared<Fuzzer_TLS_Server_Creds>();
1,128✔
178
   auto callbacks = std::make_shared<Fuzzer_TLS_Server_Callbacks>();
1,128✔
179

180
   const bool is_datagram = (in[0] & 1) == 1;
1,128✔
181

182
   Botan::TLS::Server server(callbacks, session_manager, creds, policy, fuzzer_rng_as_shared(), is_datagram);
6,768✔
183

184
   try {
1,128✔
185
      server.received_data(in.subspan(1, in.size() - 1));
1,128✔
186
   } catch(std::exception& e) {}
1,105✔
187
}
6,768✔
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