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

randombit / botan / 25357679674

04 May 2026 07:12PM UTC coverage: 89.323% (-0.05%) from 89.377%
25357679674

push

github

web-flow
Merge pull request #5567 from randombit/jack/http-crlf

Check for newline and null characters in HTTP inputs

107390 of 120226 relevant lines covered (89.32%)

11491029.57 hits per line

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

93.02
/src/lib/tls/tls_ciphersuite.cpp
1
/*
2
* TLS Cipher Suite
3
* (C) 2004-2010,2012,2013 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/tls_ciphersuite.h>
9

10
#include <botan/assert.h>
11
#include <botan/exceptn.h>
12
#include <algorithm>
13

14
namespace Botan::TLS {
15

16
size_t Ciphersuite::nonce_bytes_from_handshake() const {
5,959✔
17
   switch(m_nonce_format) {
5,959✔
18
      case Nonce_Format::CBC_MODE:
19
         return 0;
20
      case Nonce_Format::AEAD_IMPLICIT_4:
21
         return 4;
22
      case Nonce_Format::AEAD_XOR_12:
23
         return 12;
24
      case Nonce_Format::NULL_CIPHER:
25
         return 0;
26
   }
27

28
   throw Invalid_State("In Ciphersuite::nonce_bytes_from_handshake invalid enum value");
×
29
}
30

31
size_t Ciphersuite::nonce_bytes_from_record(Protocol_Version version) const {
3,905✔
32
   BOTAN_UNUSED(version);
3,905✔
33
   switch(m_nonce_format) {
3,905✔
34
      case Nonce_Format::CBC_MODE:
576✔
35
         return cipher_algo() == "3DES" ? 8 : 16;
1,061✔
36
      case Nonce_Format::AEAD_IMPLICIT_4:
37
         return 8;
38
      case Nonce_Format::AEAD_XOR_12:
2,433✔
39
      case Nonce_Format::NULL_CIPHER:
2,433✔
40
         return 0;
2,433✔
41
   }
42

43
   throw Invalid_State("In Ciphersuite::nonce_bytes_from_handshake invalid enum value");
×
44
}
45

46
bool Ciphersuite::is_scsv(uint16_t suite) {
3,000✔
47
   // Both signaling cipher suite values - skip them when iterating
48
   // negotiable ciphersuites. The two callers are:
49
   //
50
   // - 0x00FF: TLS_EMPTY_RENEGOTIATION_INFO_SCSV (RFC 5746). Consumed by
51
   //   Client_Hello_12::Client_Hello_12 to set secure_renegotiation when
52
   //   the renegotiation_info extension is absent.
53
   //
54
   // - 0x5600: TLS_FALLBACK_SCSV (RFC 7507). Recognized so it is filtered
55
   //   out of negotiation, but the inappropriate_fallback enforcement is
56
   //   intentionally not implemented:
57
   //     * Botan does not support TLS 1.0 / 1.1, so the 1.2 -> 1.0/1.1
58
   //       fallback that SCSV was originally designed to detect cannot
59
   //       occur here.
60
   //     * The 1.3 -> 1.2 downgrade is already protected by the
61
   //       ServerHello.random sentinel (RFC 8446 4.1.3, DOWNGRADE_TLS12),
62
   //       which Botan's TLS 1.3 client enforces at
63
   //       tls_client_impl_13.cpp via random_signals_downgrade().
64
   //
65
   // TODO: derive from IANA file in script
66
   return (suite == 0x00FF || suite == 0x5600);
3,000✔
67
}
68

69
bool Ciphersuite::psk_ciphersuite() const {
1,097✔
70
   return kex_method() == Kex_Algo::PSK || kex_method() == Kex_Algo::ECDHE_PSK;
1,097✔
71
}
72

73
bool Ciphersuite::ecc_ciphersuite() const {
1,080✔
74
   return kex_method() == Kex_Algo::ECDH || kex_method() == Kex_Algo::ECDHE_PSK || auth_method() == Auth_Method::ECDSA;
1,080✔
75
}
76

77
bool Ciphersuite::usable_in_version(Protocol_Version version) const {
643,579✔
78
   // RFC 8446 B.4.:
79
   //   Although TLS 1.3 uses the same cipher suite space as previous
80
   //   versions of TLS, TLS 1.3 cipher suites are defined differently, only
81
   //   specifying the symmetric ciphers, and cannot be used for TLS 1.2.
82
   //   Similarly, cipher suites for TLS 1.2 and lower cannot be used with
83
   //   TLS 1.3.
84
   //
85
   // Currently cipher suite codes {0x13,0x01} through {0x13,0x05} are
86
   // allowed for TLS 1.3. This may change in the future.
87
   const auto is_legacy_suite = (ciphersuite_code() & 0xFF00) != 0x1300;
643,579✔
88
   return version.is_pre_tls_13() == is_legacy_suite;
643,579✔
89
}
90

91
bool Ciphersuite::cbc_ciphersuite() const {
884✔
92
   return (mac_algo() != "AEAD" && cipher_algo() != "NULL");
1,140✔
93
}
94

95
bool Ciphersuite::null_ciphersuite() const {
182✔
96
   return (cipher_algo() == "NULL");
182✔
97
}
98

99
bool Ciphersuite::aead_ciphersuite() const {
3,017✔
100
   return (mac_algo() == "AEAD");
3,017✔
101
}
102

103
bool Ciphersuite::signature_used() const {
10,258✔
104
   return auth_method() != Auth_Method::IMPLICIT;
10,258✔
105
}
106

107
bool Ciphersuite::is_certificate_required() const {
4,654✔
108
   return signature_used() || kex_method() == Kex_Algo::STATIC_RSA;
4,654✔
109
}
110

111
std::optional<Ciphersuite> Ciphersuite::by_id(uint16_t suite) {
82,314✔
112
   const std::vector<Ciphersuite>& all_suites = all_known_ciphersuites();
82,314✔
113
   auto s = std::lower_bound(all_suites.begin(), all_suites.end(), suite);
82,314✔
114

115
   if(s != all_suites.end() && s->ciphersuite_code() == suite) {
82,314✔
116
      return *s;
16,834✔
117
   }
118

119
   return std::nullopt;  // some unknown ciphersuite
65,480✔
120
}
121

122
std::optional<Ciphersuite> Ciphersuite::from_name(std::string_view name) {
89✔
123
   const std::vector<Ciphersuite>& all_suites = all_known_ciphersuites();
89✔
124

125
   for(const auto& suite : all_suites) {
2,672✔
126
      if(suite.to_string() == name) {
8,016✔
127
         return suite;
89✔
128
      }
129
   }
130

131
   return std::nullopt;  // some unknown ciphersuite
×
132
}
133

134
}  // namespace Botan::TLS
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