Botan 3.9.0
Crypto and TLS for C&
tls_psk_identity_13.cpp
Go to the documentation of this file.
1/**
2 * Wrapper type for a TLS 1.3 session ticket
3 * (C) 2023 Jack Lloyd
4 * 2023 René Meusel - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#include <botan/tls_psk_identity_13.h>
10
11#include <botan/internal/mem_utils.h>
12
13namespace Botan::TLS {
14
15namespace {
16
17uint32_t obfuscate_ticket_age(const uint64_t in, const uint64_t ticket_age_add) {
18 // RFC 8446 4.2.11.1
19 // The "obfuscated_ticket_age" field of each PskIdentity contains an
20 // obfuscated version of the ticket age formed by taking the age in
21 // milliseconds and adding the "ticket_age_add" value that was included
22 // with the ticket, modulo 2^32.
23 return static_cast<uint32_t>(in + ticket_age_add);
24}
25
26inline std::vector<uint8_t> to_byte_vector(std::string_view s) {
27 return std::vector<uint8_t>(s.cbegin(), s.cend());
28}
29
30} // namespace
31
33 const std::chrono::milliseconds age,
34 const uint32_t ticket_age_add) :
35 PskIdentity(std::move(identity.get()), obfuscate_ticket_age(age.count(), ticket_age_add)) {}
36
38 m_identity(to_byte_vector(identity.get())),
39
40 // RFC 8446 4.2.11
41 // For identities established externally, an obfuscated_ticket_age of
42 // 0 SHOULD be used, and servers MUST ignore the value.
43 m_obfuscated_age(0) {}
44
45std::chrono::milliseconds PskIdentity::age(const uint32_t ticket_age_add) const {
46 return std::chrono::milliseconds(obfuscate_ticket_age(m_obfuscated_age, ticket_age_add));
47}
48
50 return bytes_to_string(m_identity);
51}
52
53} // namespace Botan::TLS
std::chrono::milliseconds age(uint32_t ticket_age_add) const
PskIdentity(std::vector< uint8_t > identity, const uint32_t obfuscated_age)
std::string identity_as_string() const
const std::vector< uint8_t > & identity() const
Strong< std::string, struct PresharedKeyID_ > PresharedKeyID
holds a PSK identity as used in TLS 1.3
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...
Definition tls_session.h:38
std::string bytes_to_string(std::span< const uint8_t > bytes)
Definition mem_utils.h:45