8#ifndef BOTAN_TLS_HANDSHAKE_IO_H_
9#define BOTAN_TLS_HANDSHAKE_IO_H_
11#include <botan/tls_magic.h>
12#include <botan/tls_version.h>
13#include <botan/internal/tls_channel_impl.h>
23class Handshake_Message;
56 virtual std::vector<uint8_t>
format(
const std::vector<uint8_t>& handshake_msg,
62 uint64_t sequence_number) = 0;
67 virtual std::pair<Handshake_Type, std::vector<uint8_t>>
get_next_record(
bool expecting_ccs) = 0;
97 std::vector<uint8_t>
format(
const std::vector<uint8_t>& handshake_msg,
100 void add_record(
const uint8_t record[],
size_t record_len,
Record_Type type, uint64_t sequence_number)
override;
102 std::pair<Handshake_Type, std::vector<uint8_t>>
get_next_record(
bool expecting_ccs)
override;
105 std::deque<uint8_t> m_queue;
119 uint64_t initial_timeout_ms,
120 uint64_t max_timeout_ms) :
123 m_initial_timeout(initial_timeout_ms),
124 m_max_timeout(max_timeout_ms),
138 std::vector<uint8_t>
format(
const std::vector<uint8_t>& handshake_msg,
141 void add_record(
const uint8_t record[],
size_t record_len,
Record_Type type, uint64_t sequence_number)
override;
143 std::pair<Handshake_Type, std::vector<uint8_t>>
get_next_record(
bool expecting_ccs)
override;
146 void retransmit_flight(
size_t flight);
147 void retransmit_last_flight();
149 std::vector<uint8_t> format_fragment(
const uint8_t fragment[],
151 uint16_t frag_offset,
154 uint16_t msg_sequence)
const;
156 std::vector<uint8_t> format_w_seq(
const std::vector<uint8_t>& handshake_msg,
158 uint16_t msg_sequence)
const;
160 std::vector<uint8_t> send_message(uint16_t msg_seq,
163 const std::vector<uint8_t>& msg);
165 class Handshake_Reassembly
final {
167 void add_fragment(
const uint8_t fragment[],
168 size_t fragment_length,
169 size_t fragment_offset,
174 bool complete()
const;
176 uint16_t epoch()
const {
return m_epoch; }
178 std::pair<Handshake_Type, std::vector<uint8_t>> message()
const;
182 size_t m_msg_length = 0;
183 uint16_t m_epoch = 0;
187 std::map<size_t, uint8_t> m_fragments;
188 std::vector<uint8_t> m_message;
191 struct Message_Info
final {
192 Message_Info(uint16_t e,
Handshake_Type mt,
const std::vector<uint8_t>& msg) :
193 epoch(e), msg_type(mt), msg_bits(msg) {}
199 std::vector<uint8_t> msg_bits;
202 class Connection_Sequence_Numbers& m_seqs;
203 std::map<uint16_t, Handshake_Reassembly> m_messages;
204 std::set<uint16_t> m_ccs_epochs;
205 std::vector<std::vector<uint16_t>> m_flights;
206 std::map<uint16_t, Message_Info> m_flight_data;
208 uint64_t m_initial_timeout = 0;
209 uint64_t m_max_timeout = 0;
211 uint64_t m_last_write = 0;
212 uint64_t m_next_timeout = 0;
214 uint16_t m_in_message_seq = 0;
215 uint16_t m_out_message_seq = 0;
std::vector< uint8_t > send_under_epoch(const Handshake_Message &msg, uint16_t epoch) override
bool timeout_check() override
void add_record(const uint8_t record[], size_t record_len, Record_Type type, uint64_t sequence_number) override
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_record(bool expecting_ccs) override
std::vector< uint8_t > format(const std::vector< uint8_t > &handshake_msg, Handshake_Type handshake_type) const override
std::function< void(uint16_t, Record_Type, const std::vector< uint8_t > &)> writer_fn
Protocol_Version initial_record_version() const override
std::vector< uint8_t > send(const Handshake_Message &msg) override
Datagram_Handshake_IO(writer_fn writer, class Connection_Sequence_Numbers &seq, uint16_t mtu, uint64_t initial_timeout_ms, uint64_t max_timeout_ms)
bool have_more_data() const override
virtual std::vector< uint8_t > send_under_epoch(const Handshake_Message &msg, uint16_t epoch)=0
Handshake_IO(const Handshake_IO &)=delete
virtual bool timeout_check()=0
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
Handshake_IO & operator=(const Handshake_IO &)=delete
virtual void add_record(const uint8_t record[], size_t record_len, Record_Type type, uint64_t sequence_number)=0
virtual Protocol_Version initial_record_version() const =0
virtual std::vector< uint8_t > format(const std::vector< uint8_t > &handshake_msg, Handshake_Type handshake_type) const =0
virtual ~Handshake_IO()=default
virtual bool have_more_data() const =0
virtual std::pair< Handshake_Type, std::vector< uint8_t > > get_next_record(bool expecting_ccs)=0
bool have_more_data() const override
std::vector< uint8_t > send_under_epoch(const Handshake_Message &msg, uint16_t epoch) override
Stream_Handshake_IO(writer_fn writer)
std::vector< uint8_t > format(const std::vector< uint8_t > &handshake_msg, Handshake_Type handshake_type) const override
Protocol_Version initial_record_version() const override
std::pair< Handshake_Type, std::vector< uint8_t > > get_next_record(bool expecting_ccs) override
bool timeout_check() override
std::vector< uint8_t > send(const Handshake_Message &msg) override
void add_record(const uint8_t record[], size_t record_len, Record_Type type, uint64_t sequence_number) override
std::function< void(Record_Type, const std::vector< uint8_t > &)> writer_fn
int(* final)(unsigned char *, CTX *)