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

randombit / botan / 21848380424

10 Feb 2026 01:47AM UTC coverage: 91.634% (+1.6%) from 90.069%
21848380424

push

github

web-flow
Merge pull request #5296 from randombit/jack/tls-header-patrol

Various changes to reduce header dependencies in TLS

104002 of 113497 relevant lines covered (91.63%)

11230277.53 hits per line

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

88.89
/src/lib/tls/tls13/msg_certificate_req_13.cpp
1
/*
2
* (C) 2022 Jack Lloyd
3
* (C) 2022 Hannes Rantzsch, René Meusel - neXenio GmbH
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/tls_messages_13.h>
9

10
#include <botan/certstor.h>
11
#include <botan/credentials_manager.h>
12
#include <botan/pkix_types.h>
13
#include <botan/tls_callbacks.h>
14
#include <botan/tls_exceptn.h>
15
#include <botan/tls_policy.h>
16
#include <botan/internal/tls_reader.h>
17

18
namespace Botan::TLS {
19

20
Handshake_Type Certificate_Request_13::type() const {
489✔
21
   return TLS::Handshake_Type::CertificateRequest;
489✔
22
}
23

24
Certificate_Request_13::Certificate_Request_13(const std::vector<uint8_t>& buf, const Connection_Side side) {
68✔
25
   TLS_Data_Reader reader("Certificate_Request_13", buf);
68✔
26

27
   // RFC 8446 4.3.2
28
   //    A server which is authenticating with a certificate MAY optionally
29
   //    request a certificate from the client.
30
   if(side != Connection_Side::Server) {
68✔
31
      throw TLS_Exception(Alert::UnexpectedMessage, "Received a Certificate_Request message from a client");
×
32
   }
33

34
   m_context = reader.get_tls_length_value(1);
136✔
35
   m_extensions.deserialize(reader, side, type());
68✔
36

37
   // RFC 8446 4.3.2
38
   //    The "signature_algorithms" extension MUST be specified, and other
39
   //    extensions may optionally be included if defined for this message.
40
   //    Clients MUST ignore unrecognized extensions.
41

42
   if(!m_extensions.has<Signature_Algorithms>()) {
66✔
43
      throw TLS_Exception(Alert::MissingExtension,
1✔
44
                          "Certificate_Request message did not provide a signature_algorithms extension");
1✔
45
   }
46

47
   // RFC 8446 4.2.
48
   //    The table below indicates the messages where a given extension may
49
   //    appear [...].  If an implementation receives an extension which it
50
   //    recognizes and which is not specified for the message in which it
51
   //    appears, it MUST abort the handshake with an "illegal_parameter" alert.
52
   //
53
   // For Certificate Request said table states:
54
   //    "status_request", "signature_algorithms", "signed_certificate_timestamp",
55
   //     "certificate_authorities", "oid_filters", "signature_algorithms_cert",
56
   const std::set<Extension_Code> allowed_extensions = {
65✔
57
      Extension_Code::CertificateStatusRequest,
58
      Extension_Code::SignatureAlgorithms,
59
      // Extension_Code::SignedCertificateTimestamp,  // NYI
60
      Extension_Code::CertificateAuthorities,
61
      // Extension_Code::OidFilters,                   // NYI
62
      Extension_Code::CertSignatureAlgorithms,
63
   };
65✔
64

65
   if(m_extensions.contains_implemented_extensions_other_than(allowed_extensions)) {
65✔
66
      throw TLS_Exception(Alert::IllegalParameter, "Certificate Request contained an extension that is not allowed");
×
67
   }
68
}
71✔
69

70
Certificate_Request_13::Certificate_Request_13(const std::vector<X509_DN>& acceptable_CAs,
97✔
71
                                               const Policy& policy,
72
                                               Callbacks& callbacks) {
97✔
73
   // RFC 8446 4.3.2
74
   //    The certificate_request_context [here: m_context] MUST be unique within
75
   //    the scope of this connection (thus preventing replay of client
76
   //    CertificateVerify messages).  This field SHALL be zero length unless
77
   //    used for the post-handshake authentication exchanges described in
78
   //    Section 4.6.2.
79
   //
80
   // TODO: Post-Handshake auth must fill m_context in an unpredictable way
81

82
   // RFC 8446 4.3.2
83
   //    [Supported signature algorithms are] expressed by sending the
84
   //    "signature_algorithms" and optionally "signature_algorithms_cert"
85
   //    extensions. [A list of certificate authorities which the server would
86
   //    accept] is expressed by sending the "certificate_authorities" extension.
87
   //
88
   //    The "signature_algorithms" extension MUST be specified, and other
89
   //    extensions may optionally be included if defined for this message.
90
   m_extensions.add(std::make_unique<Signature_Algorithms>(policy.acceptable_signature_schemes()));
194✔
91
   if(auto cert_signing_prefs = policy.acceptable_certificate_signature_schemes()) {
97✔
92
      // RFC 8446 4.2.3
93
      //    Implementations which have the same policy in both cases MAY omit
94
      //    the "signature_algorithms_cert" extension.
95
      m_extensions.add(std::make_unique<Signature_Algorithms_Cert>(std::move(cert_signing_prefs.value())));
×
96
   }
×
97

98
   if(!acceptable_CAs.empty()) {
97✔
99
      m_extensions.add(std::make_unique<Certificate_Authorities>(acceptable_CAs));
164✔
100
   }
101

102
   // TODO: Support cert_status_request for OCSP stapling
103

104
   callbacks.tls_modify_extensions(m_extensions, Connection_Side::Server, type());
97✔
105
}
97✔
106

107
std::optional<Certificate_Request_13> Certificate_Request_13::maybe_create(const Client_Hello_13& client_hello,
272✔
108
                                                                           Credentials_Manager& cred_mgr,
109
                                                                           Callbacks& callbacks,
110
                                                                           const Policy& policy) {
111
   const auto trusted_CAs = cred_mgr.trusted_certificate_authorities("tls-server", client_hello.sni_hostname());
544✔
112

113
   std::vector<X509_DN> client_auth_CAs;
272✔
114
   for(auto* const store : trusted_CAs) {
519✔
115
      const auto subjects = store->all_subjects();
247✔
116
      client_auth_CAs.insert(client_auth_CAs.end(), subjects.begin(), subjects.end());
247✔
117
   }
247✔
118

119
   if(client_auth_CAs.empty() && !policy.request_client_certificate_authentication()) {
272✔
120
      return std::nullopt;
175✔
121
   }
122

123
   return Certificate_Request_13(client_auth_CAs, policy, callbacks);
97✔
124
}
519✔
125

126
std::vector<X509_DN> Certificate_Request_13::acceptable_CAs() const {
55✔
127
   if(m_extensions.has<Certificate_Authorities>()) {
55✔
128
      return m_extensions.get<Certificate_Authorities>()->distinguished_names();
3✔
129
   }
130
   return {};
52✔
131
}
132

133
const std::vector<Signature_Scheme>& Certificate_Request_13::signature_schemes() const {
216✔
134
   // RFC 8446 4.3.2
135
   //    The "signature_algorithms" extension MUST be specified
136
   BOTAN_ASSERT_NOMSG(m_extensions.has<Signature_Algorithms>());
216✔
137

138
   return m_extensions.get<Signature_Algorithms>()->supported_schemes();
216✔
139
}
140

141
const std::vector<Signature_Scheme>& Certificate_Request_13::certificate_signature_schemes() const {
55✔
142
   // RFC 8446 4.2.3
143
   //   If no "signature_algorithms_cert" extension is present, then the
144
   //   "signature_algorithms" extension also applies to signatures appearing
145
   //   in certificates.
146
   if(auto* sig_schemes_cert = m_extensions.get<Signature_Algorithms_Cert>()) {
55✔
147
      return sig_schemes_cert->supported_schemes();
×
148
   } else {
149
      return signature_schemes();
55✔
150
   }
151
}
152

153
std::vector<uint8_t> Certificate_Request_13::serialize() const {
101✔
154
   std::vector<uint8_t> buf;
101✔
155
   append_tls_length_value(buf, m_context, 1);
101✔
156
   buf += m_extensions.serialize(Connection_Side::Server);
101✔
157
   return buf;
101✔
158
}
×
159

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