9#include <botan/internal/tls_handshake_layer_13.h>
11#include <botan/tls_alert.h>
12#include <botan/tls_exceptn.h>
13#include <botan/internal/stl_util.h>
14#include <botan/internal/tls_reader.h>
15#include <botan/internal/tls_transcript_hash_13.h>
20 m_read_buffer.insert(m_read_buffer.end(), data_from_peer.begin(), data_from_peer.end());
25constexpr size_t HEADER_LENGTH = 4;
27template <
typename Msg_Type>
31 if constexpr(std::is_same_v<Msg_Type, Handshake_Message_13>) {
57template <
typename Msg_Type>
58std::optional<Msg_Type> parse_message(TLS::TLS_Data_Reader& reader,
63 if(reader.remaining_bytes() < HEADER_LENGTH) {
67 Handshake_Type type = handshake_type_from_byte<Msg_Type>(reader.get_byte());
70 const size_t msg_len = reader.get_uint24_t();
71 if(reader.remaining_bytes() < msg_len) {
76 const auto msg = reader.get_fixed<uint8_t>(msg_len);
77 if constexpr(std::is_same_v<Msg_Type, Handshake_Message_13>) {
91 return Encrypted_Extensions(msg);
93 return Certificate_13(msg, policy, peer_side, cert_type);
95 return Certificate_Request_13(msg, peer_side);
97 return Certificate_Verify_13(msg, peer_side);
99 return Finished_13(msg);
108 return New_Session_Ticket_13(msg, peer_side);
110 return Key_Update(msg);
123 auto msg = parse_message<Handshake_Message_13>(reader, policy, m_peer, m_certificate_type);
124 if(msg.has_value()) {
127 m_read_buffer.erase(m_read_buffer.cbegin(), m_read_buffer.cbegin() + reader.
read_so_far());
136 auto msg = parse_message<Post_Handshake_Message_13>(reader, policy, m_peer, m_certificate_type);
137 if(msg.has_value()) {
138 m_read_buffer.erase(m_read_buffer.cbegin(), m_read_buffer.cbegin() + reader.
read_so_far());
147const T& get(
const std::reference_wrapper<T>& v) {
152const T& get(
const T& v) {
157std::vector<uint8_t> marshall_message(
const T& message) {
158 auto [type, serialized] =
159 std::visit([](
const auto& msg) {
return std::pair(get(msg).wire_type(), get(msg).serialize()); }, message);
162 const uint32_t msg_size =
static_cast<uint32_t
>(serialized.size());
164 std::vector<uint8_t> header{
167 return concat(header, serialized);
174 auto msg = marshall_message(message);
175 transcript_hash.
update(msg);
180 return marshall_message(message);
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ASSERT(expr, assertion_made)
static std::variant< Client_Hello_13, Client_Hello_12 > parse(const std::vector< uint8_t > &buf)
static std::vector< uint8_t > prepare_message(Handshake_Message_13_Ref message, Transcript_Hash_State &transcript_hash)
std::optional< Handshake_Message_13 > next_message(const Policy &policy, Transcript_Hash_State &transcript_hash)
std::optional< Post_Handshake_Message_13 > next_post_handshake_message(const Policy &policy)
static std::vector< uint8_t > prepare_post_handshake_message(const Post_Handshake_Message_13 &message)
void copy_data(std::span< const uint8_t > data_from_peer)
static std::variant< Hello_Retry_Request, Server_Hello_13, Server_Hello_12 > parse(const std::vector< uint8_t > &buf)
size_t read_so_far() const
void update(std::span< const uint8_t > serialized_message_s)
as_wrapped_references_t< Handshake_Message_13 > Handshake_Message_13_Ref
std::variant< New_Session_Ticket_13, Key_Update > Post_Handshake_Message_13
constexpr GeneralVariantT generalize_to(SpecialT &&specific) noexcept
Converts a given variant into another variant-ish whose type states are a super set of the given vari...
constexpr uint8_t get_byte(T input)
constexpr auto concat(Rs &&... ranges)