9#ifndef BOTAN_TLS_SESSION_STATE_H_
10#define BOTAN_TLS_SESSION_STATE_H_
12#include <botan/x509cert.h>
13#include <botan/tls_version.h>
14#include <botan/tls_ciphersuite.h>
15#include <botan/tls_magic.h>
16#include <botan/tls_server_info.h>
17#include <botan/secmem.h>
18#include <botan/strong_type.h>
19#include <botan/symkey.h>
48 return std::lexicographical_compare(id1.begin(), id1.end(),
49 id2.begin(), id2.end());
76 { validate_constraints(); }
88 { validate_constraints(); }
97 { validate_constraints(); }
99 bool is_id()
const {
return std::holds_alternative<Session_ID>(m_handle); }
100 bool is_ticket()
const {
return std::holds_alternative<Session_Ticket>(m_handle); }
101 bool is_opaque_handle()
const {
return std::holds_alternative<Opaque_Session_Handle>(m_handle); }
116 std::optional<Session_ID> id()
const;
123 std::optional<Session_Ticket> ticket()
const;
125 decltype(
auto)
get()
const {
return m_handle; }
128 void validate_constraints()
const;
131 std::variant<Session_ID, Session_Ticket, Opaque_Session_Handle> m_handle;
134class Client_Hello_13;
135class Server_Hello_13;
148 uint16_t ciphersuite,
150 uint16_t srtp_profile,
151 bool extended_master_secret,
152 bool encrypt_then_mac,
153 std::vector<X509_Certificate> peer_certs,
155 : m_start_time(start_time)
157 , m_ciphersuite(ciphersuite)
158 , m_connection_side(connection_side)
159 , m_srtp_profile(srtp_profile)
160 , m_extended_master_secret(extended_master_secret)
161 , m_encrypt_then_mac(encrypt_then_mac)
162 , m_peer_certs(
std::move(peer_certs))
163 , m_server_info(
std::move(server_info)) {}
172 std::chrono::system_clock::time_point
start_time()
const {
return m_start_time; }
214 const std::vector<X509_Certificate>&
peer_certs()
const {
return m_peer_certs; }
256 const std::optional<Session_Ticket>&
session_ticket()
const {
return m_session_ticket; }
260 std::string
kex_algo()
const {
return m_kex_algo; }
261 std::string
cipher_algo()
const {
return ciphersuite().cipher_algo(); }
262 std::string
mac_algo()
const {
return ciphersuite().mac_algo(); }
263 std::string
prf_algo()
const {
return ciphersuite().prf_algo(); }
273#if defined(BOTAN_HAS_TLS_13)
276 std::vector<X509_Certificate> peer_certs,
278 std::chrono::system_clock::time_point current_timestamp);
281 void set_session_id(
Session_ID id) { m_session_id = std::move(
id); }
282 void set_session_ticket(
Session_Ticket ticket) { m_session_ticket = std::move(ticket); }
285 Session_ID m_session_id;
286 std::optional<Session_Ticket> m_session_ticket;
289 bool m_was_resumption;
290 std::string m_kex_algo;
306 uint16_t ciphersuite,
308 bool supports_extended_master_secret,
309 bool supports_encrypt_then_mac,
310 const std::vector<X509_Certificate>& peer_certs,
312 uint16_t srtp_profile,
313 std::chrono::system_clock::time_point current_timestamp,
314 std::chrono::seconds lifetime_hint = std::chrono::seconds::max());
316#if defined(BOTAN_HAS_TLS_13)
322 const std::optional<uint32_t>& max_early_data_bytes,
323 uint32_t ticket_age_add,
324 std::chrono::seconds lifetime_hint,
326 uint16_t ciphersuite,
328 const std::vector<X509_Certificate>& peer_certs,
330 std::chrono::system_clock::time_point current_timestamp);
337 const std::optional<uint32_t>& max_early_data_bytes,
338 std::chrono::seconds lifetime_hint,
339 const std::vector<X509_Certificate>& peer_certs,
340 const Client_Hello_13& client_hello,
341 const Server_Hello_13& server_hello,
351 Session(std::span<const uint8_t> ber_data);
357 explicit Session(std::string_view pem);
381 {
return Session::decrypt(std::span(ctext, ctext_size), key); }
395 std::string PEM_encode()
const;
446 TLS_SESSION_PARAM_STRUCT_VERSION = 20230222
451 bool m_early_data_allowed;
452 uint32_t m_max_early_data_bytes;
453 uint32_t m_ticket_age_add;
454 std::chrono::seconds m_lifetime_hint;
std::vector< X509_Certificate > m_peer_certs
bool m_extended_master_secret
uint16_t dtls_srtp_profile() const
Protocol_Version version() const
Connection_Side side() const
bool supports_encrypt_then_mac() const
Protocol_Version m_version
std::chrono::system_clock::time_point m_start_time
Server_Information m_server_info
std::chrono::system_clock::time_point start_time() const
uint16_t ciphersuite_code() const
bool supports_extended_master_secret() const
Session_Base(std::chrono::system_clock::time_point start_time, Protocol_Version version, uint16_t ciphersuite, Connection_Side connection_side, uint16_t srtp_profile, bool extended_master_secret, bool encrypt_then_mac, std::vector< X509_Certificate > peer_certs, Server_Information server_info)
const std::vector< X509_Certificate > & peer_certs() const
const Server_Information & server_info() const
Connection_Side m_connection_side
Helper class to embody a session handle in all protocol versions.
decltype(auto) get() const
Session_Handle(Session_Ticket ticket)
bool is_opaque_handle() const
Session_Handle(Session_ID id)
Session_Handle(Opaque_Session_Handle ticket)
std::string cipher_algo() const
std::string mac_algo() const
bool was_resumption() const
std::string kex_algo() const
const std::optional< Session_Ticket > & session_ticket() const
const Session_ID & session_id() const
std::string prf_algo() const
std::chrono::seconds lifetime_hint() const
static Session decrypt(const uint8_t ctext[], size_t ctext_size, const SymmetricKey &key)
bool supports_early_data() const
uint32_t session_age_add() const
const secure_vector< uint8_t > & master_secret() const
uint32_t max_early_data_bytes() const
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
bool operator<(const Server_Information &a, const Server_Information &b)
std::vector< T, secure_allocator< T > > secure_vector