Botan 3.12.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 22 of file tls_handshake_layer_13.cpp.

22 {
23 // Compact consumed data before appending new data
24 BOTAN_ASSERT_NOMSG(m_read_offset <= m_read_buffer.size());
25 if(m_read_offset > 0) {
26 m_read_buffer.erase(m_read_buffer.begin(), m_read_buffer.begin() + m_read_offset);
27 m_read_offset = 0;
28 }
29
30 m_read_buffer.insert(m_read_buffer.end(), data_from_peer.begin(), data_from_peer.end());
31}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References BOTAN_ASSERT_NOMSG.

◆ 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_offset < m_read_buffer.size(); }

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

141 {
142 BOTAN_ASSERT_NOMSG(m_read_offset <= m_read_buffer.size());
143 auto pending = std::span<const uint8_t>{m_read_buffer}.subspan(m_read_offset);
144 TLS::TLS_Data_Reader reader("handshake message", pending);
145
146 auto msg = parse_message<Handshake_Message_13>(reader, policy, m_peer, m_certificate_type);
147 if(msg.has_value()) {
148 transcript_hash.update(pending.first(reader.read_so_far()));
149 m_read_offset += reader.read_so_far();
150 BOTAN_ASSERT_NOMSG(m_read_offset <= m_read_buffer.size());
151
152 if(m_read_offset == m_read_buffer.size()) {
153 m_read_buffer.clear();
154 m_read_offset = 0;
155 }
156 }
157
158 return msg;
159}

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

161 {
162 BOTAN_ASSERT_NOMSG(m_read_offset <= m_read_buffer.size());
163 auto pending = std::span<const uint8_t>{m_read_buffer}.subspan(m_read_offset);
164 TLS::TLS_Data_Reader reader("post handshake message", pending);
165
166 auto msg = parse_message<Post_Handshake_Message_13>(reader, policy, m_peer, m_certificate_type);
167 if(msg.has_value()) {
168 m_read_offset += reader.read_so_far();
169 BOTAN_ASSERT_NOMSG(m_read_offset <= m_read_buffer.size());
170
171 if(m_read_offset == m_read_buffer.size()) {
172 m_read_buffer.clear();
173 m_read_offset = 0;
174 }
175 }
176
177 return msg;
178}

References BOTAN_ASSERT_NOMSG, and 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 209 of file tls_handshake_layer_13.cpp.

210 {
211 auto msg = marshall_message(message);
212 transcript_hash.update(msg);
213 return msg;
214}

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

216 {
217 return marshall_message(message);
218}

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