Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Flight Class Reference

#include <tls_flight_13.h>

Inheritance diagram for Botan::TLS::Flight:
Botan::TLS::PostHandshakeFlight

Classes

struct  Dummy_ChangeCipherSpec
struct  Message_Info

Public Types

using Message = std::variant<Dummy_ChangeCipherSpec, Message_Info>
enum class  PostHandshake : bool { No = false , Yes = true }

Public Member Functions

Flight & add (Handshake_Message_13_Ref msg) &
Flight add (Handshake_Message_13_Ref msg) &&
Flight & add_dummy_change_cipher_spec () &
Flight add_dummy_change_cipher_spec () &&
std::vector< Message > commit ()
 Flight (const Flight &other)=delete
 Flight (Transcript_Hash_State &transcript_hash, Callbacks &callbacks)
Flight & operator= (const Flight &other)=delete
Flight & operator= (Flight &&other)=delete
 ~Flight ()=default

Protected Member Functions

void append (const Handshake_Message &message, PostHandshake post_handshake)
void append_ccs ()
 Flight (Callbacks &callbacks)
 Flight (Flight &&other)=default

Detailed Description

Helper class to coalesce handshake messages into a TLS flight. The class keeps track of the serialized messages and updates the transcript hash accordingly.

Once the flight is constructed, using code must commit() it and pass on the prepared list of serialized messages for sending. After commit() the flight object is invalid and must not be used anymore.

Note that this class takes references to transcript hash and callbacks objects. The caller is responsible for ensuring that these objects remain valid for the lifetime of the Flight object. The flight object is meant to be used in a single stack frame and not stored for later use.

Definition at line 38 of file tls_flight_13.h.

Member Typedef Documentation

◆ Message

Definition at line 48 of file tls_flight_13.h.

Member Enumeration Documentation

◆ PostHandshake

enum class Botan::TLS::Flight::PostHandshake : bool
strong
Enumerator
No 
Yes 

Definition at line 50 of file tls_flight_13.h.

50: bool { No = false, Yes = true };

Constructor & Destructor Documentation

◆ Flight() [1/4]

Botan::TLS::Flight::Flight ( Callbacks & callbacks)
inlineexplicitprotected

Definition at line 53 of file tls_flight_13.h.

53: m_callbacks(callbacks) { m_messages.emplace(); }

Referenced by add(), add(), add_dummy_change_cipher_spec(), add_dummy_change_cipher_spec(), Flight(), Flight(), operator=(), operator=(), and Botan::TLS::PostHandshakeFlight::PostHandshakeFlight().

◆ Flight() [2/4]

Botan::TLS::Flight::Flight ( Flight && other)
protecteddefault

References Flight().

◆ Flight() [3/4]

Botan::TLS::Flight::Flight ( Transcript_Hash_State & transcript_hash,
Callbacks & callbacks )
inline

Definition at line 58 of file tls_flight_13.h.

58 :
59 m_transcript_hash(transcript_hash), m_callbacks(callbacks) {
60 m_messages.emplace();
61 }

◆ Flight() [4/4]

Botan::TLS::Flight::Flight ( const Flight & other)
delete

References Flight().

◆ ~Flight()

Botan::TLS::Flight::~Flight ( )
default

Member Function Documentation

◆ add() [1/2]

Flight & Botan::TLS::Flight::add ( Handshake_Message_13_Ref msg) &
inline

Add a msg to this flight, updating the transcript hash associated with this flight and letting the user inspect the message first via the callbacks.

TODO(C++23): deducing-this

Parameters
msgThe handshake message to add to the flight
Exceptions
Invalid_Stateif the flight was already committed

Definition at line 78 of file tls_flight_13.h.

78 {
79 std::visit([&](const auto m) { append(m.get(), PostHandshake::No); }, msg);
80 return *this;
81 }
void append(const Handshake_Message &message, PostHandshake post_handshake)

References append(), Flight(), and No.

Referenced by Botan::TLS::Client_Impl_13::create().

◆ add() [2/2]

Flight Botan::TLS::Flight::add ( Handshake_Message_13_Ref msg) &&
inline

Add a msg to this flight, updating the transcript hash associated with this flight and letting the user inspect the message first via the callbacks.

TODO(C++23): deducing-this

Parameters
msgThe handshake message to add to the flight
Exceptions
Invalid_Stateif the flight was already committed

Definition at line 93 of file tls_flight_13.h.

93 {
94 std::visit([&](const auto m) { append(m.get(), PostHandshake::No); }, msg);
95 return std::move(*this);
96 }

References append(), Flight(), and No.

◆ add_dummy_change_cipher_spec() [1/2]

Flight & Botan::TLS::Flight::add_dummy_change_cipher_spec ( ) &
inline

Add a dummy ChangeCipherSpec message to the flight when following the compatibility mode for TLS 1.3. See RFC 9846 E.4 for details.

TODO(C++23): deducing-this

Exceptions
Invalid_Stateif the flight was already committed

Definition at line 106 of file tls_flight_13.h.

106 {
107 append_ccs();
108 return *this;
109 }

References append_ccs(), and Flight().

◆ add_dummy_change_cipher_spec() [2/2]

Flight Botan::TLS::Flight::add_dummy_change_cipher_spec ( ) &&
inline

Add a dummy ChangeCipherSpec message to the flight when following the compatibility mode for TLS 1.3. See RFC 9846 E.4 for details.

TODO(C++23): deducing-this

Exceptions
Invalid_Stateif the flight was already committed

Definition at line 119 of file tls_flight_13.h.

119 {
120 append_ccs();
121 return std::move(*this);
122 }

References append_ccs(), and Flight().

◆ append()

void Botan::TLS::Flight::append ( const Handshake_Message & message,
PostHandshake post_handshake )
protected

Definition at line 42 of file tls_flight_13.cpp.

42 {
43 BOTAN_STATE_CHECK(m_messages.has_value());
44
45 m_callbacks.tls_inspect_handshake_msg(message);
46
47 auto msg_info = make_message_info(message, post_handshake);
48 if(post_handshake == PostHandshake::No) {
49 BOTAN_ASSERT_NOMSG(m_transcript_hash.has_value());
50 m_transcript_hash->get().update(msg_info.header, msg_info.serialized);
51 }
52 m_messages->push_back(std::move(msg_info));
53}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_ASSERT_NOMSG, BOTAN_STATE_CHECK, and No.

Referenced by add(), add(), Botan::TLS::PostHandshakeFlight::add(), and Botan::TLS::PostHandshakeFlight::add().

◆ append_ccs()

void Botan::TLS::Flight::append_ccs ( )
protected

Definition at line 55 of file tls_flight_13.cpp.

55 {
56 BOTAN_STATE_CHECK(m_messages.has_value());
57 m_messages->push_back(Dummy_ChangeCipherSpec{});
58}

References BOTAN_STATE_CHECK.

Referenced by add_dummy_change_cipher_spec(), and add_dummy_change_cipher_spec().

◆ commit()

std::vector< Flight::Message > Botan::TLS::Flight::commit ( )

Extract the messages from the flight for sending. This invalidates the flight object and it cannot be used anymore.

Exceptions
Invalid_Stateif the flight was already committed or if it is empty

Definition at line 35 of file tls_flight_13.cpp.

35 {
36 BOTAN_STATE_CHECK(m_messages.has_value());
37 BOTAN_STATE_CHECK(!m_messages->empty());
38
39 return std::exchange(m_messages, {}).value();
40}

References BOTAN_STATE_CHECK.

◆ operator=() [1/2]

Flight & Botan::TLS::Flight::operator= ( const Flight & other)
delete

References Flight().

◆ operator=() [2/2]

Flight & Botan::TLS::Flight::operator= ( Flight && other)
delete

References Flight().


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