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

randombit / botan / 5356326050

23 Jun 2023 01:05PM UTC coverage: 91.728% (-0.008%) from 91.736%
5356326050

Pull #3595

github

web-flow
Merge a5b917599 into 92171c524
Pull Request #3595: Improve clang-tidy coverage

78163 of 85212 relevant lines covered (91.73%)

12690161.35 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

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

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

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

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

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

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

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

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

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