11#include <botan/internal/tls_channel_impl_13.h>
13#include <botan/tls_callbacks.h>
14#include <botan/tls_exceptn.h>
15#include <botan/tls_messages_13.h>
16#include <botan/internal/stl_util.h>
17#include <botan/internal/tls_channel_io.h>
18#include <botan/internal/tls_cipher_state.h>
19#include <botan/internal/tls_transcript_hash_13.h>
28 return alert.
type() == Botan::TLS::Alert::UserCanceled;
32 return alert.
type() == Botan::TLS::Alert::CloseNotify;
38 return !is_close_notify_alert(alert) && !is_user_canceled_alert(alert);
46 const std::shared_ptr<RandomNumberGenerator>&
rng,
47 const std::shared_ptr<const Policy>&
policy,
85#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
87 preserve_peer_transcript(data);
106 const auto bytes_needed = std::visit(
108 [](
BytesNeeded bytes) -> std::optional<BytesNeeded> {
return bytes; },
110 [&]<
typename T>(T&& event) -> std::optional<BytesNeeded> {
111 constexpr bool can_report_bytes_needed =
112 std::is_same_v<std::optional<BytesNeeded>,
decltype(process(std::forward<T>(event)))>;
113 if constexpr(can_report_bytes_needed) {
114 return process(std::forward<T>(event));
116 process(std::forward<T>(event));
123 if(bytes_needed.has_value()) {
124 return *bytes_needed;
154 throw Invalid_State(
"Data cannot be sent on inactive TLS connection");
173 const Alert to_send = is_error_alert(alert) ?
Alert(alert.
type(),
true) : alert;
185 if(is_close_notify_alert(alert) && m_can_write) {
192 if(is_error_alert(alert)) {
203 std::string_view context,
204 size_t length)
const {
216 return [weak = weak_from_this()](std::string_view label, std::span<const uint8_t> secret) {
217 if(
const auto self = dynamic_pointer_cast<const Channel_Impl_13>(weak.lock())) {
218 self->maybe_log_secret(label, secret);
235#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
241 if(m_downgrade_info !=
nullptr) {
244 if(m_downgrade_info->received_tls_13_error_alert) {
249 m_downgrade_info.reset();
261void Channel_Impl_13::process(
const Alert_Record& alert_record) {
262 const Alert alert(alert_record.payload);
264 if(is_close_notify_alert(alert)) {
279 if(is_error_alert(alert) && !alert.
is_fatal()) {
281 throw TLS_Exception(Alert::DecodeError,
"Error alert not marked fatal");
284#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
291 m_downgrade_info->received_tls_13_error_alert =
true;
301 const bool is_fatal_error_alert = is_error_alert(alert) && alert.
is_fatal();
303 if(!is_close_notify_alert(alert) && !is_fatal_error_alert) {
307 if(is_fatal_error_alert) {
314 if(is_close_notify_alert(alert) &&
callbacks().tls_peer_closed_connection()) {
329 throw Unexpected_Message(
"Application data received before handshake completion");
332 if(record.payload.empty()) {
341void Channel_Impl_13::shutdown() {
353#if defined(BOTAN_HAS_TLS_DOWNGRADE_SUPPORT)
356 const std::vector<std::string>& next_protocols) {
357 Downgrade_Information di{
367 m_credentials_manager,
374 m_downgrade_info = std::make_unique<Downgrade_Information>(std::move(di));
380 m_channel_io->set_record_size_limits(outgoing_limit, incoming_limit);
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_DEBUG_ASSERT(expr)
#define BOTAN_STATE_CHECK(expr)
#define BOTAN_ASSERT_NONNULL(ptr)
virtual void tls_record_received(uint64_t seq_no, std::span< const uint8_t > data)=0
virtual void tls_alert(Alert alert)=0
~Channel_Impl_13() override
std::shared_ptr< Cipher_State > m_cipher_state
Cipher_State & setup_cipher_state(std::unique_ptr< Cipher_State > cipher_state)
const Policy & policy() const
SymmetricKey key_material_export(std::string_view label, std::string_view context, size_t length) const override
void send_flight(std::vector< Flight::Message > flight)
void handle(const Key_Update &key_update)
Credentials_Manager & credentials_manager()
RandomNumberGenerator & rng()
std::optional< Transcript_Hash_State > m_transcript_hash
void to_peer(std::span< const uint8_t > data) override
virtual bool compat_mode_ccs_requested() const =0
virtual void process_post_handshake_msg(Post_Handshake_Message_13 msg)=0
std::optional< Active_Connection_State_13 > m_active_state
virtual void process_handshake_msg(Handshake_Message_13 msg)=0
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)
SecretLoggerFn secret_logger() const
std::shared_ptr< Channel_IO > m_channel_io
void send_alert(const Alert &alert) override
size_t from_peer(std::span< const uint8_t > data) override
void update_traffic_keys(bool request_peer_update=false) override
virtual void process_dummy_change_cipher_spec()=0
Session_Manager & session_manager()
const Connection_Side m_side
bool is_active() const override
Callbacks & callbacks() const
void set_selected_certificate_type(Certificate_Type cert_type)
void set_record_size_limits(uint16_t outgoing_limit, uint16_t incoming_limit)
bool is_downgrading() const
bool expects_downgrade() const
void reset_useless_records()
void send_fatal_alert(Alert::Type type)
void note_useless_record(const Policy &policy)
virtual bool is_handshake_complete() const =0
static constexpr size_t IO_BUF_DEFAULT_SIZE
std::variant< Client_Hello_13, Client_Hello_12_Shim, Server_Hello_13, Server_Hello_12_Shim, Hello_Retry_Request, Encrypted_Extensions, Certificate_13, Certificate_Request_13, Certificate_Verify_13, Finished_13 > Handshake_Message_13
std::function< void(std::string_view label, std::span< const uint8_t > secret)> SecretLoggerFn
std::variant< New_Session_Ticket_13, Key_Update > Post_Handshake_Message_13