Botan 3.9.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
14#include <string>
15#include <string_view>
16
17namespace Botan::TLS {
18
19/**
20 * This is an externally provided PreSharedKey along with its identity, master
21 * secret and (in case of TLS 1.3) a pre-provisioned Pseudo Random Function.
22 */
24 public:
25 ExternalPSK(const ExternalPSK&) = delete;
29 ~ExternalPSK() = default;
30
31 ExternalPSK(std::string_view identity, std::string_view prf_algo, secure_vector<uint8_t> psk) :
32 m_identity(identity), m_prf_algo(prf_algo), m_master_secret(std::move(psk)) {}
33
34 /**
35 * Identity (e.g. username of the PSK owner) of the preshared key.
36 * Despite the std::string return type, this may or may not be a
37 * human-readable/printable string.
38 */
39 const std::string& identity() const { return m_identity; }
40
41 /**
42 * Returns the master secret by moving it out of this object. Do not call
43 * this method more than once.
44 */
45 secure_vector<uint8_t> extract_master_secret();
46
47 /**
48 * External preshared keys in TLS 1.3 must be provisioned with a
49 * pseudo-random function (typically SHA-256 or the like). This is
50 * needed to calculate/verify the PSK binder values in the client hello.
51 */
52 const std::string& prf_algo() const { return m_prf_algo; }
53
54 private:
55 std::string m_identity;
56 std::string m_prf_algo;
57 secure_vector<uint8_t> m_master_secret;
58};
59
60} // namespace Botan::TLS
61
62#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 & operator=(ExternalPSK &&)=default
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69