Botan 3.6.1
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/stl_util.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
26} // namespace
27
29 const std::chrono::milliseconds age,
30 const uint32_t ticket_age_add) :
31 PskIdentity(std::move(identity.get()), obfuscate_ticket_age(age.count(), ticket_age_add)) {}
32
34 m_identity(to_byte_vector(identity.get())),
35
36 // RFC 8446 4.2.11
37 // For identities established externally, an obfuscated_ticket_age of
38 // 0 SHOULD be used, and servers MUST ignore the value.
39 m_obfuscated_age(0) {}
40
41std::chrono::milliseconds PskIdentity::age(const uint32_t ticket_age_add) const {
42 return std::chrono::milliseconds(obfuscate_ticket_age(m_obfuscated_age, ticket_age_add));
43}
44
46 return Botan::to_string(m_identity);
47}
48
49} // 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
T to_byte_vector(std::string_view s)
Definition stl_util.h:29
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13