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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

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

62.5
/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/tls_client.h>
10
#include <botan/tls_session_manager_noop.h>
11

12
class Fuzzer_TLS_Client_Creds : public Botan::Credentials_Manager {
1,962✔
13
   public:
14
      std::string psk_identity_hint(const std::string&, const std::string&) override { return "psk_hint"; }
×
15

16
      std::string psk_identity(const std::string&, const std::string&, const std::string&) override { return "psk_id"; }
×
17

18
      Botan::SymmetricKey psk(const std::string&, const std::string&, const std::string&) override {
×
19
         return Botan::SymmetricKey("AABBCCDDEEFF00112233445566778899");
×
20
      }
21
};
22

23
class Fuzzer_TLS_Policy : public Botan::TLS::Policy {
1,962✔
24
   public:
25
      std::vector<uint16_t> ciphersuite_list(Botan::TLS::Protocol_Version) const override {
1,962✔
26
         std::vector<uint16_t> ciphersuites;
1,962✔
27

28
         for(auto&& suite : Botan::TLS::Ciphersuite::all_known_ciphersuites()) {
186,390✔
29
            if(suite.valid() == false)
184,428✔
30
               ciphersuites.push_back(suite.ciphersuite_code());
×
31
         }
32

33
         return ciphersuites;
1,962✔
34
      }
×
35
};
36

37
class Fuzzer_TLS_Client_Callbacks : public Botan::TLS::Callbacks {
1,962✔
38
   public:
39
      void tls_emit_data(std::span<const uint8_t>) override {
3,918✔
40
         // discard
41
      }
3,918✔
42

43
      void tls_record_received(uint64_t, std::span<const uint8_t>) override {
×
44
         // ignore peer data
45
      }
×
46

47
      void tls_alert(Botan::TLS::Alert) override {
4✔
48
         // ignore alert
49
      }
4✔
50

51
      void tls_verify_cert_chain(const std::vector<Botan::X509_Certificate>& cert_chain,
×
52
                                 const std::vector<std::optional<Botan::OCSP::Response>>& ocsp_responses,
53
                                 const std::vector<Botan::Certificate_Store*>& trusted_roots,
54
                                 Botan::Usage_Type usage,
55
                                 std::string_view hostname,
56
                                 const Botan::TLS::Policy& policy) override {
57
         try {
×
58
            // try to validate to exercise those code paths
59
            Botan::TLS::Callbacks::tls_verify_cert_chain(
×
60
               cert_chain, ocsp_responses, trusted_roots, usage, hostname, policy);
61
         } catch(...) {
×
62
            // ignore validation result
63
         }
×
64
      }
×
65
};
66

67
void fuzz(const uint8_t in[], size_t len) {
1,962✔
68
   if(len == 0)
1,962✔
69
      return;
×
70

71
   auto session_manager = std::make_shared<Botan::TLS::Session_Manager_Noop>();
1,962✔
72
   auto policy = std::make_shared<Fuzzer_TLS_Policy>();
1,962✔
73
   Botan::TLS::Protocol_Version client_offer = Botan::TLS::Protocol_Version::TLS_V12;
1,962✔
74
   Botan::TLS::Server_Information info("server.name", 443);
1,962✔
75
   auto callbacks = std::make_shared<Fuzzer_TLS_Client_Callbacks>();
1,962✔
76
   auto creds = std::make_shared<Fuzzer_TLS_Client_Creds>();
1,962✔
77

78
   Botan::TLS::Client client(callbacks, session_manager, creds, policy, fuzzer_rng_as_shared(), info, client_offer);
13,734✔
79

80
   try {
1,962✔
81
      client.received_data(in, len);
1,962✔
82
   } catch(std::exception& e) {}
1,956✔
83
}
9,810✔
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

© 2025 Coveralls, Inc