Botan 3.6.1
Crypto and TLS for C&
Botan::TLS::Certificate_Request_12 Class Referencefinal

#include <tls_messages.h>

Inheritance diagram for Botan::TLS::Certificate_Request_12:
Botan::TLS::Handshake_Message

Public Member Functions

const std::vector< X509_DN > & acceptable_CAs () const
 
const std::vector< std::string > & acceptable_cert_types () const
 
 Certificate_Request_12 (const std::vector< uint8_t > &buf)
 
 Certificate_Request_12 (Handshake_IO &io, Handshake_Hash &hash, const Policy &policy, const std::vector< X509_DN > &allowed_cas)
 
std::vector< uint8_t > serialize () const override
 
const std::vector< Signature_Scheme > & signature_schemes () const
 
Handshake_Type type () const override
 
std::string type_string () const
 
virtual Handshake_Type wire_type () const
 

Detailed Description

Certificate Request Message (TLS 1.2)

Definition at line 698 of file tls_messages.h.

Constructor & Destructor Documentation

◆ Certificate_Request_12() [1/2]

Botan::TLS::Certificate_Request_12::Certificate_Request_12 ( Handshake_IO & io,
Handshake_Hash & hash,
const Policy & policy,
const std::vector< X509_DN > & ca_certs )

Create a new Certificate Request message

Definition at line 54 of file msg_cert_req.cpp.

57 :
58 m_names(ca_certs), m_cert_key_types({"RSA", "ECDSA"}) {
59 m_schemes = policy.acceptable_signature_schemes();
60 hash.update(io.send(*this));
61}

◆ Certificate_Request_12() [2/2]

Botan::TLS::Certificate_Request_12::Certificate_Request_12 ( const std::vector< uint8_t > & buf)
explicit

Deserialize a Certificate Request message

Definition at line 66 of file msg_cert_req.cpp.

66 {
67 if(buf.size() < 4) {
68 throw Decoding_Error("Certificate_Req: Bad certificate request");
69 }
70
71 TLS_Data_Reader reader("CertificateRequest", buf);
72
73 const auto cert_type_codes = reader.get_range_vector<uint8_t>(1, 1, 255);
74
75 for(const auto cert_type_code : cert_type_codes) {
76 const std::string cert_type_name = cert_type_code_to_name(cert_type_code);
77
78 if(cert_type_name.empty()) { // something we don't know
79 continue;
80 }
81
82 m_cert_key_types.emplace_back(cert_type_name);
83 }
84
85 const std::vector<uint8_t> algs = reader.get_range_vector<uint8_t>(2, 2, 65534);
86
87 if(algs.size() % 2 != 0) {
88 throw Decoding_Error("Bad length for signature IDs in certificate request");
89 }
90
91 for(size_t i = 0; i != algs.size(); i += 2) {
92 m_schemes.emplace_back(make_uint16(algs[i], algs[i + 1]));
93 }
94
95 const uint16_t purported_size = reader.get_uint16_t();
96
97 if(reader.remaining_bytes() != purported_size) {
98 throw Decoding_Error("Inconsistent length in certificate request");
99 }
100
101 while(reader.has_remaining()) {
102 std::vector<uint8_t> name_bits = reader.get_range_vector<uint8_t>(2, 0, 65535);
103
104 BER_Decoder decoder(name_bits.data(), name_bits.size());
105 X509_DN name;
106 decoder.decode(name);
107 m_names.emplace_back(name);
108 }
109}
std::string name
constexpr uint16_t make_uint16(uint8_t i0, uint8_t i1)
Definition loadstor.h:88

References Botan::TLS::TLS_Data_Reader::get_range_vector(), Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::TLS_Data_Reader::has_remaining(), Botan::make_uint16(), name, and Botan::TLS::TLS_Data_Reader::remaining_bytes().

Member Function Documentation

◆ acceptable_CAs()

const std::vector< X509_DN > & Botan::TLS::Certificate_Request_12::acceptable_CAs ( ) const

Definition at line 115 of file msg_cert_req.cpp.

115 {
116 return m_names;
117}

◆ acceptable_cert_types()

const std::vector< std::string > & Botan::TLS::Certificate_Request_12::acceptable_cert_types ( ) const

Definition at line 111 of file msg_cert_req.cpp.

111 {
112 return m_cert_key_types;
113}

◆ serialize()

std::vector< uint8_t > Botan::TLS::Certificate_Request_12::serialize ( ) const
overridevirtual

Serialize a Certificate Request message

Implements Botan::TLS::Handshake_Message.

Definition at line 126 of file msg_cert_req.cpp.

126 {
127 std::vector<uint8_t> buf;
128
129 std::vector<uint8_t> cert_types;
130
131 cert_types.reserve(m_cert_key_types.size());
132 for(const auto& cert_key_type : m_cert_key_types) {
133 cert_types.push_back(cert_type_name_to_code(cert_key_type));
134 }
135
136 append_tls_length_value(buf, cert_types, 1);
137
138 if(!m_schemes.empty()) {
139 buf += Signature_Algorithms(m_schemes).serialize(Connection_Side::Server);
140 }
141
142 std::vector<uint8_t> encoded_names;
143
144 for(const auto& name : m_names) {
145 DER_Encoder encoder;
146 encoder.encode(name);
147
148 append_tls_length_value(encoded_names, encoder.get_contents(), 2);
149 }
150
151 append_tls_length_value(buf, encoded_names, 2);
152
153 return buf;
154}
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition tls_reader.h:180

References Botan::TLS::append_tls_length_value(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::get_contents(), name, Botan::TLS::Signature_Algorithms::serialize(), and Botan::TLS::Server.

◆ signature_schemes()

const std::vector< Signature_Scheme > & Botan::TLS::Certificate_Request_12::signature_schemes ( ) const

Definition at line 119 of file msg_cert_req.cpp.

119 {
120 return m_schemes;
121}

Referenced by Botan::TLS::Handshake_State::choose_sig_format(), and Botan::TLS::Handshake_State::parse_sig_format().

◆ type()

Handshake_Type Botan::TLS::Certificate_Request_12::type ( ) const
overridevirtual
Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 21 of file msg_cert_req.cpp.

References Botan::TLS::CertificateRequest.

◆ type_string()

std::string Botan::TLS::Handshake_Message::type_string ( ) const
inherited
Returns
string representation of this message type

Definition at line 19 of file tls_handshake_state.cpp.

19 {
21}
virtual Handshake_Type type() const =0
const char * handshake_type_to_string(Handshake_Type type)

References Botan::TLS::handshake_type_to_string(), and Botan::TLS::Handshake_Message::type().

◆ wire_type()

virtual Handshake_Type Botan::TLS::Handshake_Message::wire_type ( ) const
inlinevirtualinherited
Returns
the wire representation of the message's type

Reimplemented in Botan::TLS::Hello_Retry_Request.

Definition at line 39 of file tls_handshake_msg.h.

39 {
40 // Usually equal to the Handshake_Type enum value,
41 // with the exception of TLS 1.3 Hello Retry Request.
42 return type();
43 }

Referenced by Botan::TLS::Stream_Handshake_IO::send().


The documentation for this class was generated from the following files: