Botan 3.6.1
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)
inline

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 19 of file tls_handshake_layer_13.cpp.

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

Referenced by Botan::TLS::Channel_Impl_13::from_peer().

◆ 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(); }

Referenced by Botan::TLS::Channel_Impl_13::from_peer(), and Botan::TLS::Channel_Impl_13::handle().

◆ 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 119 of file tls_handshake_layer_13.cpp.

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

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

Referenced by Botan::TLS::Channel_Impl_13::from_peer().

◆ 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 133 of file tls_handshake_layer_13.cpp.

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

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

Referenced by Botan::TLS::Channel_Impl_13::from_peer().

◆ prepare_message()

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

Marshalls 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 172 of file tls_handshake_layer_13.cpp.

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

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

Referenced by Botan::TLS::Channel_Impl_13::AggregatedHandshakeMessages::add().

◆ prepare_post_handshake_message()

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

Marshalls 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 179 of file tls_handshake_layer_13.cpp.

179 {
180 return marshall_message(message);
181}

Referenced by Botan::TLS::Channel_Impl_13::AggregatedPostHandshakeMessages::add().

◆ 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; }

Referenced by Botan::TLS::Channel_Impl_13::set_selected_certificate_type().


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