Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | List of all members
Botan::TPM_Context Class Reference

`#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 39 of file tpm.h.

## Member Typedef Documentation

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 46 of file tpm.h.

## Constructor & Destructor Documentation

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

Definition at line 156 of file tpm.cpp.

References TSPI_CHECK_SUCCESS.

156 : m_pin_cb(cb)
157 {
158 TSPI_CHECK_SUCCESS(::Tspi_Context_Create(&m_ctx));
159 TSPI_CHECK_SUCCESS(::Tspi_Context_Connect(m_ctx, nullptr));
160
161 TSPI_CHECK_SUCCESS(::Tspi_Context_GetTpmObject(m_ctx, &m_tpm));
162
163 const TSS_UUID SRK_UUID = TSS_UUID_SRK;
164
165 TSPI_CHECK_SUCCESS(::Tspi_Context_LoadKeyByUUID(m_ctx, TSS_PS_TYPE_SYSTEM, SRK_UUID, &m_srk));
166
167 TSS_HPOLICY srk_policy;
168 TSPI_CHECK_SUCCESS(::Tspi_GetPolicyObject(m_srk, TSS_POLICY_USAGE, &srk_policy));
169 set_policy_secret(srk_policy, srk_password);
170
171 // TODO: leaking policy object here?
172 // TODO: do we have to cache it?
173 // TODO: try to use SRK with null, if it fails call the pin cb?
174 }
TSPI_CHECK_SUCCESS
#define TSPI_CHECK_SUCCESS(expr)
Definition: tpm.cpp:68

Botan::TPM_Context::~TPM_Context | ( |  | ) |

Definition at line 176 of file tpm.cpp.

References TSPI_CHECK_SUCCESS.

177 {
178 TSPI_CHECK_SUCCESS(::Tspi_Context_CloseObject(m_ctx, m_srk));
179 //TSPI_CHECK_SUCCESS(::Tspi_Context_CloseObject(m_ctx, m_tpm));
180 TSPI_CHECK_SUCCESS(::Tspi_Context_Close(m_ctx));
181 }
TSPI_CHECK_SUCCESS
#define TSPI_CHECK_SUCCESS(expr)
Definition: tpm.cpp:68

## Member Function Documentation

uint32_t Botan::TPM_Context::current_counter | ( |  | ) |

Definition at line 183 of file tpm.cpp.

References TSPI_CHECK_SUCCESS.

184 {
185 uint32_t r = 0;
186 TSPI_CHECK_SUCCESS(::Tspi_TPM_ReadCounter(m_tpm, &r));
187 return r;
188 }
TSPI_CHECK_SUCCESS
#define TSPI_CHECK_SUCCESS(expr)
Definition: tpm.cpp:68

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

Definition at line 190 of file tpm.cpp.

References TSPI_CHECK_SUCCESS.

191 {
192 BYTE* mem;
193 TSPI_CHECK_SUCCESS(::Tspi_TPM_GetRandom(m_tpm, out_len, &mem));
194 std::memcpy(out, mem, out_len);
195 TSPI_CHECK_SUCCESS(::Tspi_Context_FreeMemory(m_ctx, mem));
196 }
TSPI_CHECK_SUCCESS
#define TSPI_CHECK_SUCCESS(expr)
Definition: tpm.cpp:68

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

Definition at line 58 of file tpm.h.

59 {
60 return m_pin_cb(who);
61 }

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

Definition at line 65 of file tpm.h.

Referenced by Botan::TPM_PrivateKey::export_blob(), Botan::TPM_PrivateKey::register_key(), Botan::TPM_PrivateKey::registered_keys(), and Botan::TPM_PrivateKey::TPM_PrivateKey().

65 { return m_ctx; }

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

Definition at line 66 of file tpm.h.

Referenced by Botan::TPM_PrivateKey::TPM_PrivateKey().

66 { return m_srk; }

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

Definition at line 198 of file tpm.cpp.

References TSPI_CHECK_SUCCESS.

199 {
200 TSPI_CHECK_SUCCESS(::Tspi_TPM_StirRandom(m_tpm, in_len, const_cast<BYTE*>(in)));
201 }
TSPI_CHECK_SUCCESS
#define TSPI_CHECK_SUCCESS(expr)
Definition: tpm.cpp:68

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

- src/lib/prov/tpm/tpm.h
- src/lib/prov/tpm/tpm.cpp