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

randombit / botan / 21966968252

12 Feb 2026 10:36PM UTC coverage: 90.07% (+0.003%) from 90.067%
21966968252

Pull #5321

github

web-flow
Merge fd30428c7 into e7443105f
Pull Request #5321: Avoid various unneeded include files

102234 of 113505 relevant lines covered (90.07%)

11432801.46 hits per line

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

98.65
/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/pkix_types.h>
15
#include <botan/tls_extensions.h>
16
#include <botan/tls_policy.h>
17
#include <botan/internal/fmt.h>
18
#include <botan/internal/tls_handshake_hash.h>
19
#include <botan/internal/tls_handshake_io.h>
20
#include <botan/internal/tls_reader.h>
21

22
namespace Botan::TLS {
23

24
Certificate_Request_12::~Certificate_Request_12() = default;
938✔
25

26
Handshake_Type Certificate_Request_12::type() const {
732✔
27
   return Handshake_Type::CertificateRequest;
732✔
28
}
29

30
namespace {
31

32
std::string cert_type_code_to_name(uint8_t code) {
404✔
33
   switch(code) {
404✔
34
      case 1:
195✔
35
         return "RSA";
195✔
36
      case 64:
196✔
37
         return "ECDSA";
196✔
38
      default:
13✔
39
         return "";  // DH or something else
13✔
40
   }
41
}
42

43
uint8_t cert_type_name_to_code(std::string_view name) {
556✔
44
   if(name == "RSA") {
556✔
45
      return 1;
278✔
46
   }
47
   if(name == "ECDSA") {
278✔
48
      return 64;
278✔
49
   }
50

51
   throw Invalid_Argument(fmt("Unknown/unhandled TLS cert type {}", name));
×
52
}
53

54
}  // namespace
55

56
/**
57
* Create a new Certificate Request message
58
*/
59
Certificate_Request_12::Certificate_Request_12(Handshake_IO& io,
278✔
60
                                               Handshake_Hash& hash,
61
                                               const Policy& policy,
62
                                               const std::vector<X509_DN>& ca_certs) :
278✔
63
      m_names(ca_certs), m_cert_key_types({"RSA", "ECDSA"}) {
1,390✔
64
   m_schemes = policy.acceptable_signature_schemes();
278✔
65
   hash.update(io.send(*this));
556✔
66
}
834✔
67

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

76
   TLS_Data_Reader reader("CertificateRequest", buf);
200✔
77

78
   const auto cert_type_codes = reader.get_range_vector<uint8_t>(1, 1, 255);
200✔
79

80
   for(const auto cert_type_code : cert_type_codes) {
604✔
81
      const std::string cert_type_name = cert_type_code_to_name(cert_type_code);
404✔
82

83
      if(cert_type_name.empty()) {  // something we don't know
404✔
84
         continue;
13✔
85
      }
86

87
      m_cert_key_types.emplace_back(cert_type_name);
391✔
88
   }
404✔
89

90
   const std::vector<uint8_t> algs = reader.get_range_vector<uint8_t>(2, 2, 65534);
200✔
91

92
   if(algs.size() % 2 != 0) {
196✔
93
      throw Decoding_Error("Bad length for signature IDs in certificate request");
1✔
94
   }
95

96
   for(size_t i = 0; i != algs.size(); i += 2) {
1,879✔
97
      m_schemes.emplace_back(make_uint16(algs[i], algs[i + 1]));
1,688✔
98
   }
99

100
   const uint16_t purported_size = reader.get_uint16_t();
195✔
101

102
   if(reader.remaining_bytes() != purported_size) {
195✔
103
      throw Decoding_Error("Inconsistent length in certificate request");
3✔
104
   }
105

106
   while(reader.has_remaining()) {
364✔
107
      std::vector<uint8_t> name_bits = reader.get_range_vector<uint8_t>(2, 0, 65535);
172✔
108

109
      BER_Decoder decoder(name_bits.data(), name_bits.size());
172✔
110
      X509_DN name;
172✔
111
      decoder.decode(name);
172✔
112
      m_names.emplace_back(name);
172✔
113
   }
344✔
114
}
415✔
115

116
const std::vector<std::string>& Certificate_Request_12::acceptable_cert_types() const {
192✔
117
   return m_cert_key_types;
192✔
118
}
119

120
const std::vector<X509_DN>& Certificate_Request_12::acceptable_CAs() const {
192✔
121
   return m_names;
192✔
122
}
123

124
const std::vector<Signature_Scheme>& Certificate_Request_12::signature_schemes() const {
256✔
125
   return m_schemes;
256✔
126
}
127

128
/**
129
* Serialize a Certificate Request message
130
*/
131
std::vector<uint8_t> Certificate_Request_12::serialize() const {
278✔
132
   std::vector<uint8_t> buf;
278✔
133

134
   std::vector<uint8_t> cert_types;
278✔
135

136
   cert_types.reserve(m_cert_key_types.size());
278✔
137
   for(const auto& cert_key_type : m_cert_key_types) {
834✔
138
      cert_types.push_back(cert_type_name_to_code(cert_key_type));
556✔
139
   }
140

141
   append_tls_length_value(buf, cert_types, 1);
278✔
142

143
   if(!m_schemes.empty()) {
278✔
144
      buf += Signature_Algorithms(m_schemes).serialize(Connection_Side::Server);
556✔
145
   }
146

147
   std::vector<uint8_t> encoded_names;
278✔
148

149
   for(const auto& name : m_names) {
619✔
150
      DER_Encoder encoder;
341✔
151
      encoder.encode(name);
341✔
152

153
      append_tls_length_value(encoded_names, encoder.get_contents(), 2);
682✔
154
   }
341✔
155

156
   append_tls_length_value(buf, encoded_names, 2);
278✔
157

158
   return buf;
278✔
159
}
556✔
160
}  // 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