26 #include <boost/lexical_cast.hpp>
30 Tpm::Tpm(
const std::string& locator, unique_ptr<BackEnd> backEnd)
32 , m_backEnd(std::move(backEnd))
36 Tpm::~Tpm() =
default;
39 Tpm::hasKey(
const Name& keyName)
const
41 return m_backEnd->hasKey(keyName);
45 Tpm::createKey(
const Name& identityName,
const KeyParams& params)
47 auto keyHandle = m_backEnd->createKey(identityName, params);
48 auto keyName = keyHandle->getKeyName();
49 m_keys[keyName] = std::move(keyHandle);
54 Tpm::deleteKey(
const Name& keyName)
56 if (
auto it = m_keys.find(keyName); it != m_keys.end())
59 m_backEnd->deleteKey(keyName);
63 Tpm::getPublicKey(
const Name& keyName)
const
73 return key ? key->
sign(digestAlgorithm,
bufs) :
nullptr;
77 Tpm::verify(
const InputBuffers&
bufs, span<const uint8_t>
sig,
const Name& keyName,
82 return boost::logic::indeterminate;
88 Tpm::decrypt(span<const uint8_t> buf,
const Name& keyName)
const
91 return key ? key->
decrypt(buf) :
nullptr;
94 #pragma GCC diagnostic push
95 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
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);
121 #pragma GCC diagnostic pop
124 Tpm::exportPrivateKey(
const Name& keyName,
const char* pw,
size_t pwLen)
const
126 return m_backEnd->exportKey(keyName, pw, pwLen);
130 Tpm::importPrivateKey(
const Name& keyName, span<const uint8_t> pkcs8,
const char* pw,
size_t pwLen)
132 m_backEnd->importKey(keyName, pkcs8, pw, pwLen);
136 Tpm::importPrivateKey(
const Name& keyName, shared_ptr<transform::PrivateKey> key)
138 m_backEnd->importKey(keyName, std::move(key));
142 Tpm::findKey(
const Name& keyName)
const
144 if (
auto it = m_keys.find(keyName); it != m_keys.end())
145 return it->second.get();
147 auto handle = m_backEnd->getKeyHandle(keyName);
148 if (handle ==
nullptr)
151 const KeyHandle* key = handle.get();
152 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.
std::shared_ptr< const Buffer > ConstBufferPtr
span< const uint8_t > sig