Botan 3.11.0
Crypto and TLS for C&
Botan::TLS::Handshake_Layer Class Reference

#include <tls_handshake_layer_13.h>

Public Member Functions

void copy_data (std::span< const uint8_t > data_from_peer)
 Handshake_Layer (Connection_Side whoami)
bool has_pending_data () const
std::optional< Handshake_Message_13next_message (const Policy &policy, Transcript_Hash_State &transcript_hash)
std::optional< Post_Handshake_Message_13next_post_handshake_message (const Policy &policy)
void set_selected_certificate_type (Certificate_Type cert_type)

Static Public Member Functions

static std::vector< uint8_t > prepare_message (Handshake_Message_13_Ref message, Transcript_Hash_State &transcript_hash)
static std::vector< uint8_t > prepare_post_handshake_message (const Post_Handshake_Message_13 &message)

Detailed Description

Implementation of the TLS 1.3 handshake protocol layer

This component transforms payload bytes received in TLS records from the peer into parsed handshake messages and vice versa.

Definition at line 28 of file tls_handshake_layer_13.h.

Constructor & Destructor Documentation

◆ Handshake_Layer()

Botan::TLS::Handshake_Layer::Handshake_Layer ( Connection_Side whoami)
inlineexplicit

Definition at line 30 of file tls_handshake_layer_13.h.

30 :
32 // RFC 8446 4.4.2
33 // If the corresponding certificate type extension
34 // ("server_certificate_type" or "client_certificate_type") was not
35 // negotiated in EncryptedExtensions, or the X.509 certificate type
36 // was negotiated, then each CertificateEntry contains a DER-encoded
37 // X.509 certificate.
38 //
39 // We need the certificate_type info to parse Certificate messages.
40 ,
41 m_certificate_type(Certificate_Type::X509) {}

Member Function Documentation

◆ copy_data()

void Botan::TLS::Handshake_Layer::copy_data ( std::span< const uint8_t > data_from_peer)

Reads data that was received in handshake records and stores it internally for further processing during the invocation of next_message().

Parameters
data_from_peerThe data to be parsed.

Definition at line 20 of file tls_handshake_layer_13.cpp.

20 {
21 m_read_buffer.insert(m_read_buffer.end(), data_from_peer.begin(), data_from_peer.end());
22}

◆ has_pending_data()

bool Botan::TLS::Handshake_Layer::has_pending_data ( ) const
inline

Check if the Handshake_Layer has stored a partial message in its internal buffer. This can happen if a handshake message spans multiple records.

Definition at line 95 of file tls_handshake_layer_13.h.

95{ return !m_read_buffer.empty(); }

◆ next_message()

std::optional< Handshake_Message_13 > Botan::TLS::Handshake_Layer::next_message ( const Policy & policy,
Transcript_Hash_State & transcript_hash )

Parses one handshake message off the internal buffer that is being filled using copy_data.

Parameters
policythe TLS policy
transcript_hashthe transcript hash state to be updated
Returns
the parsed handshake message, or nullopt if more data is needed to complete the message

Definition at line 120 of file tls_handshake_layer_13.cpp.

121 {
122 TLS::TLS_Data_Reader reader("handshake message", m_read_buffer);
123
124 auto msg = parse_message<Handshake_Message_13>(reader, policy, m_peer, m_certificate_type);
125 if(msg.has_value()) {
126 BOTAN_ASSERT_NOMSG(m_read_buffer.size() >= reader.read_so_far());
127 transcript_hash.update(std::span{m_read_buffer.data(), reader.read_so_far()});
128 m_read_buffer.erase(m_read_buffer.cbegin(), m_read_buffer.cbegin() + reader.read_so_far());
129 }
130
131 return msg;
132}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References BOTAN_ASSERT_NOMSG, Botan::TLS::TLS_Data_Reader::read_so_far(), and Botan::TLS::Transcript_Hash_State::update().

◆ next_post_handshake_message()

std::optional< Post_Handshake_Message_13 > Botan::TLS::Handshake_Layer::next_post_handshake_message ( const Policy & policy)

Parses one post-handshake message off the internal buffer that is being filled using copy_data.

Parameters
policythe TLS policy
Returns
the parsed post-handshake message, or nullopt if more data is needed to complete the message

Definition at line 134 of file tls_handshake_layer_13.cpp.

134 {
135 TLS::TLS_Data_Reader reader("post handshake message", m_read_buffer);
136
137 auto msg = parse_message<Post_Handshake_Message_13>(reader, policy, m_peer, m_certificate_type);
138 if(msg.has_value()) {
139 m_read_buffer.erase(m_read_buffer.cbegin(), m_read_buffer.cbegin() + reader.read_so_far());
140 }
141
142 return msg;
143}

References Botan::TLS::TLS_Data_Reader::read_so_far().

◆ prepare_message()

std::vector< uint8_t > Botan::TLS::Handshake_Layer::prepare_message ( Handshake_Message_13_Ref message,
Transcript_Hash_State & transcript_hash )
static

Marshals one handshake message for sending in an (encrypted) record and updates the provided transcript hash state accordingly.

Parameters
messagethe handshake message to be marshalled
transcript_hashthe transcript hash state to be updated
Returns
the marshalled handshake message

Definition at line 174 of file tls_handshake_layer_13.cpp.

175 {
176 auto msg = marshall_message(message);
177 transcript_hash.update(msg);
178 return msg;
179}

References Botan::TLS::Transcript_Hash_State::update().

◆ prepare_post_handshake_message()

std::vector< uint8_t > Botan::TLS::Handshake_Layer::prepare_post_handshake_message ( const Post_Handshake_Message_13 & message)
static

Marshals one post-handshake message for sending in an (encrypted) record.

Parameters
messagethe post handshake message to be marshalled
Returns
the marshalled post-handshake message

Definition at line 181 of file tls_handshake_layer_13.cpp.

181 {
182 return marshall_message(message);
183}

◆ set_selected_certificate_type()

void Botan::TLS::Handshake_Layer::set_selected_certificate_type ( Certificate_Type cert_type)
inline

Set the certificate_type used for parsing Certificate messages. This is determined via (client/server)_certificate_type extensions during the handshake.

RFC 7250 4.3 and 4.4 When the TLS server has specified RawPublicKey as the [client_certificate_type/server_certificate_type], authentication of the TLS [client/server] to the TLS [server/client] is supported only through authentication of the received client SubjectPublicKeyInfo via an out-of-band method.

If the peer sends a Certificate message containing an incompatible means of authentication, a 'decode_error' will be generated.

Definition at line 112 of file tls_handshake_layer_13.h.

112{ m_certificate_type = cert_type; }

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