Botan  2.11.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::TLS::Certificate Class Referencefinal

#include <tls_messages.h>

Inheritance diagram for Botan::TLS::Certificate:
Botan::TLS::Handshake_Message

Public Member Functions

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

Detailed Description

Certificate Message

Definition at line 370 of file tls_messages.h.

Constructor & Destructor Documentation

◆ Certificate() [1/2]

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

Create a new Certificate message

Definition at line 23 of file msg_certificate.cpp.

References hash, and Botan::TLS::Handshake_IO::send().

25  :
26  m_certs(cert_list)
27  {
28  hash.update(io.send(*this));
29  }
MechanismType hash

◆ Certificate() [2/2]

Botan::TLS::Certificate::Certificate ( const std::vector< uint8_t > &  buf,
const Policy policy 
)
explicit

Deserialize a Certificate message

Definition at line 34 of file msg_certificate.cpp.

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

35  {
36  if(buf.size() < 3)
37  throw Decoding_Error("Certificate: Message malformed");
38 
39  const size_t total_size = make_uint32(0, buf[0], buf[1], buf[2]);
40 
41  if(total_size != buf.size() - 3)
42  throw Decoding_Error("Certificate: Message malformed");
43 
44  const size_t max_size = policy.maximum_certificate_chain_size();
45  if(max_size > 0 && total_size > max_size)
46  throw Decoding_Error("Certificate chain exceeds policy specified maximum size");
47 
48  const uint8_t* certs = buf.data() + 3;
49 
50  while(size_t remaining_bytes = buf.data() + buf.size() - certs)
51  {
52  if(remaining_bytes < 3)
53  throw Decoding_Error("Certificate: Message malformed");
54 
55  const size_t cert_size = make_uint32(0, certs[0], certs[1], certs[2]);
56 
57  if(remaining_bytes < (3 + cert_size))
58  throw Decoding_Error("Certificate: Message malformed");
59 
60  DataSource_Memory cert_buf(&certs[3], cert_size);
61  m_certs.push_back(X509_Certificate(cert_buf));
62 
63  certs += cert_size + 3;
64  }
65  }
constexpr uint32_t make_uint32(uint8_t i0, uint8_t i1, uint8_t i2, uint8_t i3)
Definition: loadstor.h:65

Member Function Documentation

◆ cert_chain()

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

Definition at line 374 of file tls_messages.h.

374 { return m_certs; }

◆ count()

size_t Botan::TLS::Certificate::count ( ) const
inline

Definition at line 376 of file tls_messages.h.

376 { return m_certs.size(); }

◆ empty()

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

Definition at line 377 of file tls_messages.h.

377 { return m_certs.empty(); }

◆ type()

Handshake_Type Botan::TLS::Certificate::type ( ) const
inlineoverridevirtual
Returns
the message type

Implements Botan::TLS::Handshake_Message.

Definition at line 373 of file tls_messages.h.

References Botan::TLS::CERTIFICATE.

◆ 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.

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

20  {
22  }
virtual Handshake_Type type() const =0
const char * handshake_type_to_string(Handshake_Type type)

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