26 #include <boost/lexical_cast.hpp>
32 Tpm::Tpm(
const std::string& locator, unique_ptr<BackEnd> backEnd)
34 , m_backEnd(std::move(backEnd))
38 Tpm::~Tpm() =
default;
41 Tpm::hasKey(
const Name& keyName)
const
43 return m_backEnd->hasKey(keyName);
47 Tpm::createKey(
const Name& identityName,
const KeyParams& params)
49 auto keyHandle = m_backEnd->createKey(identityName, params);
50 auto keyName = keyHandle->getKeyName();
51 m_keys[keyName] = std::move(keyHandle);
56 Tpm::deleteKey(
const Name& keyName)
58 auto it = m_keys.find(keyName);
59 if (it != m_keys.end())
62 m_backEnd->deleteKey(keyName);
66 Tpm::getPublicKey(
const Name& keyName)
const
76 return key ? key->
sign(digestAlgorithm,
bufs) :
nullptr;
80 Tpm::verify(
const InputBuffers&
bufs, span<const uint8_t>
sig,
const Name& keyName,
85 return boost::logic::indeterminate;
91 Tpm::decrypt(span<const uint8_t> buf,
const Name& keyName)
const
94 return key ? key->
decrypt(buf) :
nullptr;
98 Tpm::isTerminalMode()
const
100 return m_backEnd->isTerminalMode();
104 Tpm::setTerminalMode(
bool isTerminal)
const
106 m_backEnd->setTerminalMode(isTerminal);
110 Tpm::isTpmLocked()
const
112 return m_backEnd->isTpmLocked();
116 Tpm::unlockTpm(
const char* password,
size_t passwordLength)
const
118 return m_backEnd->unlockTpm(password, passwordLength);
122 Tpm::exportPrivateKey(
const Name& keyName,
const char* pw,
size_t pwLen)
const
124 return m_backEnd->exportKey(keyName, pw, pwLen);
128 Tpm::importPrivateKey(
const Name& keyName, span<const uint8_t> pkcs8,
const char* pw,
size_t pwLen)
130 m_backEnd->importKey(keyName, pkcs8, pw, pwLen);
134 Tpm::importPrivateKey(
const Name& keyName, shared_ptr<transform::PrivateKey> key)
136 m_backEnd->importKey(keyName, std::move(key));
140 Tpm::findKey(
const Name& keyName)
const
142 auto it = m_keys.find(keyName);
143 if (it != m_keys.end())
144 return it->second.get();
146 auto handle = m_backEnd->getKeyHandle(keyName);
147 if (handle ==
nullptr)
150 const KeyHandle* key = handle.get();
151 m_keys[keyName] = std::move(handle);
Base class for key parameters.
Represents an absolute name.
Abstraction of TPM key handle.
ConstBufferPtr derivePublicKey() const
ConstBufferPtr decrypt(span< const uint8_t > cipherText) const
Return plain text content decrypted from cipherText using this key.
bool verify(DigestAlgorithm digestAlgorithm, const InputBuffers &bufs, span< const uint8_t > sig) const
Verify the signature sig over bufs using this key and digestAlgorithm.
ConstBufferPtr sign(DigestAlgorithm digestAlgorithm, const InputBuffers &bufs) const
Generate a digital signature for bufs using this key with digestAlgorithm.
shared_ptr< const Buffer > ConstBufferPtr
span< const uint8_t > sig