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

#include <tls_server_impl_13.h>

Inheritance diagram for Botan::TLS::Server_Impl_13:
Botan::TLS::Channel_Impl_13 Botan::TLS::Channel_Impl Botan::TLS::Secret_Logger

Public Member Functions

std::string application_protocol () const override
void close ()
bool expects_downgrade () const
std::optional< std::string > external_psk_identity () const override
std::unique_ptr< Downgrade_Informationextract_downgrade_info ()
size_t from_peer (std::span< const uint8_t > data) override
bool is_active () const override
bool is_closed () const override
bool is_closed_for_reading () const override
bool is_closed_for_writing () const override
bool is_downgrading () const
bool is_handshake_complete () const override
SymmetricKey key_material_export (std::string_view label, std::string_view context, size_t length) const override
bool new_session_ticket_supported () const override
std::vector< X509_Certificatepeer_cert_chain () const override
std::shared_ptr< const Public_Keypeer_raw_public_key () const override
void renegotiate (bool) override
bool secure_renegotiation_supported () const override
void send_alert (const Alert &alert) override
void send_fatal_alert (Alert::Type type)
size_t send_new_session_tickets (size_t tickets) override
void send_warning_alert (Alert::Type type)
 Server_Impl_13 (const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &credentials_manager, const std::shared_ptr< const Policy > &policy, const std::shared_ptr< RandomNumberGenerator > &rng)
bool timeout_check () override
void to_peer (std::span< const uint8_t > data) override
void update_traffic_keys (bool request_peer_update=false) override

Protected Member Functions

AggregatedHandshakeMessages aggregate_handshake_messages ()
AggregatedPostHandshakeMessages aggregate_post_handshake_messages ()
Callbackscallbacks () const
Credentials_Managercredentials_manager ()
void expect_downgrade (const Server_Information &server_info, const std::vector< std::string > &next_protocols)
void opportunistically_update_traffic_keys ()
const Policypolicy () const
virtual bool prepend_ccs ()
void preserve_client_hello (std::span< const uint8_t > msg)
void preserve_peer_transcript (std::span< const uint8_t > input)
void request_downgrade ()
void request_downgrade_for_resumption (Session_with_Handle session)
RandomNumberGeneratorrng ()
void send_dummy_change_cipher_spec ()
template<typename... MsgTs>
std::vector< uint8_t > send_handshake_message (const std::variant< MsgTs... > &message)
template<typename MsgT>
std::vector< uint8_t > send_handshake_message (std::reference_wrapper< MsgT > message)
std::vector< uint8_t > send_post_handshake_message (Post_Handshake_Message_13 message)
Session_Managersession_manager ()
void set_io_buffer_size (size_t io_buf_sz)
void set_record_size_limits (uint16_t outgoing_limit, uint16_t incoming_limit)
void set_selected_certificate_type (Certificate_Type cert_type)

Protected Attributes

std::unique_ptr< Cipher_Statem_cipher_state
std::unique_ptr< Downgrade_Informationm_downgrade_info
const Connection_Side m_side
Transcript_Hash_State m_transcript_hash

Detailed Description

SSL/TLS Server 1.3 implementation

Definition at line 22 of file tls_server_impl_13.h.

Constructor & Destructor Documentation

◆ Server_Impl_13()

Botan::TLS::Server_Impl_13::Server_Impl_13 ( const std::shared_ptr< Callbacks > & callbacks,
const std::shared_ptr< Session_Manager > & session_manager,
const std::shared_ptr< Credentials_Manager > & credentials_manager,
const std::shared_ptr< const Policy > & policy,
const std::shared_ptr< RandomNumberGenerator > & rng )
explicit

Definition at line 22 of file tls_server_impl_13.cpp.

26 :
28#if defined(BOTAN_HAS_TLS_12)
29 if(policy->allow_tls12()) {
30 expect_downgrade({}, {});
31 }
32#endif
33
34 m_transitions.set_expected_next(Handshake_Type::ClientHello);
35}
const Policy & policy() const
void expect_downgrade(const Server_Information &server_info, const std::vector< std::string > &next_protocols)
Credentials_Manager & credentials_manager()
RandomNumberGenerator & rng()
Channel_Impl_13(const std::shared_ptr< Callbacks > &callbacks, const std::shared_ptr< Session_Manager > &session_manager, const std::shared_ptr< Credentials_Manager > &credentials_manager, const std::shared_ptr< RandomNumberGenerator > &rng, const std::shared_ptr< const Policy > &policy, bool is_server)
Session_Manager & session_manager()

References Botan::TLS::Channel_Impl_13::callbacks(), Botan::TLS::Channel_Impl_13::Channel_Impl_13(), Botan::TLS::Channel_Impl_13::credentials_manager(), Botan::TLS::Channel_Impl_13::policy(), Botan::TLS::Channel_Impl_13::rng(), and Botan::TLS::Channel_Impl_13::session_manager().

Member Function Documentation

◆ aggregate_handshake_messages()

AggregatedHandshakeMessages Botan::TLS::Channel_Impl_13::aggregate_handshake_messages ( )
inlineprotectedinherited

Definition at line 258 of file tls_channel_impl_13.h.

References m_transcript_hash.

Referenced by send_handshake_message().

◆ aggregate_post_handshake_messages()

AggregatedPostHandshakeMessages Botan::TLS::Channel_Impl_13::aggregate_post_handshake_messages ( )
inlineprotectedinherited

◆ application_protocol()

std::string Botan::TLS::Server_Impl_13::application_protocol ( ) const
overridevirtual

Return the protocol notification set for this connection, if any (ALPN). This value is not tied to the session and a later renegotiation of the same session can choose a new protocol.

Implements Botan::TLS::Channel_Impl.

Definition at line 37 of file tls_server_impl_13.cpp.

37 {
39 const auto& eee = m_handshake_state.encrypted_extensions().extensions();
40 if(auto* const alpn = eee.get<Application_Layer_Protocol_Notification>()) {
41 return alpn->single_protocol();
42 }
43 }
44
45 return "";
46}
bool is_handshake_complete() const override

References application_protocol(), and is_handshake_complete().

Referenced by application_protocol().

◆ callbacks()

Callbacks & Botan::TLS::Channel_Impl_13::callbacks ( ) const
inlineprotectedinherited

◆ close()

void Botan::TLS::Channel_Impl::close ( )
inlineinherited

Send a close notification alert

Definition at line 76 of file tls_channel_impl.h.

76{ send_warning_alert(Alert::CloseNotify); }
void send_warning_alert(Alert::Type type)

References send_warning_alert().

◆ credentials_manager()

Credentials_Manager & Botan::TLS::Channel_Impl_13::credentials_manager ( )
inlineprotectedinherited

Definition at line 270 of file tls_channel_impl_13.h.

270{ return *m_credentials_manager; }

Referenced by Channel_Impl_13(), and Botan::TLS::Server_Impl_13::Server_Impl_13().

◆ expect_downgrade()

void Botan::TLS::Channel_Impl_13::expect_downgrade ( const Server_Information & server_info,
const std::vector< std::string > & next_protocols )
protectedinherited

Indicate that we have to expect a downgrade to TLS 1.2. In which case the current implementation (i.e. Client_Impl_13 or Server_Impl_13) will need to be replaced by their respective counter parts.

This will prepare an internal structure where any information required to downgrade can be preserved.

See also
Channel_Impl::Downgrade_Information

Definition at line 401 of file tls_channel_impl_13.cpp.

402 {
404 {},
405 {},
406 {},
407 server_info,
408 next_protocols,
410 m_callbacks,
411 m_session_manager,
412 m_credentials_manager,
413 m_rng,
414 m_policy,
415 false, // received_tls_13_error_alert
416 false // will_downgrade
417 };
418 m_downgrade_info = std::make_unique<Downgrade_Information>(std::move(di));
419}
std::unique_ptr< Downgrade_Information > m_downgrade_info
static constexpr size_t IO_BUF_DEFAULT_SIZE
Definition tls_channel.h:37

References Botan::TLS::Channel::IO_BUF_DEFAULT_SIZE, and Botan::TLS::Channel_Impl::m_downgrade_info.

◆ expects_downgrade()

bool Botan::TLS::Channel_Impl::expects_downgrade ( ) const
inlineinherited

Definition at line 276 of file tls_channel_impl.h.

276{ return m_downgrade_info != nullptr; }

References m_downgrade_info.

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

◆ external_psk_identity()

std::optional< std::string > Botan::TLS::Server_Impl_13::external_psk_identity ( ) const
overridevirtual
Returns
identity of the PSK used for this connection or std::nullopt if no PSK was used.

Implements Botan::TLS::Channel_Impl.

Definition at line 73 of file tls_server_impl_13.cpp.

73 {
74 return m_psk_identity;
75}

References external_psk_identity().

Referenced by external_psk_identity().

◆ extract_downgrade_info()

std::unique_ptr< Downgrade_Information > Botan::TLS::Channel_Impl::extract_downgrade_info ( )
inlineinherited
See also
Downgrade_Information

Definition at line 274 of file tls_channel_impl.h.

274{ return std::exchange(m_downgrade_info, {}); }

References m_downgrade_info.

◆ from_peer()

size_t Botan::TLS::Channel_Impl_13::from_peer ( std::span< const uint8_t > data)
overridevirtualinherited

Inject TLS traffic received from counterparty

Returns
a hint as the how many more bytes we need to q the current record (this may be 0 if on a record boundary)

Implements Botan::TLS::Channel_Impl.

Definition at line 66 of file tls_channel_impl_13.cpp.

66 {
68
69 // RFC 8446 6.1
70 // Any data received after a closure alert has been received MUST be ignored.
71 if(!m_can_read) {
72 return 0;
73 }
74
75 try {
76 if(expects_downgrade()) {
78 }
79
80 m_record_layer.copy_data(data);
81
82 while(true) {
83 // RFC 8446 6.1
84 // Any data received after a closure alert has been received MUST be ignored.
85 //
86 // ... this data might already be in the record layer's read buffer.
87 if(!m_can_read) {
88 return 0;
89 }
90
91 auto result = m_record_layer.next_record(m_cipher_state.get());
92
93 if(std::holds_alternative<BytesNeeded>(result)) {
94 return std::get<BytesNeeded>(result);
95 }
96
97 const auto& record = std::get<Record>(result);
98
99 // RFC 8446 5.1
100 // Handshake messages MUST NOT be interleaved with other record types.
101 if(record.type != Record_Type::Handshake && m_handshake_layer.has_pending_data()) {
102 throw Unexpected_Message("Expected remainder of a handshake message");
103 }
104
105 if(record.type == Record_Type::Handshake) {
106 m_handshake_layer.copy_data(record.fragment);
107
108 if(!is_handshake_complete()) {
109 while(auto handshake_msg = m_handshake_layer.next_message(policy(), m_transcript_hash)) {
110 // RFC 8446 5.1
111 // Handshake messages MUST NOT span key changes. Implementations
112 // MUST verify that all messages immediately preceding a key change
113 // align with a record boundary; if not, then they MUST terminate the
114 // connection with an "unexpected_message" alert. Because the
115 // ClientHello, EndOfEarlyData, ServerHello, Finished, and KeyUpdate
116 // messages can immediately precede a key change, implementations
117 // MUST send these messages in alignment with a record boundary.
118 //
119 // Note: Hello_Retry_Request was added to the list below although it cannot immediately precede a key change.
120 // However, there cannot be any further sensible messages in the record after HRR.
121 //
122 // Note: Server_Hello_12 was deliberately not included in the check below because in TLS 1.2 Server Hello and
123 // other handshake messages can be legally coalesced in a single record.
124 //
125 if(holds_any_of<Client_Hello_12_Shim,
126 Client_Hello_13 /*, EndOfEarlyData,*/,
127 Server_Hello_13,
128 Hello_Retry_Request,
129 Finished_13>(handshake_msg.value()) &&
130 m_handshake_layer.has_pending_data()) {
131 throw Unexpected_Message("Unexpected additional handshake message data found in record");
132 }
133
134 process_handshake_msg(std::move(handshake_msg.value()));
135
136 if(is_downgrading()) {
137 // Downgrade to TLS 1.2 was detected. Stop everything we do and await being replaced by a 1.2 implementation.
138 return 0;
139 } else if(m_downgrade_info != nullptr) {
140 // We received a TLS 1.3 error alert that could have been a TLS 1.2 warning alert.
141 // Now that we know that we are talking to a TLS 1.3 server, shut down.
142 if(m_downgrade_info->received_tls_13_error_alert) {
143 shutdown();
144 }
145
146 // Downgrade can only be indicated in the first received peer message. This was not the case.
147 m_downgrade_info.reset();
148 }
149
150 // After the initial handshake message is received, the record
151 // layer must be more restrictive.
152 // See RFC 8446 5.1 regarding "legacy_record_version"
153 if(!m_first_message_received) {
154 m_record_layer.disable_receiving_compat_mode();
155 m_first_message_received = true;
156 }
157 }
158 } else {
159 while(auto handshake_msg = m_handshake_layer.next_post_handshake_message(policy())) {
160 process_post_handshake_msg(std::move(handshake_msg.value()));
161 }
162 }
163 } else if(record.type == Record_Type::ChangeCipherSpec) {
165 } else if(record.type == Record_Type::ApplicationData) {
166 BOTAN_ASSERT(record.seq_no.has_value(), "decrypted application traffic had a sequence number");
167 callbacks().tls_record_received(record.seq_no.value(), record.fragment);
168 } else if(record.type == Record_Type::Alert) {
169 process_alert(record.fragment);
170 } else {
171 throw Unexpected_Message("Unexpected record type " + std::to_string(static_cast<size_t>(record.type)) +
172 " from counterparty");
173 }
174 }
175 } catch(TLS_Exception& e) {
176 send_fatal_alert(e.type());
177 throw;
178 } catch(Invalid_Authentication_Tag&) {
179 // RFC 8446 5.2
180 // If the decryption fails, the receiver MUST terminate the connection
181 // with a "bad_record_mac" alert.
182 send_fatal_alert(Alert::BadRecordMac);
183 throw;
184 } catch(Decoding_Error&) {
185 send_fatal_alert(Alert::DecodeError);
186 throw;
187 } catch(...) {
188 send_fatal_alert(Alert::InternalError);
189 throw;
190 }
191}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
#define BOTAN_ASSERT(expr, assertion_made)
Definition assert.h:62
virtual void tls_record_received(uint64_t seq_no, std::span< const uint8_t > data)=0
virtual void process_post_handshake_msg(Post_Handshake_Message_13 msg)=0
virtual void process_handshake_msg(Handshake_Message_13 msg)=0
virtual void process_dummy_change_cipher_spec()=0
std::unique_ptr< Cipher_State > m_cipher_state
void preserve_peer_transcript(std::span< const uint8_t > input)
void send_fatal_alert(Alert::Type type)
virtual bool is_handshake_complete() const =0
constexpr bool holds_any_of(const std::variant< Ts... > &v) noexcept
Definition stl_util.h:65

References Botan::TLS::Alert, Botan::TLS::ApplicationData, BOTAN_ASSERT, BOTAN_STATE_CHECK, callbacks(), Botan::TLS::ChangeCipherSpec, Botan::TLS::Channel_Impl::expects_downgrade(), Botan::TLS::Handshake, Botan::holds_any_of(), Botan::TLS::Channel_Impl::is_downgrading(), Botan::TLS::Channel_Impl::is_handshake_complete(), m_cipher_state, Botan::TLS::Channel_Impl::m_downgrade_info, m_transcript_hash, policy(), Botan::TLS::Channel_Impl::preserve_peer_transcript(), process_dummy_change_cipher_spec(), process_handshake_msg(), process_post_handshake_msg(), Botan::TLS::Channel_Impl::send_fatal_alert(), Botan::TLS::Callbacks::tls_record_received(), and Botan::TLS::TLS_Exception::type().

◆ is_active()

bool Botan::TLS::Channel_Impl_13::is_active ( ) const
overridevirtualinherited
Returns
true iff the connection is active for sending application data

Note that the connection is active until the application has called close(), even if a CloseNotify has been received from the peer.

Implements Botan::TLS::Channel_Impl.

Definition at line 303 of file tls_channel_impl_13.cpp.

303 {
304 return m_cipher_state != nullptr && m_cipher_state->can_encrypt_application_traffic() // handshake done
305 && m_can_write; // close() hasn't been called
306}

References m_cipher_state.

Referenced by to_peer().

◆ is_closed()

bool Botan::TLS::Channel_Impl_13::is_closed ( ) const
inlineoverridevirtualinherited
Returns
true iff the connection has been closed, i.e. CloseNotify has been received from the peer.

Implements Botan::TLS::Channel_Impl.

Definition at line 169 of file tls_channel_impl_13.h.

bool is_closed_for_reading() const override
bool is_closed_for_writing() const override

References is_closed_for_reading(), and is_closed_for_writing().

◆ is_closed_for_reading()

bool Botan::TLS::Channel_Impl_13::is_closed_for_reading ( ) const
inlineoverridevirtualinherited
Returns
true iff the connection is active for sending application data

Implements Botan::TLS::Channel_Impl.

Definition at line 171 of file tls_channel_impl_13.h.

171{ return !m_can_read; }

Referenced by is_closed().

◆ is_closed_for_writing()

bool Botan::TLS::Channel_Impl_13::is_closed_for_writing ( ) const
inlineoverridevirtualinherited
Returns
true iff the connection has been definitely closed

Implements Botan::TLS::Channel_Impl.

Definition at line 173 of file tls_channel_impl_13.h.

173{ return !m_can_write; }

Referenced by is_closed().

◆ is_downgrading()

bool Botan::TLS::Channel_Impl::is_downgrading ( ) const
inlineinherited

Indicates whether a downgrade to TLS 1.2 or lower is in progress

See also
Downgrade_Information

Definition at line 269 of file tls_channel_impl.h.

269{ return m_downgrade_info && m_downgrade_info->will_downgrade; }

References m_downgrade_info.

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

◆ is_handshake_complete()

bool Botan::TLS::Server_Impl_13::is_handshake_complete ( ) const
overridevirtual
Returns
true iff the TLS handshake has finished successfully

Implements Botan::TLS::Channel_Impl.

Definition at line 169 of file tls_server_impl_13.cpp.

169 {
170 return m_handshake_state.handshake_finished();
171}

References is_handshake_complete().

Referenced by application_protocol(), is_handshake_complete(), new_session_ticket_supported(), and send_new_session_tickets().

◆ key_material_export()

SymmetricKey Botan::TLS::Channel_Impl_13::key_material_export ( std::string_view label,
std::string_view context,
size_t length ) const
overridevirtualinherited

Key material export (RFC 5705)

Parameters
labela disambiguating label string
contexta per-association context value
lengththe length of the desired key in bytes
Returns
key of length bytes

Implements Botan::TLS::Channel_Impl.

Definition at line 308 of file tls_channel_impl_13.cpp.

310 {
312 BOTAN_STATE_CHECK(m_cipher_state != nullptr && m_cipher_state->can_export_keys());
313 return SymmetricKey(m_cipher_state->export_key(label, context, length));
314}
OctetString SymmetricKey
Definition symkey.h:140

References BOTAN_STATE_CHECK, Botan::TLS::Channel_Impl::is_downgrading(), and m_cipher_state.

◆ new_session_ticket_supported()

bool Botan::TLS::Server_Impl_13::new_session_ticket_supported ( ) const
overridevirtual
Returns
true if this channel can issue TLS 1.3 style session tickets.

Reimplemented from Botan::TLS::Channel_Impl.

Definition at line 77 of file tls_server_impl_13.cpp.

77 {
78 // RFC 8446 4.2.9
79 // This extension also restricts the modes for use with PSK resumption.
80 // Servers SHOULD NOT send NewSessionTicket with tickets that are not
81 // compatible with the advertised modes; however, if a server does so,
82 // the impact will just be that the client's attempts at resumption fail.
83 //
84 // Note: Applications can overrule this by calling send_new_session_tickets()
85 // regardless of this method indicating no support for tickets.
86 //
87 // TODO: Implement other PSK KE modes than PSK_DHE_KE
88 return is_handshake_complete() && m_handshake_state.client_hello().extensions().has<PSK_Key_Exchange_Modes>() &&
89 value_exists(m_handshake_state.client_hello().extensions().get<PSK_Key_Exchange_Modes>()->modes(),
91}
bool value_exists(const std::vector< T > &vec, const V &val)
Definition stl_util.h:43

References is_handshake_complete(), Botan::TLS::PSK_Key_Exchange_Modes::modes(), new_session_ticket_supported(), Botan::TLS::PSK_DHE_KE, and Botan::value_exists().

Referenced by new_session_ticket_supported().

◆ opportunistically_update_traffic_keys()

void Botan::TLS::Channel_Impl_13::opportunistically_update_traffic_keys ( )
inlineprotectedinherited

Schedule a traffic key update to opportunistically happen before the channel sends application data the next time. Such a key update will never request a reciprocal key update from the peer.

Definition at line 240 of file tls_channel_impl_13.h.

240{ m_opportunistic_key_update = true; }

Referenced by handle().

◆ peer_cert_chain()

std::vector< X509_Certificate > Botan::TLS::Server_Impl_13::peer_cert_chain ( ) const
overridevirtual
Returns
certificate chain of the peer (may be empty)

Implements Botan::TLS::Channel_Impl.

Definition at line 48 of file tls_server_impl_13.cpp.

48 {
49 if(m_handshake_state.has_client_certificate_msg() &&
50 m_handshake_state.client_certificate().has_certificate_chain()) {
51 return m_handshake_state.client_certificate().cert_chain();
52 }
53
54 if(m_resumed_session.has_value()) {
55 return m_resumed_session->peer_certs();
56 }
57
58 return {};
59}

References peer_cert_chain().

Referenced by peer_cert_chain(), and send_new_session_tickets().

◆ peer_raw_public_key()

std::shared_ptr< const Public_Key > Botan::TLS::Server_Impl_13::peer_raw_public_key ( ) const
overridevirtual
Returns
raw public key of the peer (may be nullptr)

Implements Botan::TLS::Channel_Impl.

Definition at line 61 of file tls_server_impl_13.cpp.

61 {
62 if(m_handshake_state.has_client_certificate_msg() && m_handshake_state.client_certificate().is_raw_public_key()) {
63 return m_handshake_state.client_certificate().public_key();
64 }
65
66 if(m_resumed_session.has_value()) {
67 return m_resumed_session->peer_raw_public_key();
68 }
69
70 return nullptr;
71}

References peer_raw_public_key().

Referenced by peer_raw_public_key(), and send_new_session_tickets().

◆ policy()

const Policy & Botan::TLS::Channel_Impl_13::policy ( ) const
inlineprotectedinherited

◆ prepend_ccs()

virtual bool Botan::TLS::Channel_Impl_13::prepend_ccs ( )
inlineprotectedvirtualinherited
Returns
whether a change cipher spec record should be prepended now

This method can be used by subclasses to indicate that send_record should prepend a CCS before the actual record. This is useful for middlebox compatibility mode. See RFC 8446 D.4.

Definition at line 231 of file tls_channel_impl_13.h.

231{ return false; }

◆ preserve_client_hello()

void Botan::TLS::Channel_Impl::preserve_client_hello ( std::span< const uint8_t > msg)
inlineprotectedinherited

Definition at line 229 of file tls_channel_impl.h.

229 {
231 m_downgrade_info->client_hello_message.assign(msg.begin(), msg.end());
232 }

References BOTAN_STATE_CHECK, and m_downgrade_info.

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

◆ preserve_peer_transcript()

void Botan::TLS::Channel_Impl::preserve_peer_transcript ( std::span< const uint8_t > input)
inlineprotectedinherited

Definition at line 224 of file tls_channel_impl.h.

224 {
226 m_downgrade_info->peer_transcript.insert(m_downgrade_info->peer_transcript.end(), input.begin(), input.end());
227 }

References BOTAN_STATE_CHECK, and m_downgrade_info.

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

◆ renegotiate()

void Botan::TLS::Channel_Impl_13::renegotiate ( bool )
inlineoverridevirtualinherited

Attempt to renegotiate the session

Implements Botan::TLS::Channel_Impl.

Definition at line 187 of file tls_channel_impl_13.h.

187 {
188 throw Invalid_Argument("renegotiation is not allowed in TLS 1.3");
189 }

◆ request_downgrade()

void Botan::TLS::Channel_Impl::request_downgrade ( )
inlineprotectedinherited

Implementations use this to signal that the peer indicated a protocol version downgrade. After calling request_downgrade() no further state changes must be performed by the implementation. Particularly, no further handshake messages must be emitted. Instead, they must yield control flow back to the underlying Channel implementation to perform the protocol version downgrade.

Definition at line 250 of file tls_channel_impl.h.

250 {
252 m_downgrade_info->will_downgrade = true;
253 }

References BOTAN_STATE_CHECK, and m_downgrade_info.

Referenced by request_downgrade_for_resumption().

◆ request_downgrade_for_resumption()

void Botan::TLS::Channel_Impl::request_downgrade_for_resumption ( Session_with_Handle session)
inlineprotectedinherited

Definition at line 255 of file tls_channel_impl.h.

255 {
256 BOTAN_STATE_CHECK(m_downgrade_info && m_downgrade_info->client_hello_message.empty() &&
257 m_downgrade_info->peer_transcript.empty() && !m_downgrade_info->tls12_session.has_value());
258 BOTAN_ASSERT_NOMSG(session.session.version().is_pre_tls_13());
259 m_downgrade_info->tls12_session = std::move(session);
261 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References BOTAN_ASSERT_NOMSG, BOTAN_STATE_CHECK, Botan::TLS::Protocol_Version::is_pre_tls_13(), m_downgrade_info, request_downgrade(), Botan::TLS::Session_with_Handle::session, and Botan::TLS::Session_Base::version().

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

◆ rng()

RandomNumberGenerator & Botan::TLS::Channel_Impl_13::rng ( )
inlineprotectedinherited

◆ secure_renegotiation_supported()

bool Botan::TLS::Channel_Impl_13::secure_renegotiation_supported ( ) const
inlineoverridevirtualinherited
Returns
true iff the counterparty supports the secure renegotiation extensions.

Implements Botan::TLS::Channel_Impl.

Definition at line 203 of file tls_channel_impl_13.h.

203 {
204 // Secure renegotiation is not supported in TLS 1.3, though BoGo
205 // tests expect us to claim that it is available.
206 return true;
207 }

◆ send_alert()

void Botan::TLS::Channel_Impl_13::send_alert ( const Alert & alert)
overridevirtualinherited

Send a TLS alert message. If the alert is fatal, the internal state (keys, etc) will be reset.

Parameters
alertthe Alert to send

Implements Botan::TLS::Channel_Impl.

Definition at line 278 of file tls_channel_impl_13.cpp.

278 {
279 if(alert.is_valid() && m_can_write) {
280 try {
281 send_record(Record_Type::Alert, alert.serialize());
282 } catch(...) { /* swallow it */
283 }
284 }
285
286 // Note: In TLS 1.3 sending a CloseNotify must not immediately lead to closing the reading end.
287 // RFC 8446 6.1
288 // Each party MUST send a "close_notify" alert before closing its write
289 // side of the connection, unless it has already sent some error alert.
290 // This does not have any effect on its read side of the connection.
291 if(is_close_notify_alert(alert) && m_can_write) {
292 m_can_write = false;
293 if(m_cipher_state) {
294 m_cipher_state->clear_write_keys();
295 }
296 }
297
298 if(is_error_alert(alert)) {
299 shutdown();
300 }
301}

References Botan::TLS::Alert, Botan::TLS::Alert::is_valid(), m_cipher_state, and Botan::TLS::Alert::serialize().

◆ send_dummy_change_cipher_spec()

void Botan::TLS::Channel_Impl_13::send_dummy_change_cipher_spec ( )
protectedinherited

Definition at line 247 of file tls_channel_impl_13.cpp.

247 {
248 // RFC 8446 5.
249 // The change_cipher_spec record is used only for compatibility purposes
250 // (see Appendix D.4).
251 //
252 // The only allowed CCS message content is 0x01, all other CCS records MUST
253 // be rejected by TLS 1.3 implementations.
254 send_record(Record_Type::ChangeCipherSpec, {0x01});
255}

References Botan::TLS::ChangeCipherSpec.

◆ send_fatal_alert()

void Botan::TLS::Channel_Impl::send_fatal_alert ( Alert::Type type)
inlineinherited

Send a fatal alert

Definition at line 71 of file tls_channel_impl.h.

71{ send_alert(Alert(type, true)); }
virtual void send_alert(const Alert &alert)=0

References Botan::TLS::Alert, and send_alert().

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

◆ send_handshake_message() [1/2]

template<typename... MsgTs>
std::vector< uint8_t > Botan::TLS::Channel_Impl_13::send_handshake_message ( const std::variant< MsgTs... > & message)
inlineprotectedinherited

Definition at line 243 of file tls_channel_impl_13.h.

243 {
245 }
AggregatedHandshakeMessages & add(Handshake_Message_13_Ref message)
AggregatedHandshakeMessages aggregate_handshake_messages()
constexpr GeneralVariantT generalize_to(SpecialT &&specific)
Converts a given variant into another variant-ish whose type states are a super set of the given vari...
Definition stl_util.h:87

References Botan::TLS::Channel_Impl_13::AggregatedHandshakeMessages::add(), aggregate_handshake_messages(), Botan::generalize_to(), and Botan::TLS::Channel_Impl_13::AggregatedMessages::send().

Referenced by Botan::TLS::Client_Impl_13::Client_Impl_13(), and send_handshake_message().

◆ send_handshake_message() [2/2]

template<typename MsgT>
std::vector< uint8_t > Botan::TLS::Channel_Impl_13::send_handshake_message ( std::reference_wrapper< MsgT > message)
inlineprotectedinherited

Definition at line 248 of file tls_channel_impl_13.h.

248 {
250 }
std::vector< uint8_t > send_handshake_message(const std::variant< MsgTs... > &message)

References Botan::generalize_to(), and send_handshake_message().

◆ send_new_session_tickets()

size_t Botan::TLS::Server_Impl_13::send_new_session_tickets ( size_t )
overridevirtual

Send tickets new session tickets to the peer. This is only supported on TLS 1.3 servers.

If the server's Session_Manager does not accept the generated Session objects, the server implementation won't be able to send new tickets. Additionally, anything but TLS 1.3 servers will return 0 (because they don't support sending such session tickets).

Returns
the number of session tickets successfully sent to the client

Reimplemented from Botan::TLS::Channel_Impl.

Definition at line 93 of file tls_server_impl_13.cpp.

93 {
95
96 if(tickets == 0) {
97 return 0;
98 }
99
100 auto flight = aggregate_post_handshake_messages();
101 size_t tickets_created = 0;
102
103 for(size_t i = 0; i < tickets; ++i) {
104 auto nonce = m_cipher_state->next_ticket_nonce();
105 const Session session(m_cipher_state->psk(nonce),
106 std::nullopt, // early data not yet implemented
107 policy().session_ticket_lifetime(),
110 m_handshake_state.client_hello(),
111 m_handshake_state.server_hello(),
112 callbacks(),
113 rng());
114
115 if(callbacks().tls_should_persist_resumption_information(session)) {
116 if(auto handle = session_manager().establish(session)) {
117 flight.add(New_Session_Ticket_13(std::move(nonce), session, handle.value(), callbacks()));
118 ++tickets_created;
119 }
120 }
121 }
122
123 if(flight.contains_messages()) {
124 flight.send();
125 }
126
127 return tickets_created;
128}
AggregatedPostHandshakeMessages aggregate_post_handshake_messages()
std::vector< X509_Certificate > peer_cert_chain() const override
std::shared_ptr< const Public_Key > peer_raw_public_key() const override

References Botan::TLS::Channel_Impl_13::aggregate_post_handshake_messages(), BOTAN_STATE_CHECK, Botan::TLS::Channel_Impl_13::callbacks(), is_handshake_complete(), Botan::TLS::Channel_Impl_13::m_cipher_state, peer_cert_chain(), peer_raw_public_key(), Botan::TLS::Channel_Impl_13::policy(), Botan::TLS::Channel_Impl_13::rng(), send_new_session_tickets(), and Botan::TLS::Channel_Impl_13::session_manager().

Referenced by send_new_session_tickets().

◆ send_post_handshake_message()

std::vector< uint8_t > Botan::TLS::Channel_Impl_13::send_post_handshake_message ( Post_Handshake_Message_13 message)
inlineprotectedinherited

◆ send_warning_alert()

void Botan::TLS::Channel_Impl::send_warning_alert ( Alert::Type type)
inlineinherited

Send a warning alert

Definition at line 66 of file tls_channel_impl.h.

66{ send_alert(Alert(type, false)); }

References Botan::TLS::Alert, and send_alert().

Referenced by close().

◆ session_manager()

Session_Manager & Botan::TLS::Channel_Impl_13::session_manager ( )
inlineprotectedinherited

◆ set_io_buffer_size()

void Botan::TLS::Channel_Impl::set_io_buffer_size ( size_t io_buf_sz)
inlineprotectedinherited

Definition at line 237 of file tls_channel_impl.h.

237 {
239 m_downgrade_info->io_buffer_size = io_buf_sz;
240 }

References BOTAN_STATE_CHECK, and m_downgrade_info.

◆ set_record_size_limits()

void Botan::TLS::Channel_Impl_13::set_record_size_limits ( uint16_t outgoing_limit,
uint16_t incoming_limit )
protectedinherited

Set the record size limits as negotiated by the "record_size_limit" extension (RFC 8449).

Parameters
outgoing_limitthe maximal number of plaintext bytes to be sent in a protected record
incoming_limitthe maximal number of plaintext bytes to be accepted in a received protected record

Definition at line 421 of file tls_channel_impl_13.cpp.

421 {
422 m_record_layer.set_record_size_limits(outgoing_limit, incoming_limit);
423}

◆ set_selected_certificate_type()

void Botan::TLS::Channel_Impl_13::set_selected_certificate_type ( Certificate_Type cert_type)
protectedinherited

Set the expected certificate type needed to parse Certificate messages in the handshake layer. See RFC 7250 and 8446 4.4.2 for further details.

Definition at line 425 of file tls_channel_impl_13.cpp.

425 {
426 m_handshake_layer.set_selected_certificate_type(cert_type);
427}

◆ timeout_check()

bool Botan::TLS::Channel_Impl_13::timeout_check ( )
inlineoverridevirtualinherited

Perform a handshake timeout check. This does nothing unless this is a DTLS channel with a pending handshake state, in which case we check for timeout and potentially retransmit handshake packets.

In the TLS 1.3 implementation, this always returns false.

Implements Botan::TLS::Channel_Impl.

Definition at line 217 of file tls_channel_impl_13.h.

217{ return false; }

◆ to_peer()

void Botan::TLS::Channel_Impl_13::to_peer ( std::span< const uint8_t > data)
overridevirtualinherited

Inject plaintext intended for counterparty Throws an exception if is_active() is false

Implements Botan::TLS::Channel_Impl.

Definition at line 257 of file tls_channel_impl_13.cpp.

257 {
258 if(!is_active()) {
259 throw Invalid_State("Data cannot be sent on inactive TLS connection");
260 }
261
262 // RFC 8446 4.6.3
263 // If the request_update field [of a received KeyUpdate] is set to
264 // "update_requested", then the receiver MUST send a KeyUpdate of its own
265 // with request_update set to "update_not_requested" prior to sending its
266 // next Application Data record.
267 // This mechanism allows either side to force an update to the entire
268 // connection, but causes an implementation which receives multiple
269 // KeyUpdates while it is silent to respond with a single update.
270 if(m_opportunistic_key_update) {
271 update_traffic_keys(false /* update_requested */);
272 m_opportunistic_key_update = false;
273 }
274
275 send_record(Record_Type::ApplicationData, {data.begin(), data.end()});
276}
void update_traffic_keys(bool request_peer_update=false) override

References Botan::TLS::ApplicationData, is_active(), and update_traffic_keys().

◆ update_traffic_keys()

void Botan::TLS::Channel_Impl_13::update_traffic_keys ( bool request_peer_update = false)
overridevirtualinherited

Attempt to update the session's traffic key material Note that this is possible with a TLS 1.3 channel, only.

Parameters
request_peer_updateif true, require a reciprocal key update

Implements Botan::TLS::Channel_Impl.

Definition at line 316 of file tls_channel_impl_13.cpp.

316 {
320 send_post_handshake_message(Key_Update(request_peer_update));
321 m_cipher_state->update_write_keys(*this);
322}
#define BOTAN_ASSERT_NONNULL(ptr)
Definition assert.h:114
std::vector< uint8_t > send_post_handshake_message(Post_Handshake_Message_13 message)

References BOTAN_ASSERT_NONNULL, BOTAN_STATE_CHECK, Botan::TLS::Channel_Impl::is_downgrading(), Botan::TLS::Channel_Impl::is_handshake_complete(), m_cipher_state, and send_post_handshake_message().

Referenced by to_peer().

Member Data Documentation

◆ m_cipher_state

std::unique_ptr<Cipher_State> Botan::TLS::Channel_Impl_13::m_cipher_state
protectedinherited

◆ m_downgrade_info

◆ m_side

const Connection_Side Botan::TLS::Channel_Impl_13::m_side
protectedinherited

Definition at line 288 of file tls_channel_impl_13.h.

Referenced by Channel_Impl_13().

◆ m_transcript_hash

Transcript_Hash_State Botan::TLS::Channel_Impl_13::m_transcript_hash
protectedinherited

Definition at line 289 of file tls_channel_impl_13.h.

Referenced by aggregate_handshake_messages(), and from_peer().


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