Botan 3.8.0
Crypto and TLS for C&
Botan::TPM_Context Class Referencefinal

#include <tpm.h>

Public Types

typedef std::function< std::string(std::string)> pin_cb
 

Public Member Functions

uint32_t current_counter ()
 
void gen_random (uint8_t out[], size_t out_len)
 
std::string get_user_pin (const std::string &who)
 
TSS_HCONTEXT handle () const
 
TSS_HKEY srk () const
 
void stir_random (const uint8_t in[], size_t in_len)
 
 TPM_Context (pin_cb cb, const char *srk_password)
 
 ~TPM_Context ()
 

Detailed Description

Creates a connection to the TPM. All other TPM types take and hold a TPM_Context reference, so all other objects must be deallocated before ~TPM_Context runs.

Use nullptr for the srk_password to indicate the well known secret (ie, an unencrypted SRK). This is usually what you want.

TODO: handling owner password?

Definition at line 43 of file tpm.h.

Member Typedef Documentation

◆ pin_cb

typedef std::function<std::string(std::string)> Botan::TPM_Context::pin_cb

User callback for getting the PIN. Will be passed the best available description of what we are attempting to load.

Definition at line 49 of file tpm.h.

Constructor & Destructor Documentation

◆ TPM_Context()

Botan::TPM_Context::TPM_Context ( pin_cb cb,
const char * srk_password )

Definition at line 137 of file tpm.cpp.

137 : m_pin_cb(cb), m_srk_policy(0) {
138 TSPI_CHECK_SUCCESS(::Tspi_Context_Create(&m_ctx));
139 TSPI_CHECK_SUCCESS(::Tspi_Context_Connect(m_ctx, nullptr));
140
141 TSPI_CHECK_SUCCESS(::Tspi_Context_GetTpmObject(m_ctx, &m_tpm));
142
143 const TSS_UUID SRK_UUID = TSS_UUID_SRK;
144
145 TSPI_CHECK_SUCCESS(::Tspi_Context_LoadKeyByUUID(m_ctx, TSS_PS_TYPE_SYSTEM, SRK_UUID, &m_srk));
146
147 TSPI_CHECK_SUCCESS(::Tspi_GetPolicyObject(m_srk, TSS_POLICY_USAGE, &m_srk_policy));
148 set_policy_secret(m_srk_policy, srk_password);
149
150 // TODO: do we have to cache it?
151 // TODO: try to use SRK with null, if it fails call the pin cb?
152}
#define TSPI_CHECK_SUCCESS(expr)
Definition tpm.cpp:67

References TSPI_CHECK_SUCCESS.

◆ ~TPM_Context()

Botan::TPM_Context::~TPM_Context ( )

Definition at line 154 of file tpm.cpp.

154 {
155 TSPI_CHECK_SUCCESS(::Tspi_Context_CloseObject(m_ctx, m_srk));
156 //TSPI_CHECK_SUCCESS(::Tspi_Context_CloseObject(m_ctx, m_tpm));
157 TSPI_CHECK_SUCCESS(::Tspi_Context_Close(m_srk_policy));
158 TSPI_CHECK_SUCCESS(::Tspi_Context_Close(m_ctx));
159}

References TSPI_CHECK_SUCCESS.

Member Function Documentation

◆ current_counter()

uint32_t Botan::TPM_Context::current_counter ( )

Definition at line 161 of file tpm.cpp.

161 {
162 uint32_t r = 0;
163 TSPI_CHECK_SUCCESS(::Tspi_TPM_ReadCounter(m_tpm, &r));
164 return r;
165}

References TSPI_CHECK_SUCCESS.

◆ gen_random()

void Botan::TPM_Context::gen_random ( uint8_t out[],
size_t out_len )

Definition at line 167 of file tpm.cpp.

167 {
168 BYTE* mem;
169 TSPI_CHECK_SUCCESS(::Tspi_TPM_GetRandom(m_tpm, to_uint32(out_len), &mem));
170 copy_mem(out, reinterpret_cast<const uint8_t*>(mem), out_len);
171 TSPI_CHECK_SUCCESS(::Tspi_Context_FreeMemory(m_ctx, mem));
172}
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:149

References Botan::copy_mem(), and TSPI_CHECK_SUCCESS.

◆ get_user_pin()

std::string Botan::TPM_Context::get_user_pin ( const std::string & who)
inline

Definition at line 61 of file tpm.h.

61{ return m_pin_cb(who); }

References get_user_pin().

Referenced by get_user_pin().

◆ handle()

TSS_HCONTEXT Botan::TPM_Context::handle ( ) const
inline

Definition at line 65 of file tpm.h.

65{ return m_ctx; }

◆ srk()

TSS_HKEY Botan::TPM_Context::srk ( ) const
inline

Definition at line 67 of file tpm.h.

67{ return m_srk; }

◆ stir_random()

void Botan::TPM_Context::stir_random ( const uint8_t in[],
size_t in_len )

Definition at line 174 of file tpm.cpp.

174 {
175 TSPI_CHECK_SUCCESS(::Tspi_TPM_StirRandom(m_tpm, to_uint32(in_len), const_cast<BYTE*>(in)));
176}

References TSPI_CHECK_SUCCESS.


The documentation for this class was generated from the following files: