Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Certificate_12 Class Referencefinal

#include <tls_messages_12.h>

Inheritance diagram for Botan::TLS::Certificate_12:
Botan::TLS::Handshake_Message

Public Member Functions

const std::vector< X509_Certificate > & cert_chain () const
 Certificate_12 (Handshake_IO &io, Handshake_Hash &hash, std::vector< X509_Certificate > certs)
 Certificate_12 (std::span< const uint8_t > buf, const Policy &policy)
size_t count () const
bool empty () const
std::vector< uint8_t > serialize () const override
Handshake_Type type () const override
std::string type_string () const
virtual Handshake_Type wire_type () const
 ~Certificate_12 () override

Detailed Description

Certificate Message of TLS 1.2

Definition at line 221 of file tls_messages_12.h.

Constructor & Destructor Documentation

◆ Certificate_12() [1/2]

Botan::TLS::Certificate_12::Certificate_12 ( Handshake_IO & io,
Handshake_Hash & hash,
std::vector< X509_Certificate > cert_list )

Create a new Certificate message

Definition at line 28 of file msg_certificate_12.cpp.

28 :
29 m_certs(std::move(cert_list)) {
30 hash.update(io.send(*this));
31}

References Botan::TLS::Handshake_IO::send(), and Botan::TLS::Handshake_Hash::update().

◆ Certificate_12() [2/2]

Botan::TLS::Certificate_12::Certificate_12 ( std::span< const uint8_t > buf,
const Policy & policy )

Deserialize a Certificate message

Definition at line 36 of file msg_certificate_12.cpp.

36 {
37 if(buf.size() < 3) {
38 throw Decoding_Error("Certificate: Message malformed");
39 }
40
41 const size_t total_size = make_uint32(0, buf[0], buf[1], buf[2]);
42
43 if(total_size != buf.size() - 3) {
44 throw Decoding_Error("Certificate: Message malformed");
45 }
46
47 const size_t max_size = policy.maximum_certificate_chain_size();
48 if(max_size > 0 && total_size > max_size) {
49 throw Decoding_Error("Certificate chain exceeds policy specified maximum size");
50 }
51
52 const uint8_t* certs = buf.data() + 3;
53
54 while(const size_t remaining_bytes = buf.data() + buf.size() - certs) {
55 if(remaining_bytes < 3) {
56 throw Decoding_Error("Certificate: Message malformed");
57 }
58
59 const size_t cert_size = make_uint32(0, certs[0], certs[1], certs[2]);
60
61 if(remaining_bytes < (3 + cert_size)) {
62 throw Decoding_Error("Certificate: Message malformed");
63 }
64
65 DataSource_Memory cert_buf(&certs[3], cert_size);
66 try {
67 m_certs.push_back(X509_Certificate(cert_buf));
68 } catch(Exception& e) {
69 // bad_certificate would make more sense but BoGo expects decoding_error
70 throw TLS_Exception(Alert::DecodeError, e.what());
71 }
72
73 certs += cert_size + 3;
74 }
75
76 /*
77 * TLS 1.0 through 1.2 all seem to require that the certificate be
78 * precisely a v3 certificate. In fact the strict wording would seem
79 * to require that every certificate in the chain be v3. But often
80 * the intermediates are outside of the control of the server.
81 * But, require that the leaf certificate be v3
82 */
83 if(!m_certs.empty() && m_certs[0].x509_version() != 3) {
84 throw TLS_Exception(Alert::BadCertificate, "The leaf certificate must be v3");
85 }
86}
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition loadstor.h:104

References Botan::make_uint32(), Botan::TLS::Policy::maximum_certificate_chain_size(), and Botan::Exception::what().

◆ ~Certificate_12()

Botan::TLS::Certificate_12::~Certificate_12 ( )
overridedefault

References serialize().

Member Function Documentation

◆ cert_chain()

const std::vector< X509_Certificate > & Botan::TLS::Certificate_12::cert_chain ( ) const
inline

Definition at line 225 of file tls_messages_12.h.

225{ return m_certs; }

◆ count()

size_t Botan::TLS::Certificate_12::count ( ) const

Definition at line 106 of file msg_certificate_12.cpp.

106 {
107 return m_certs.size();
108}

◆ empty()

bool Botan::TLS::Certificate_12::empty ( ) const
inline

Definition at line 229 of file tls_messages_12.h.

229{ return m_certs.empty(); }

◆ serialize()

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

Serialize a Certificate message

Implements Botan::TLS::Handshake_Message.

Definition at line 91 of file msg_certificate_12.cpp.

91 {
92 // RFC 5246 7.4.2
93 // opaque ASN.1Cert<1..2^24-1>;
94 // [...]
95 // ASN.1Cert certificate_list<0..2^24-1>;
96 std::vector<uint8_t> certs;
97 for(const auto& cert : m_certs) {
98 append_tls_length_value(certs, cert.BER_encode(), 3);
99 }
100
101 std::vector<uint8_t> buf;
102 append_tls_length_value(buf, certs, 3);
103 return buf;
104}
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:182

References Botan::TLS::append_tls_length_value().

Referenced by ~Certificate_12().

◆ type()

Handshake_Type Botan::TLS::Certificate_12::type ( ) const
inlineoverridevirtual

Return the TLS handshake type code

Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 223 of file tls_messages_12.h.

References Botan::TLS::Certificate.

◆ type_string()

std::string Botan::TLS::Handshake_Message::type_string ( ) const
inherited

Return a free-form string describing this message type

Returns
string representation of this message type

Definition at line 22 of file tls_handshake_state.cpp.

22 {
24}
virtual Handshake_Type type() const =0
const char * handshake_type_to_string(Handshake_Type type)
Definition tls_magic.cpp:15

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

◆ wire_type()

virtual Handshake_Type Botan::TLS::Handshake_Message::wire_type ( ) const
inlinevirtualinherited

Return the wire encoding of the message type code

Note
This is usually equal to type with the exception of a TLS 1.3 Helloy Retry Request.
Returns
the wire representation of the message's type

Reimplemented in Botan::TLS::Hello_Retry_Request.

Definition at line 47 of file tls_handshake_msg.h.

47{ return type(); }

References type().

Referenced by Botan::TLS::Stream_Handshake_IO::send(), and Botan::TLS::Handshake_Layer::update_transcript_for_psk_binder_calc().


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