10#include <botan/tls_messages_12.h>
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>
32std::string cert_type_code_to_name(uint8_t code) {
43uint8_t cert_type_name_to_code(std::string_view
name) {
51 throw Invalid_Argument(
fmt(
"Unknown/unhandled TLS cert type {}",
name));
62 std::vector<X509_DN> ca_certs) :
63 m_names(std::move(ca_certs)), m_cert_key_types({
"RSA",
"ECDSA"}) {
64 for(
const auto scheme : policy.acceptable_signature_schemes()) {
65 if(scheme.is_compatible_with(Protocol_Version::TLS_V12)) {
66 m_schemes.push_back(scheme);
70 if(m_schemes.empty()) {
71 throw Internal_Error(
"Policy returned no acceptable signature schemes for CertificateRequest");
73 hash.update(io.send(*
this));
88 for(
const auto cert_type_code : cert_type_codes) {
89 const std::string cert_type_name = cert_type_code_to_name(cert_type_code);
91 if(cert_type_name.empty()) {
95 m_cert_key_types.emplace_back(cert_type_name);
98 const std::vector<uint8_t> algs = reader.
get_range_vector<uint8_t>(2, 2, 65534);
100 if(algs.size() % 2 != 0) {
101 throw Decoding_Error(
"Bad length for signature IDs in certificate request");
104 for(
size_t i = 0; i != algs.size(); i += 2) {
105 m_schemes.emplace_back(
make_uint16(algs[i], algs[i + 1]));
111 throw Decoding_Error(
"Inconsistent length in certificate request");
116 std::vector<uint8_t> name_bits = reader.
get_range_vector<uint8_t>(2, 1, 65535);
120 decoder.decode(
name).verify_end();
121 m_names.emplace_back(
name);
126 return m_cert_key_types;
141 std::vector<uint8_t> buf;
143 std::vector<uint8_t> cert_types;
145 cert_types.reserve(m_cert_key_types.size());
146 for(
const auto& cert_key_type : m_cert_key_types) {
147 cert_types.push_back(cert_type_name_to_code(cert_key_type));
155 std::vector<uint8_t> encoded_names;
157 for(
const auto&
name : m_names) {
secure_vector< uint8_t > get_contents()
DER_Encoder & encode(bool b)
~Certificate_Request_12() override
Certificate_Request_12(Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, std::vector< X509_DN > allowed_cas)
const std::vector< std::string > & acceptable_cert_types() const
const std::vector< Signature_Scheme > & signature_schemes() const
std::vector< uint8_t > serialize() const override
const std::vector< X509_DN > & acceptable_CAs() const
Handshake_Type type() const override
std::vector< uint8_t > serialize(Connection_Side whoami) const override
bool has_remaining() const
size_t remaining_bytes() const
std::vector< T > get_range_vector(size_t len_bytes, size_t min_elems, size_t max_elems)
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
std::string fmt(std::string_view format, const T &... args)
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)