Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Session Class Referencefinal

#include <tls_session.h>

Inheritance diagram for Botan::TLS::Session:
Botan::TLS::Session_Base

Public Member Functions

Ciphersuite ciphersuite () const
uint16_t ciphersuite_code () const
secure_vector< uint8_t > DER_encode () const
uint16_t dtls_srtp_profile () const
std::vector< uint8_t > encrypt (const SymmetricKey &key, RandomNumberGenerator &rng) const
secure_vector< uint8_t > extract_master_secret ()
std::chrono::seconds lifetime_hint () const
const secure_vector< uint8_t > & master_secret () const
uint32_t max_early_data_bytes () const
const std::vector< X509_Certificate > & peer_certs () const
std::optional< Certificate_Type > peer_credential_type () const
std::shared_ptr< const Public_Key > peer_raw_public_key () const
std::string PEM_encode () const
const Server_Information & server_info () const
 Session (const secure_vector< uint8_t > &master_secret, Protocol_Version version, uint16_t ciphersuite, Connection_Side side, bool supports_extended_master_secret, bool supports_encrypt_then_mac, const std::vector< X509_Certificate > &peer_certs, const Server_Information &server_info, uint16_t srtp_profile, std::chrono::system_clock::time_point current_timestamp, std::chrono::seconds lifetime_hint=std::chrono::seconds::max())
 Session (const secure_vector< uint8_t > &session_psk, const std::optional< uint32_t > &max_early_data_bytes, uint32_t ticket_age_add, std::chrono::seconds lifetime_hint, Protocol_Version version, uint16_t ciphersuite, Connection_Side side, const std::vector< X509_Certificate > &peer_certs, std::shared_ptr< const Public_Key > peer_raw_public_key, const Server_Information &server_info, std::chrono::system_clock::time_point current_timestamp)
BOTAN_FUTURE_EXPLICIT Session (std::span< const uint8_t > ber_data)
 Session (std::string_view pem)
uint32_t session_age_add () const
Connection_Side side () const
std::chrono::system_clock::time_point start_time () const
bool supports_early_data () const
bool supports_encrypt_then_mac () const
bool supports_extended_master_secret () const
Protocol_Version version () const

Static Public Member Functions

static Session decrypt (const uint8_t ctext[], size_t ctext_size, const SymmetricKey &key)
static Session decrypt (std::span< const uint8_t > ctext, const SymmetricKey &key)

Protected Attributes

uint16_t m_ciphersuite = 0
Connection_Side m_connection_side = Connection_Side::Client
bool m_encrypt_then_mac = false
bool m_extended_master_secret = false
std::vector< X509_Certificate > m_peer_certs
std::shared_ptr< const Public_Key > m_peer_raw_public_key
Server_Information m_server_info
uint16_t m_srtp_profile = 0
std::chrono::system_clock::time_point m_start_time
Protocol_Version m_version

Detailed Description

Represents a session's negotiated features along with all resumption information to re-establish a TLS connection later on.

Definition at line 254 of file tls_session.h.

Constructor & Destructor Documentation

◆ Session() [1/4]

Botan::TLS::Session::Session ( const secure_vector< uint8_t > & master_secret,
Protocol_Version version,
uint16_t ciphersuite,
Connection_Side side,
bool supports_extended_master_secret,
bool supports_encrypt_then_mac,
const std::vector< X509_Certificate > & peer_certs,
const Server_Information & server_info,
uint16_t srtp_profile,
std::chrono::system_clock::time_point current_timestamp,
std::chrono::seconds lifetime_hint = std::chrono::seconds::max() )

New TLS 1.2 session (sets session start time)

Definition at line 239 of file tls_session.cpp.

249 :
250 Session_Base(current_timestamp,
251 version,
253 side,
254 srtp_profile,
255 extended_master_secret,
256 encrypt_then_mac,
257 certs,
258 nullptr, // RFC 7250 (raw public keys) is NYI for TLS 1.2
260 m_master_secret(master_secret),
261 m_early_data_allowed(false),
262 m_max_early_data_bytes(0),
263 m_ticket_age_add(0),
264 m_lifetime_hint(lifetime_hint) {
265 BOTAN_ARG_CHECK(version.is_pre_tls_13(), "Instantiated a TLS 1.2 session object with a TLS version newer than 1.2");
266}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
Protocol_Version version() const
Definition tls_session.h:74
Connection_Side side() const
Definition tls_session.h:89
Ciphersuite ciphersuite() const
const Server_Information & server_info() const
std::chrono::seconds lifetime_hint() const
const secure_vector< uint8_t > & master_secret() const

References BOTAN_ARG_CHECK, Botan::TLS::Session_Base::ciphersuite(), lifetime_hint(), master_secret(), Botan::TLS::Session_Base::server_info(), Botan::TLS::Session_Base::Session_Base(), Botan::TLS::Session_Base::side(), and Botan::TLS::Session_Base::version().

Referenced by decrypt(), decrypt(), and Session().

◆ Session() [2/4]

Botan::TLS::Session::Session ( const secure_vector< uint8_t > & session_psk,
const std::optional< uint32_t > & max_early_data_bytes,
uint32_t ticket_age_add,
std::chrono::seconds lifetime_hint,
Protocol_Version version,
uint16_t ciphersuite,
Connection_Side side,
const std::vector< X509_Certificate > & peer_certs,
std::shared_ptr< const Public_Key > peer_raw_public_key,
const Server_Information & server_info,
std::chrono::system_clock::time_point current_timestamp )

New TLS 1.3 session (sets session start time)

Definition at line 270 of file tls_session.cpp.

280 :
281 Session_Base(current_timestamp,
282 version,
284 side,
285
286 // TODO: SRTP might become necessary when DTLS 1.3 is being implemented
287 0,
288
289 // RFC 8446 Appendix D
290 // Because TLS 1.3 always hashes in the transcript up to the server
291 // Finished, implementations which support both TLS 1.3 and earlier
292 // versions SHOULD indicate the use of the Extended Master Secret
293 // extension in their APIs whenever TLS 1.3 is used.
294 true,
295
296 // TLS 1.3 uses AEADs, so technically encrypt-then-MAC is not applicable.
297 false,
299 std::move(peer_raw_public_key),
301 m_master_secret(session_psk),
302 m_early_data_allowed(max_early_data_bytes.has_value()),
303 m_max_early_data_bytes(max_early_data_bytes.value_or(0)),
304 m_ticket_age_add(ticket_age_add),
305 m_lifetime_hint(lifetime_hint) {
306 BOTAN_ARG_CHECK(!version.is_pre_tls_13(), "Instantiated a TLS 1.3 session object with a TLS version older than 1.3");
307}
std::shared_ptr< const Public_Key > peer_raw_public_key() const
const std::vector< X509_Certificate > & peer_certs() const
uint32_t max_early_data_bytes() const

References BOTAN_ARG_CHECK, Botan::TLS::Session_Base::ciphersuite(), lifetime_hint(), max_early_data_bytes(), Botan::TLS::Session_Base::peer_certs(), Botan::TLS::Session_Base::peer_raw_public_key(), Botan::TLS::Session_Base::server_info(), Botan::TLS::Session_Base::Session_Base(), Botan::TLS::Session_Base::side(), and Botan::TLS::Session_Base::version().

◆ Session() [3/4]

Botan::TLS::Session::Session ( std::span< const uint8_t > ber_data)

Load a session from DER representation (created by DER_encode)

Parameters
ber_dataDER representation buffer

Definition at line 313 of file tls_session.cpp.

313 {
314 uint8_t side_code = 0;
315
316 std::vector<uint8_t> raw_pubkey_or_empty;
317
318 ASN1_String server_hostname;
319 ASN1_String server_service;
320 uint16_t server_port = 0;
321
322 uint8_t major_version = 0;
323 uint8_t minor_version = 0;
324
325 uint64_t start_time = 0;
326 uint16_t srtp_profile = 0;
327 uint16_t ciphersuite_code = 0;
328 uint64_t lifetime_hint = 0;
329
330 BER_Decoder(ber_data, BER_Decoder::Limits::DER())
331 .start_sequence()
332 .decode_and_check(TLS_SESSION_PARAM_STRUCT_VERSION, "Unknown version in serialized TLS session")
333 .decode_integer_type(start_time)
334 .decode_integer_type(major_version)
335 .decode_integer_type(minor_version)
336 .decode_integer_type(ciphersuite_code)
337 .decode_integer_type(side_code)
339 .decode(m_encrypt_then_mac)
340 .decode(m_master_secret, ASN1_Type::OctetString)
341 .decode_list<X509_Certificate>(m_peer_certs)
342 .decode(raw_pubkey_or_empty, ASN1_Type::OctetString)
343 .decode(server_hostname)
344 .decode(server_service)
345 .decode_integer_type(server_port)
346 .decode_integer_type(srtp_profile)
347 .decode(m_early_data_allowed)
348 .decode_integer_type(m_max_early_data_bytes)
349 .decode_integer_type(m_ticket_age_add)
350 .decode_integer_type(lifetime_hint)
351 .end_cons()
352 .verify_end();
353
355 throw Decoding_Error(
356 "Serialized TLS session contains unknown cipher suite "
357 "(" +
358 std::to_string(ciphersuite_code) + ")");
359 }
360
362 m_version = Protocol_Version(major_version, minor_version);
363 // A session for a version that is disabled in this build is still well formed
364 if(m_version != Protocol_Version::TLS_V12 && m_version != Protocol_Version::DTLS_V12 &&
365 m_version != Protocol_Version::TLS_V13) {
366 throw Decoding_Error("Serialized TLS session contains unknown protocol version " + m_version.to_string());
367 }
368
369 const auto max_seconds =
370 std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::time_point::max().time_since_epoch());
371
372 if(start_time > static_cast<uint64_t>(max_seconds.count())) {
373 throw Decoding_Error("Serialized TLS session contains an out of range start time");
374 }
375 m_start_time = std::chrono::system_clock::time_point(
376 std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::seconds(start_time)));
377 if(side_code != static_cast<uint8_t>(Connection_Side::Client) &&
378 side_code != static_cast<uint8_t>(Connection_Side::Server)) {
379 throw Decoding_Error("Serialized TLS session contains unknown connection side " + std::to_string(side_code));
380 }
381 m_connection_side = static_cast<Connection_Side>(side_code);
382
383 const bool valid_secret_size = m_version.is_pre_tls_13()
384 ? (m_master_secret.size() == 48)
385 : (m_master_secret.size() == 32 || m_master_secret.size() == 48);
386 if(!valid_secret_size) {
387 throw Decoding_Error("Serialized TLS session has master_secret of unexpected length");
388 }
389 m_srtp_profile = srtp_profile;
390
391 m_server_info = Server_Information(server_hostname.value(), server_service.value(), server_port);
392
393 if(!raw_pubkey_or_empty.empty()) {
394 m_peer_raw_public_key = X509::load_key(raw_pubkey_or_empty);
395 }
396
397 // RFC 9846 4.7.1
398 // Servers MUST NOT use any value greater than 604800 seconds (7 days).
399 //
400 // Any TLS 1.2 lifetime must still fit into std::chrono::seconds
401 const uint64_t max_lifetime =
402 m_version.is_pre_tls_13() ? static_cast<uint64_t>(std::chrono::seconds::max().count()) : 604800;
403 if(lifetime_hint > max_lifetime) {
404 throw Decoding_Error("Serialized TLS session contains an out of range lifetime");
405 }
406 m_lifetime_hint = std::chrono::seconds(lifetime_hint);
407}
static Limits DER()
Definition ber_dec.h:44
static std::optional< Ciphersuite > by_id(uint16_t suite)
std::vector< X509_Certificate > m_peer_certs
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
Definition tls_session.h:69
uint16_t ciphersuite_code() const
Definition tls_session.h:79
std::shared_ptr< const Public_Key > m_peer_raw_public_key
Connection_Side m_connection_side
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition pem.cpp:64
std::unique_ptr< Public_Key > load_key(DataSource &source)
Definition x509_key.cpp:28

References Botan::TLS::Ciphersuite::by_id(), Botan::TLS::Session_Base::ciphersuite_code(), Botan::TLS::Client, Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_and_check(), Botan::BER_Decoder::decode_integer_type(), Botan::BER_Decoder::decode_list(), Botan::BER_Decoder::Limits::DER(), lifetime_hint(), Botan::X509::load_key(), Botan::TLS::Session_Base::m_ciphersuite, Botan::TLS::Session_Base::m_connection_side, Botan::TLS::Session_Base::m_encrypt_then_mac, Botan::TLS::Session_Base::m_extended_master_secret, Botan::TLS::Session_Base::m_peer_certs, Botan::TLS::Session_Base::m_peer_raw_public_key, Botan::TLS::Session_Base::m_server_info, Botan::TLS::Session_Base::m_srtp_profile, Botan::TLS::Session_Base::m_start_time, Botan::TLS::Session_Base::m_version, Botan::OctetString, Botan::TLS::Server, Botan::BER_Decoder::start_sequence(), Botan::TLS::Session_Base::start_time(), and Botan::ASN1_String::value().

◆ Session() [4/4]

Botan::TLS::Session::Session ( std::string_view pem)
explicit

Load a session from PEM representation (created by PEM_encode)

Parameters
PEMPEM representation

Definition at line 311 of file tls_session.cpp.

311: Session(PEM_Code::decode_check_label(pem, "TLS SESSION")) {}
Session(const secure_vector< uint8_t > &master_secret, Protocol_Version version, uint16_t ciphersuite, Connection_Side side, bool supports_extended_master_secret, bool supports_encrypt_then_mac, const std::vector< X509_Certificate > &peer_certs, const Server_Information &server_info, uint16_t srtp_profile, std::chrono::system_clock::time_point current_timestamp, std::chrono::seconds lifetime_hint=std::chrono::seconds::max())
secure_vector< uint8_t > decode_check_label(DataSource &source, std::string_view label_want)
Definition pem.cpp:51

References Session().

Member Function Documentation

◆ ciphersuite()

Ciphersuite Botan::TLS::Session_Base::ciphersuite ( ) const
inherited

Get the ciphersuite info of the negotiated TLS session

Definition at line 123 of file tls_session.cpp.

123 {
124 auto suite = Ciphersuite::by_id(m_ciphersuite);
125 if(!suite.has_value()) {
126 throw Decoding_Error("Failed to find cipher suite for ID " + std::to_string(m_ciphersuite));
127 }
128 return suite.value();
129}

References Botan::TLS::Ciphersuite::by_id(), and m_ciphersuite.

Referenced by Botan::TLS::Session_Summary::cipher_algo(), Botan::TLS::Session_Summary::mac_algo(), Botan::TLS::Session_Summary::prf_algo(), Botan::TLS::Server_Hello_12::Server_Hello_12(), Botan::TLS::Session::Session(), Botan::TLS::Session::Session(), and Session_Base().

◆ ciphersuite_code()

uint16_t Botan::TLS::Session_Base::ciphersuite_code ( ) const
inlineinherited

Get the ciphersuite code of the negotiated TLS session

Definition at line 79 of file tls_session.h.

79{ return m_ciphersuite; }

References m_ciphersuite.

Referenced by Botan::TLS::Session::Session().

◆ decrypt() [1/2]

Session Botan::TLS::Session::decrypt ( const uint8_t ctext[],
size_t ctext_size,
const SymmetricKey & key )
inlinestatic

Decrypt a session created by encrypt

Parameters
ctextthe ciphertext returned by encrypt
ctext_sizethe size of ctext in bytes
keythe same key used by the encrypting side

Definition at line 320 of file tls_session.h.

320 {
321 return Session::decrypt(std::span(ctext, ctext_size), key);
322 }
static Session decrypt(const uint8_t ctext[], size_t ctext_size, const SymmetricKey &key)

References decrypt(), and Session().

Referenced by decrypt(), Botan::TLS::Session_Manager_SQL::find_some(), Botan::TLS::Session_Manager_SQL::retrieve_one(), and Botan::TLS::Session_Manager_Stateless::retrieve_one().

◆ decrypt() [2/2]

Session Botan::TLS::Session::decrypt ( std::span< const uint8_t > ctext,
const SymmetricKey & key )
static

Decrypt a session created by encrypt

Parameters
ctextthe ciphertext returned by encrypt
keythe same key used by the encrypting side

Definition at line 515 of file tls_session.cpp.

515 {
516 try {
517 const size_t min_session_size = 48 + 4; // serious under-estimate
518 if(in.size() < TLS_SESSION_CRYPT_OVERHEAD + min_session_size) {
519 throw Decoding_Error("Encrypted session too short to be valid");
520 }
521
522 BufferSlicer sub(in);
523 const auto* const magic = sub.take(TLS_SESSION_CRYPT_MAGIC_LEN).data();
524 const auto* const key_name = sub.take(TLS_SESSION_CRYPT_KEY_NAME_LEN).data();
525 const auto* const key_seed = sub.take(TLS_SESSION_CRYPT_AEAD_KEY_SEED_LEN).data();
526 const auto* const aead_nonce = sub.take(TLS_SESSION_CRYPT_AEAD_NONCE_LEN).data();
527 auto ctext = sub.copy_as_secure_vector(sub.remaining());
528
529 if(load_be<uint64_t>(magic, 0) != TLS_SESSION_CRYPT_MAGIC) {
530 throw Decoding_Error("Missing expected magic numbers");
531 }
532
533 auto hmac = MessageAuthenticationCode::create_or_throw(TLS_SESSION_CRYPT_HMAC);
534 hmac->set_key(key);
535
536 // First derive and check the "key name"
537 std::vector<uint8_t> cmp_key_name(hmac->output_length());
538 hmac->update(TLS_SESSION_CRYPT_KEY_NAME);
539 hmac->final(cmp_key_name.data());
540
541 if(CT::is_equal(cmp_key_name.data(), key_name, TLS_SESSION_CRYPT_KEY_NAME_LEN).as_bool() == false) {
542 throw Decoding_Error("Wrong key name for encrypted session");
543 }
544
545 hmac->update(key_seed, TLS_SESSION_CRYPT_AEAD_KEY_SEED_LEN);
546 const secure_vector<uint8_t> aead_key = hmac->final();
547
548 auto aead = AEAD_Mode::create_or_throw(TLS_SESSION_CRYPT_AEAD, Cipher_Dir::Decryption);
549 aead->set_key(aead_key);
550 aead->set_associated_data(in.data(), TLS_SESSION_CRYPT_HDR_LEN);
551 aead->start(aead_nonce, TLS_SESSION_CRYPT_AEAD_NONCE_LEN);
552 aead->finish(ctext, 0);
553 return Session(ctext);
554 } catch(std::exception& e) {
555 throw Decoding_Error("Failed to decrypt serialized TLS session: " + std::string(e.what()));
556 }
557}
static std::unique_ptr< AEAD_Mode > create_or_throw(std::string_view algo, Cipher_Dir direction, std::string_view provider="")
Definition aead.cpp:51
static std::unique_ptr< MessageAuthenticationCode > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:142
constexpr CT::Mask< T > is_equal(const T x[], const T y[], size_t len)
Definition ct_utils.h:803
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
constexpr auto load_be(ParamTs &&... params)
Definition loadstor.h:504

References Botan::BufferSlicer::copy_as_secure_vector(), Botan::AEAD_Mode::create_or_throw(), Botan::MessageAuthenticationCode::create_or_throw(), Botan::Decryption, Botan::CT::is_equal(), Botan::load_be(), Botan::BufferSlicer::remaining(), Session(), and Botan::BufferSlicer::take().

◆ DER_encode()

secure_vector< uint8_t > Botan::TLS::Session::DER_encode ( ) const

Encode this session data for storage

Warning
if the master secret is compromised so is the session traffic

Definition at line 409 of file tls_session.cpp.

409 {
410 const auto raw_pubkey_or_empty =
411 m_peer_raw_public_key ? m_peer_raw_public_key->subject_public_key() : std::vector<uint8_t>{};
412
413 return DER_Encoder()
414 .start_sequence()
415 .encode(TLS_SESSION_PARAM_STRUCT_VERSION)
416 .encode(static_cast<size_t>(std::chrono::system_clock::to_time_t(m_start_time)))
417 .encode(static_cast<size_t>(m_version.major_version()))
418 .encode(static_cast<size_t>(m_version.minor_version()))
419 .encode(static_cast<size_t>(m_ciphersuite))
420 .encode(static_cast<size_t>(m_connection_side))
422 .encode(m_encrypt_then_mac)
423 .encode(m_master_secret, ASN1_Type::OctetString)
424 .start_sequence()
425 .encode_list(m_peer_certs)
426 .end_cons()
427 .encode(raw_pubkey_or_empty, ASN1_Type::OctetString)
428 .encode(ASN1_String(m_server_info.hostname(), ASN1_Type::Utf8String))
429 .encode(ASN1_String(m_server_info.service(), ASN1_Type::Utf8String))
430 .encode(static_cast<size_t>(m_server_info.port()))
431 .encode(static_cast<size_t>(m_srtp_profile))
432
433 // the fields below were introduced for TLS 1.3 session tickets
434 .encode(m_early_data_allowed)
435 .encode(static_cast<size_t>(m_max_early_data_bytes))
436 .encode(static_cast<size_t>(m_ticket_age_add))
437 .encode(static_cast<size_t>(m_lifetime_hint.count()))
438 .end_cons()
439 .get_contents();
440}

References Botan::DER_Encoder::encode(), Botan::DER_Encoder::encode_list(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::TLS::Session_Base::m_ciphersuite, Botan::TLS::Session_Base::m_connection_side, Botan::TLS::Session_Base::m_encrypt_then_mac, Botan::TLS::Session_Base::m_extended_master_secret, Botan::TLS::Session_Base::m_peer_certs, Botan::TLS::Session_Base::m_peer_raw_public_key, Botan::TLS::Session_Base::m_server_info, Botan::TLS::Session_Base::m_srtp_profile, Botan::TLS::Session_Base::m_start_time, Botan::TLS::Session_Base::m_version, Botan::OctetString, Botan::DER_Encoder::start_sequence(), and Botan::Utf8String.

Referenced by encrypt(), and PEM_encode().

◆ dtls_srtp_profile()

uint16_t Botan::TLS::Session_Base::dtls_srtp_profile ( ) const
inlineinherited

Get the negotiated DTLS-SRTP algorithm (RFC 5764)

Definition at line 94 of file tls_session.h.

94{ return m_srtp_profile; }

References m_srtp_profile.

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), and Botan::TLS::Server_Hello_12::Server_Hello_12().

◆ encrypt()

std::vector< uint8_t > Botan::TLS::Session::encrypt ( const SymmetricKey & key,
RandomNumberGenerator & rng ) const

Encrypt a session (useful for serialization or session tickets)

Definition at line 472 of file tls_session.cpp.

472 {
473 auto hmac = MessageAuthenticationCode::create_or_throw(TLS_SESSION_CRYPT_HMAC);
474 hmac->set_key(key);
475
476 // First derive the "key name"
477 std::vector<uint8_t> key_name(hmac->output_length());
478 hmac->update(TLS_SESSION_CRYPT_KEY_NAME);
479 hmac->final(key_name.data());
480 key_name.resize(TLS_SESSION_CRYPT_KEY_NAME_LEN);
481
482 std::vector<uint8_t> aead_nonce;
483 std::vector<uint8_t> key_seed;
484
485 rng.random_vec(aead_nonce, TLS_SESSION_CRYPT_AEAD_NONCE_LEN);
486 rng.random_vec(key_seed, TLS_SESSION_CRYPT_AEAD_KEY_SEED_LEN);
487
488 hmac->update(key_seed);
489 const secure_vector<uint8_t> aead_key = hmac->final();
490
491 secure_vector<uint8_t> bits = this->DER_encode();
492
493 // create the header
494 std::vector<uint8_t> buf;
495 buf.reserve(TLS_SESSION_CRYPT_OVERHEAD + bits.size());
496 buf.resize(TLS_SESSION_CRYPT_MAGIC_LEN);
497 store_be(TLS_SESSION_CRYPT_MAGIC, &buf[0]); // NOLINT(*container-data-pointer)
498 buf += key_name;
499 buf += key_seed;
500 buf += aead_nonce;
501
502 auto aead = AEAD_Mode::create_or_throw(TLS_SESSION_CRYPT_AEAD, Cipher_Dir::Encryption);
503 BOTAN_ASSERT_NOMSG(aead->valid_nonce_length(TLS_SESSION_CRYPT_AEAD_NONCE_LEN));
504 BOTAN_ASSERT_NOMSG(aead->tag_size() == TLS_SESSION_CRYPT_AEAD_TAG_SIZE);
505 aead->set_key(aead_key);
506 aead->set_associated_data(buf);
507 aead->start(aead_nonce);
508 aead->finish(bits, 0);
509
510 // append the ciphertext
511 buf += bits;
512 return buf;
513}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
secure_vector< uint8_t > DER_encode() const
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

References BOTAN_ASSERT_NOMSG, Botan::AEAD_Mode::create_or_throw(), Botan::MessageAuthenticationCode::create_or_throw(), DER_encode(), Botan::Encryption, Botan::RandomNumberGenerator::random_vec(), and Botan::store_be().

Referenced by Botan::TLS::Session_Manager_Stateless::establish(), and Botan::TLS::Session_Manager_SQL::store().

◆ extract_master_secret()

secure_vector< uint8_t > Botan::TLS::Session::extract_master_secret ( )

Get the contained master secret as a moved-out object

Definition at line 446 of file tls_session.cpp.

446 {
447 BOTAN_STATE_CHECK(!m_master_secret.empty());
448 return std::exchange(m_master_secret, {});
449}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49

References BOTAN_STATE_CHECK.

◆ lifetime_hint()

std::chrono::seconds Botan::TLS::Session::lifetime_hint ( ) const
inline
Returns
the lifetime of the ticket as defined by the TLS server

Definition at line 366 of file tls_session.h.

366{ return m_lifetime_hint; }

Referenced by Session(), Session(), Session(), and Botan::TLS::Callbacks::tls_should_persist_resumption_information().

◆ master_secret()

const secure_vector< uint8_t > & Botan::TLS::Session::master_secret ( ) const
inline

Get a reference to the contained master secret

Definition at line 341 of file tls_session.h.

341{ return m_master_secret; }

Referenced by Session().

◆ max_early_data_bytes()

uint32_t Botan::TLS::Session::max_early_data_bytes ( ) const
inline

Return the number of bytes allowed for 0-RTT early data

Definition at line 361 of file tls_session.h.

361{ return m_max_early_data_bytes; }

Referenced by Session().

◆ peer_certs()

const std::vector< X509_Certificate > & Botan::TLS::Session_Base::peer_certs ( ) const
inlineinherited

Return the certificate chain of the peer (possibly empty)

Definition at line 111 of file tls_session.h.

111{ return m_peer_certs; }

References m_peer_certs.

Referenced by Botan::TLS::Session_Summary::Client_Impl_13, Botan::TLS::Session::Session(), and Session_Base().

◆ peer_credential_type()

std::optional< Certificate_Type > Botan::TLS::Session_Base::peer_credential_type ( ) const
inlineinherited

Return the type of credential used by the peer, or std::nullopt if the peer did not authenticate itself

Definition at line 122 of file tls_session.h.

122 {
123 if(!m_peer_certs.empty()) {
125 }
126
129 }
130
131 return std::nullopt;
132 }

References m_peer_certs, m_peer_raw_public_key, Botan::TLS::RawPublicKey, and Botan::TLS::X509.

◆ peer_raw_public_key()

std::shared_ptr< const Public_Key > Botan::TLS::Session_Base::peer_raw_public_key ( ) const
inlineinherited

Return the raw public key of the peer (possibly empty)

Definition at line 116 of file tls_session.h.

116{ return m_peer_raw_public_key; }

References m_peer_raw_public_key.

Referenced by Botan::TLS::Session_Summary::Client_Impl_13, Botan::TLS::Session::Session(), and Session_Base().

◆ PEM_encode()

std::string Botan::TLS::Session::PEM_encode ( ) const

Encode this session data for storage

Warning
if the master secret is compromised so is the session traffic

Definition at line 442 of file tls_session.cpp.

442 {
443 return PEM_Code::encode(this->DER_encode(), "TLS SESSION");
444}
std::string encode(const uint8_t der[], size_t length, std::string_view label, size_t width)
Definition pem.cpp:41

References DER_encode(), and Botan::PEM_Code::encode().

◆ server_info()

const Server_Information & Botan::TLS::Session_Base::server_info ( ) const
inlineinherited

Get information about the TLS server

Returns information that identifies the server side of the connection. This is useful for the client in that it identifies what was originally passed to the constructor. For the server, it includes the name the client specified in the server name indicator extension.

Definition at line 142 of file tls_session.h.

142{ return m_server_info; }

References m_server_info.

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), Botan::TLS::Session_Summary::Client_Impl_13, Botan::TLS::Session::Session(), Botan::TLS::Session::Session(), Session_Base(), and Botan::TLS::Session_Manager_SQL::store().

◆ session_age_add()

uint32_t Botan::TLS::Session::session_age_add ( ) const
inline

Return the ticket obfuscation adder

Definition at line 356 of file tls_session.h.

356{ return m_ticket_age_add; }

◆ side()

Connection_Side Botan::TLS::Session_Base::side ( ) const
inlineinherited

◆ start_time()

std::chrono::system_clock::time_point Botan::TLS::Session_Base::start_time ( ) const
inlineinherited

Get the wall clock time this session began

Definition at line 69 of file tls_session.h.

69{ return m_start_time; }

References m_start_time.

Referenced by Botan::TLS::Session_Manager_In_Memory::find_some(), Botan::TLS::Session::Session(), Session_Base(), and Botan::TLS::Session_Manager_SQL::store().

◆ supports_early_data()

bool Botan::TLS::Session::supports_early_data ( ) const
inline

Get whether the saved session supports sending/receiving of early data

Definition at line 351 of file tls_session.h.

351{ return m_early_data_allowed; }

◆ supports_encrypt_then_mac()

bool Botan::TLS::Session_Base::supports_encrypt_then_mac ( ) const
inlineinherited

Returns true if a TLS 1.2 session negotiated "encrypt then MAC"; TLS 1.3 sessions will always return false as they always use an AEAD.

Definition at line 100 of file tls_session.h.

100{ return m_encrypt_then_mac; }

References m_encrypt_then_mac.

Referenced by Botan::TLS::Client_Hello_12::Client_Hello_12(), and Botan::TLS::Server_Hello_12::Server_Hello_12().

◆ supports_extended_master_secret()

bool Botan::TLS::Session_Base::supports_extended_master_secret ( ) const
inlineinherited

Returns true if a TLS 1.2 session negotiated "extended master secret"; TLS 1.3 sessions will always return true (see RFC 8446 Appendix D).

Definition at line 106 of file tls_session.h.

106{ return m_extended_master_secret; }

References m_extended_master_secret.

◆ version()

Protocol_Version Botan::TLS::Session_Base::version ( ) const
inlineinherited

Member Data Documentation

◆ m_ciphersuite

uint16_t Botan::TLS::Session_Base::m_ciphersuite = 0
protectedinherited

◆ m_connection_side

Connection_Side Botan::TLS::Session_Base::m_connection_side = Connection_Side::Client
protectedinherited

◆ m_encrypt_then_mac

bool Botan::TLS::Session_Base::m_encrypt_then_mac = false
protectedinherited

◆ m_extended_master_secret

bool Botan::TLS::Session_Base::m_extended_master_secret = false
protectedinherited

◆ m_peer_certs

std::vector<X509_Certificate> Botan::TLS::Session_Base::m_peer_certs
protectedinherited

◆ m_peer_raw_public_key

std::shared_ptr<const Public_Key> Botan::TLS::Session_Base::m_peer_raw_public_key
protectedinherited

◆ m_server_info

Server_Information Botan::TLS::Session_Base::m_server_info
protectedinherited

◆ m_srtp_profile

uint16_t Botan::TLS::Session_Base::m_srtp_profile = 0
protectedinherited

◆ m_start_time

std::chrono::system_clock::time_point Botan::TLS::Session_Base::m_start_time
protectedinherited

◆ m_version

Protocol_Version Botan::TLS::Session_Base::m_version
protectedinherited

The documentation for this class was generated from the following files: