Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | List of all members
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 593 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 59 of file msg_cert_req.cpp.

62 :
63 m_names(ca_certs),
64 m_cert_key_types({ "RSA", "ECDSA", "DSA" })
65 {
66 m_schemes = policy.acceptable_signature_schemes();
67 hash.update(io.send(*this));
68 }
MechanismType hash

◆ 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 73 of file msg_cert_req.cpp.

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

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 123 of file msg_cert_req.cpp.

124 {
125 return m_names;
126 }

◆ acceptable_cert_types()

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

Definition at line 118 of file msg_cert_req.cpp.

119 {
120 return m_cert_key_types;
121 }

◆ 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 136 of file msg_cert_req.cpp.

137 {
138 std::vector<uint8_t> buf;
139
140 std::vector<uint8_t> cert_types;
141
142 for(const auto& cert_key_type : m_cert_key_types)
143 cert_types.push_back(cert_type_name_to_code(cert_key_type));
144
145 append_tls_length_value(buf, cert_types, 1);
146
147 if(!m_schemes.empty())
148 buf += Signature_Algorithms(m_schemes).serialize(Connection_Side::SERVER);
149
150 std::vector<uint8_t> encoded_names;
151
152 for(const auto& name : m_names)
153 {
154 DER_Encoder encoder;
155 encoder.encode(name);
156
157 append_tls_length_value(encoded_names, encoder.get_contents(), 2);
158 }
159
160 append_tls_length_value(buf, encoded_names, 2);
161
162 return buf;
163 }
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:212

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 128 of file msg_cert_req.cpp.

129 {
130 return m_schemes;
131 }

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 20 of file msg_cert_req.cpp.

21 {
23 }
@ CERTIFICATE_REQUEST
Definition: tls_magic.h:75

References Botan::TLS::CERTIFICATE_REQUEST.

◆ type_string()

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

Definition at line 18 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

Definition at line 42 of file tls_handshake_msg.h.

43 {
44 // Usually equal to the Handshake_Type enum value,
45 // with the exception of TLS 1.3 Hello Retry Request.
46 return type();
47 }

References type.

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


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