Botan 3.12.0
Crypto and TLS for C&
tls_external_psk.h
Go to the documentation of this file.
1/*
2 * TLS 1.3 Preshared Key Container
3 * (C) 2023 Jack Lloyd
4 * 2023 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_TLS_EXTERNAL_PSK_H_
10#define BOTAN_TLS_EXTERNAL_PSK_H_
11
12#include <botan/secmem.h>
13#include <string>
14#include <string_view>
15
16namespace Botan::TLS {
17
18/**
19 * This is an externally provided PreSharedKey along with its identity, master
20 * secret and (in case of TLS 1.3) a pre-provisioned Pseudo Random Function.
21 */
22class BOTAN_PUBLIC_API(3, 2) ExternalPSK final {
23 public:
24 ExternalPSK(const ExternalPSK&) = delete;
28 ~ExternalPSK() = default;
29
30 ExternalPSK(std::string_view identity, std::string_view prf_algo, secure_vector<uint8_t> psk) :
31 m_identity(identity), m_prf_algo(prf_algo), m_master_secret(std::move(psk)), m_is_imported(false) {}
32
33 ExternalPSK(std::string_view identity, std::string_view prf_algo, secure_vector<uint8_t> psk, bool imported) :
34 m_identity(identity), m_prf_algo(prf_algo), m_master_secret(std::move(psk)), m_is_imported(imported) {}
35
36 /**
37 * Identity (e.g. username of the PSK owner) of the preshared key.
38 * Despite the std::string return type, this may or may not be a
39 * human-readable/printable string.
40 */
41 const std::string& identity() const { return m_identity; }
42
43 /**
44 * Returns the master secret by moving it out of this object. Do not call
45 * this method more than once.
46 */
47 secure_vector<uint8_t> extract_master_secret();
48
49 /**
50 * External preshared keys in TLS 1.3 must be provisioned with a
51 * pseudo-random function (typically SHA-256 or the like). This is
52 * needed to calculate/verify the PSK binder values in the client hello.
53 */
54 const std::string& prf_algo() const { return m_prf_algo; }
55
56 /**
57 * Returns true if this PSK was derived using the PSK importer
58 * mechanism from RFC 9258. Imported PSKs use the "imp binder"
59 * label for binder computation instead of "ext binder".
60 */
61 bool is_imported() const { return m_is_imported; }
62
63 private:
64 std::string m_identity;
65 std::string m_prf_algo;
66 secure_vector<uint8_t> m_master_secret;
67 bool m_is_imported;
68};
69
70} // namespace Botan::TLS
71
72#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
ExternalPSK(const ExternalPSK &)=delete
const std::string & prf_algo() const
const std::string & identity() const
ExternalPSK(std::string_view identity, std::string_view prf_algo, secure_vector< uint8_t > psk)
ExternalPSK(ExternalPSK &&)=default
ExternalPSK & operator=(const ExternalPSK &)=delete
ExternalPSK(std::string_view identity, std::string_view prf_algo, secure_vector< uint8_t > psk, bool imported)
ExternalPSK & operator=(ExternalPSK &&)=default
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:68