8#include <botan/tls_messages.h>
11#include <botan/tls_callbacks.h>
12#include <botan/tls_session.h>
13#include <botan/tls_session_manager.h>
14#include <botan/internal/loadstor.h>
15#include <botan/internal/tls_handshake_hash.h>
16#include <botan/internal/tls_handshake_io.h>
17#include <botan/internal/tls_reader.h>
19#include <botan/tls_exceptn.h>
28 std::chrono::seconds lifetime) :
29 m_ticket_lifetime_hint(lifetime), m_ticket(std::move(ticket)) {
39 throw Decoding_Error(
"Session ticket message too short to be valid");
44 m_ticket_lifetime_hint = std::chrono::seconds(reader.
get_uint32_t());
51template <
typename lifetime_t = u
int32_t>
52void store_lifetime(std::span<uint8_t> sink, std::chrono::seconds lifetime) {
53 BOTAN_ARG_CHECK(lifetime.count() >= 0 && lifetime.count() <= std::numeric_limits<lifetime_t>::max(),
54 "Ticket lifetime is out of range");
55 store_be(
static_cast<lifetime_t
>(lifetime.count()), sink.data());
61 std::vector<uint8_t> buf(4);
62 store_be(
static_cast<uint32_t
>(m_ticket_lifetime_hint.count()), buf.data());
67#if defined(BOTAN_HAS_TLS_13)
73 m_ticket_lifetime_hint(session.lifetime_hint()),
74 m_ticket_age_add(session.session_age_add()),
75 m_ticket_nonce(std::move(nonce)),
76 m_handle(handle.opaque_handle()) {
83 m_ticket_lifetime_hint = std::chrono::seconds(reader.
get_uint32_t());
88 if(m_ticket_lifetime_hint > std::chrono::days(7)) {
89 throw TLS_Exception(Alert::IllegalParameter,
"Received a session ticket with lifetime longer than one week.");
103 throw TLS_Exception(Alert::IllegalParameter,
"NewSessionTicket message contained unexpected extension");
120 std::vector<uint8_t> result(8);
122 store_lifetime(std::span(result.data(), 4), m_ticket_lifetime_hint);
123 store_be(m_ticket_age_add, result.data() + 4);
128 if(m_extensions.
empty()) {
129 result.push_back(0x00);
130 result.push_back(0x00);
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_ARG_CHECK(expr, msg)
virtual void tls_modify_extensions(Extensions &extn, Connection_Side which_side, Handshake_Type which_message)
std::optional< uint32_t > max_early_data_size() const
bool contains_implemented_extensions_other_than(const std::set< Extension_Code > &allowed_extensions) const
std::vector< uint8_t > serialize(Connection_Side whoami) const
void deserialize(TLS_Data_Reader &reader, Connection_Side from, Handshake_Type message_type)
void update(const uint8_t in[], size_t length)
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
std::vector< uint8_t > serialize() const override
New_Session_Ticket_12(Handshake_IO &io, Handshake_Hash &hash, Session_Ticket ticket, std::chrono::seconds lifetime)
Handshake_Type type() const override
std::optional< uint32_t > early_data_byte_limit() const
New_Session_Ticket_13(Ticket_Nonce nonce, const Session &session, const Session_Handle &handle, Callbacks &callbacks)
std::vector< uint8_t > serialize() const override
Helper class to embody a session handle in all protocol versions.
std::vector< T > get_range(size_t len_bytes, size_t min_elems, size_t max_elems)
std::vector< uint8_t > get_tls_length_value(size_t len_bytes)
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Strong< std::vector< uint8_t >, struct Ticket_Nonce_ > Ticket_Nonce
Used to derive the ticket's PSK from the resumption_master_secret.
Strong< std::vector< uint8_t >, struct Session_Ticket_ > Session_Ticket
holds a TLS 1.2 session ticket for stateless resumption
Strong< std::vector< uint8_t >, struct Opaque_Session_Handle_ > Opaque_Session_Handle
holds an opaque session handle as used in TLS 1.3 that could be either a ticket for stateless resumpt...
constexpr auto store_be(ParamTs &&... params)