Botan 3.6.1
Crypto and TLS for C&
|
#include <tpm2_context.h>
Public Member Functions | |
Context (const Context &)=delete | |
Context (Context &&ctx) noexcept=default | |
ESYS_CONTEXT * | esys_context () noexcept |
void | evict (std::unique_ptr< TPM2::PrivateKey > key, const SessionBundle &sessions) |
Evicts a persistent key from the TPM. The key cannot be used after. | |
std::optional< TPM2_HANDLE > | find_free_persistent_handle () const |
std::string | manufacturer () const |
size_t | max_random_bytes_per_request () const |
operator ESYS_CONTEXT * () noexcept | |
Context & | operator= (const Context &)=delete |
Context & | operator= (Context &&ctx) noexcept=default |
TPM2_HANDLE | persist (TPM2::PrivateKey &key, const SessionBundle &sessions, std::span< const uint8_t > auth_value={}, std::optional< TPM2_HANDLE > persistent_handle=std::nullopt) |
Makes key persistent at location persistent_handle or any free. | |
std::vector< TPM2_HANDLE > | persistent_handles () const |
std::unique_ptr< TPM2::PrivateKey > | storage_root_key (std::span< const uint8_t > auth_value, const SessionBundle &sessions) |
bool | supports_algorithm (std::string_view algo_name) const |
std::vector< ESYS_TR > | transient_handles () const |
void | use_botan_crypto_backend (const std::shared_ptr< Botan::RandomNumberGenerator > &rng) |
bool | uses_botan_crypto_backend () const noexcept |
std::string | vendor () const |
~Context () | |
Static Public Member Functions | |
static std::shared_ptr< Context > | create (const std::string &tcti_nameconf) |
static std::shared_ptr< Context > | create (std::optional< std::string > tcti={}, std::optional< std::string > conf={}) |
static bool | supports_botan_crypto_backend () noexcept |
Central class for interacting with a TPM2. Additional to managing the connection to the TPM, this provides authorative information about the TPM's capabilities. Also, it allows to persist and evict keys generated by the TPM.
Definition at line 39 of file tpm2_context.h.
|
defaultnoexcept |
Botan::TPM2::Context::~Context | ( | ) |
Definition at line 399 of file tpm2_context.cpp.
|
static |
tcti_nameconf | this is passed to Tss2_TctiLdr_Initialize verbatim |
Definition at line 53 of file tpm2_context.cpp.
References Context().
Referenced by botan_tpm2_ctx_init(), and botan_tpm2_ctx_init_ex().
|
static |
tcti | if set this is passed to Tss2_TctiLdr_Initialize_Ex verbatim otherwise a nullptr is passed. |
conf | if set this is passed to Tss2_TctiLdr_Initialize_Ex verbatim otherwise a nullptr is passed. |
Definition at line 58 of file tpm2_context.cpp.
References Context().
|
noexcept |
Definition at line 106 of file tpm2_context.cpp.
void Botan::TPM2::Context::evict | ( | std::unique_ptr< TPM2::PrivateKey > | key, |
const SessionBundle & | sessions ) |
Evicts a persistent key
from the TPM. The key cannot be used after.
Definition at line 373 of file tpm2_context.cpp.
References BOTAN_ARG_CHECK, BOTAN_ASSERT, BOTAN_ASSERT_NONNULL, and Botan::TPM2::check_rc().
std::optional< TPM2_HANDLE > Botan::TPM2::Context::find_free_persistent_handle | ( | ) | const |
Definition at line 288 of file tpm2_context.cpp.
References BOTAN_ASSERT_UNREACHABLE, persistent_handles(), and Botan::value_exists().
Referenced by persist().
std::string Botan::TPM2::Context::manufacturer | ( | ) | const |
Definition at line 207 of file tpm2_context.cpp.
References Botan::cast_uint8_ptr_to_char(), and Botan::store_be().
size_t Botan::TPM2::Context::max_random_bytes_per_request | ( | ) | const |
Definition at line 275 of file tpm2_context.cpp.
|
inlinenoexcept |
Definition at line 91 of file tpm2_context.h.
TPM2_HANDLE Botan::TPM2::Context::persist | ( | TPM2::PrivateKey & | key, |
const SessionBundle & | sessions, | ||
std::span< const uint8_t > | auth_value = {}, | ||
std::optional< TPM2_HANDLE > | persistent_handle = std::nullopt ) |
Makes key
persistent at location persistent_handle
or any free.
Definition at line 317 of file tpm2_context.cpp.
References BOTAN_ARG_CHECK, BOTAN_ASSERT_EQUAL, BOTAN_ASSERT_NOMSG, BOTAN_STATE_CHECK, Botan::TPM2::check_rc(), Botan::TPM2::copy_into(), find_free_persistent_handle(), Botan::TPM2::PrivateKey::handles(), Botan::TPM2::out_persistent_handle(), Botan::TPM2::out_transient_handle(), persistent_handles(), and Botan::value_exists().
std::vector< TPM2_HANDLE > Botan::TPM2::Context::persistent_handles | ( | ) | const |
Definition at line 312 of file tpm2_context.cpp.
Referenced by find_free_persistent_handle(), and persist().
std::unique_ptr< TPM2::PrivateKey > Botan::TPM2::Context::storage_root_key | ( | std::span< const uint8_t > | auth_value, |
const SessionBundle & | sessions ) |
Definition at line 279 of file tpm2_context.cpp.
References Botan::TPM2::PrivateKey::load_persistent().
bool Botan::TPM2::Context::supports_algorithm | ( | std::string_view | algo_name | ) | const |
The algo_name
can be any of the string algorithm specifiers used elsewhere. For example, "RSA", "AES-128", "SHA-1", "CTR(3DES)", etc.
Definition at line 213 of file tpm2_context.cpp.
References Botan::TPM2::asymmetric_algorithm_botan_to_tss2(), Botan::TPM2::block_cipher_botan_to_tss2(), Botan::TPM2::cipher_botan_to_tss2(), Botan::TPM2::cipher_mode_botan_to_tss2(), Botan::TPM2::hash_algo_botan_to_tss2(), Botan::TPM2::rsa_encryption_padding_botan_to_tss2(), Botan::TPM2::rsa_encryption_scheme_botan_to_tss2(), Botan::TPM2::rsa_signature_padding_botan_to_tss2(), and Botan::TPM2::rsa_signature_scheme_botan_to_tss2().
|
staticnoexcept |
Checks if the TSS2 supports registering Botan's crypto backend at runtime. Older versions of the TSS2 do not support this feature ( 4.0.0), also Botan may be compiled without support for TSS' crypto backend.
Definition at line 45 of file tpm2_context.cpp.
Referenced by botan_tpm2_supports_crypto_backend().
std::vector< ESYS_TR > Botan::TPM2::Context::transient_handles | ( | ) | const |
Definition at line 284 of file tpm2_context.cpp.
void Botan::TPM2::Context::use_botan_crypto_backend | ( | const std::shared_ptr< Botan::RandomNumberGenerator > & | rng | ) |
Overrides the TSS2's crypto callbacks with Botan's functionality.
This replaces all cryptographic functionality required for the communication with the TPM by botan's implementations. The TSS2 would otherwise use OpenSSL or mbedTLS.
Note that the provided rng
should not be dependent on the TPM.
rng | the RNG to use for the crypto operations |
Not_Implemented | if the TPM2-TSS does not support crypto callbacks |
Definition at line 80 of file tpm2_context.cpp.
References BOTAN_STATE_CHECK, BOTAN_UNUSED, Botan::TPM2::enable_crypto_callbacks(), and uses_botan_crypto_backend().
|
noexcept |
Definition at line 91 of file tpm2_context.cpp.
Referenced by use_botan_crypto_backend().
std::string Botan::TPM2::Context::vendor | ( | ) | const |
Definition at line 190 of file tpm2_context.cpp.
References Botan::BufferStuffer::append(), BOTAN_ASSERT_NOMSG, Botan::cast_uint8_ptr_to_char(), Botan::BufferStuffer::remaining_capacity(), and Botan::store_be().