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

randombit / botan / 21782759586

07 Feb 2026 12:31PM UTC coverage: 90.073% (-0.001%) from 90.074%
21782759586

push

github

web-flow
Merge pull request #5289 from randombit/jack/header-patrol-2

Further misc header reductions, forward declarations, etc

102244 of 113513 relevant lines covered (90.07%)

11458499.72 hits per line

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

98.63
/src/lib/tls/tls12/msg_certificate_req_12.cpp
1
/*
2
* Certificate Request Message
3
* (C) 2004-2006,2012 Jack Lloyd
4
*     2021 Elektrobit Automotive GmbH
5
*     2022 René Meusel, Hannes Rantzsch - neXenio GmbH
6
*
7
* Botan is released under the Simplified BSD License (see license.txt)
8
*/
9

10
#include <botan/tls_messages_12.h>
11

12
#include <botan/ber_dec.h>
13
#include <botan/der_enc.h>
14
#include <botan/tls_extensions.h>
15
#include <botan/tls_policy.h>
16
#include <botan/internal/fmt.h>
17
#include <botan/internal/tls_handshake_hash.h>
18
#include <botan/internal/tls_handshake_io.h>
19
#include <botan/internal/tls_reader.h>
20

21
namespace Botan::TLS {
22

23
Handshake_Type Certificate_Request_12::type() const {
731✔
24
   return Handshake_Type::CertificateRequest;
731✔
25
}
26

27
namespace {
28

29
std::string cert_type_code_to_name(uint8_t code) {
402✔
30
   switch(code) {
402✔
31
      case 1:
194✔
32
         return "RSA";
194✔
33
      case 64:
195✔
34
         return "ECDSA";
195✔
35
      default:
13✔
36
         return "";  // DH or something else
13✔
37
   }
38
}
39

40
uint8_t cert_type_name_to_code(std::string_view name) {
554✔
41
   if(name == "RSA") {
554✔
42
      return 1;
277✔
43
   }
44
   if(name == "ECDSA") {
277✔
45
      return 64;
277✔
46
   }
47

48
   throw Invalid_Argument(fmt("Unknown/unhandled TLS cert type {}", name));
×
49
}
50

51
}  // namespace
52

53
/**
54
* Create a new Certificate Request message
55
*/
56
Certificate_Request_12::Certificate_Request_12(Handshake_IO& io,
277✔
57
                                               Handshake_Hash& hash,
58
                                               const Policy& policy,
59
                                               const std::vector<X509_DN>& ca_certs) :
277✔
60
      m_names(ca_certs), m_cert_key_types({"RSA", "ECDSA"}) {
1,385✔
61
   m_schemes = policy.acceptable_signature_schemes();
277✔
62
   hash.update(io.send(*this));
554✔
63
}
831✔
64

65
/**
66
* Deserialize a Certificate Request message
67
*/
68
Certificate_Request_12::Certificate_Request_12(const std::vector<uint8_t>& buf) {
200✔
69
   if(buf.size() < 4) {
200✔
70
      throw Decoding_Error("Certificate_Req: Bad certificate request");
1✔
71
   }
72

73
   TLS_Data_Reader reader("CertificateRequest", buf);
199✔
74

75
   const auto cert_type_codes = reader.get_range_vector<uint8_t>(1, 1, 255);
199✔
76

77
   for(const auto cert_type_code : cert_type_codes) {
601✔
78
      const std::string cert_type_name = cert_type_code_to_name(cert_type_code);
402✔
79

80
      if(cert_type_name.empty()) {  // something we don't know
402✔
81
         continue;
13✔
82
      }
83

84
      m_cert_key_types.emplace_back(cert_type_name);
389✔
85
   }
402✔
86

87
   const std::vector<uint8_t> algs = reader.get_range_vector<uint8_t>(2, 2, 65534);
199✔
88

89
   if(algs.size() % 2 != 0) {
195✔
90
      throw Decoding_Error("Bad length for signature IDs in certificate request");
1✔
91
   }
92

93
   for(size_t i = 0; i != algs.size(); i += 2) {
1,869✔
94
      m_schemes.emplace_back(make_uint16(algs[i], algs[i + 1]));
1,679✔
95
   }
96

97
   const uint16_t purported_size = reader.get_uint16_t();
194✔
98

99
   if(reader.remaining_bytes() != purported_size) {
194✔
100
      throw Decoding_Error("Inconsistent length in certificate request");
3✔
101
   }
102

103
   while(reader.has_remaining()) {
361✔
104
      std::vector<uint8_t> name_bits = reader.get_range_vector<uint8_t>(2, 0, 65535);
170✔
105

106
      BER_Decoder decoder(name_bits.data(), name_bits.size());
170✔
107
      X509_DN name;
170✔
108
      decoder.decode(name);
170✔
109
      m_names.emplace_back(name);
170✔
110
   }
340✔
111
}
413✔
112

113
const std::vector<std::string>& Certificate_Request_12::acceptable_cert_types() const {
191✔
114
   return m_cert_key_types;
191✔
115
}
116

117
const std::vector<X509_DN>& Certificate_Request_12::acceptable_CAs() const {
191✔
118
   return m_names;
191✔
119
}
120

121
const std::vector<Signature_Scheme>& Certificate_Request_12::signature_schemes() const {
256✔
122
   return m_schemes;
256✔
123
}
124

125
/**
126
* Serialize a Certificate Request message
127
*/
128
std::vector<uint8_t> Certificate_Request_12::serialize() const {
277✔
129
   std::vector<uint8_t> buf;
277✔
130

131
   std::vector<uint8_t> cert_types;
277✔
132

133
   cert_types.reserve(m_cert_key_types.size());
277✔
134
   for(const auto& cert_key_type : m_cert_key_types) {
831✔
135
      cert_types.push_back(cert_type_name_to_code(cert_key_type));
554✔
136
   }
137

138
   append_tls_length_value(buf, cert_types, 1);
277✔
139

140
   if(!m_schemes.empty()) {
277✔
141
      buf += Signature_Algorithms(m_schemes).serialize(Connection_Side::Server);
554✔
142
   }
143

144
   std::vector<uint8_t> encoded_names;
277✔
145

146
   for(const auto& name : m_names) {
616✔
147
      DER_Encoder encoder;
339✔
148
      encoder.encode(name);
339✔
149

150
      append_tls_length_value(encoded_names, encoder.get_contents(), 2);
678✔
151
   }
339✔
152

153
   append_tls_length_value(buf, encoded_names, 2);
277✔
154

155
   return buf;
277✔
156
}
554✔
157
}  // 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