26 #include <boost/lexical_cast.hpp> 32 Tpm::Tpm(
const std::string& scheme,
const std::string& location, unique_ptr<BackEnd> backEnd)
34 , m_location(location)
44 return m_scheme +
":" + m_location;
50 return m_backEnd->hasKey(keyName);
54 Tpm::createKey(
const Name& identityName,
const KeyParams& params)
56 auto keyHandle = m_backEnd->createKey(identityName, params);
57 auto keyName = keyHandle->getKeyName();
63 Tpm::deleteKey(
const Name& keyName)
65 auto it = m_keys.find(keyName);
66 if (it != m_keys.end())
69 m_backEnd->deleteKey(keyName);
91 return key->
sign(digestAlgorithm, buf, size);
101 return boost::logic::indeterminate;
103 return key->
verify(digestAlgorithm, buf, bufLen, sig, sigLen);
114 return key->
decrypt(buf, size);
120 return m_backEnd->isTerminalMode();
126 m_backEnd->setTerminalMode(isTerminal);
132 return m_backEnd->isTpmLocked();
138 return m_backEnd->unlockTpm(password, passwordLength);
142 Tpm::exportPrivateKey(
const Name& keyName,
const char* pw,
size_t pwLen)
const 144 return m_backEnd->exportKey(keyName, pw, pwLen);
148 Tpm::importPrivateKey(
const Name& keyName,
const uint8_t* pkcs8,
size_t pkcs8Len,
149 const char* pw,
size_t pwLen)
151 m_backEnd->importKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
155 Tpm::importPrivateKey(
const Name& keyName, shared_ptr<transform::PrivateKey> key)
157 m_backEnd->importKey(keyName,
std::move(key));
161 Tpm::findKey(
const Name& keyName)
const 163 auto it = m_keys.find(keyName);
164 if (it != m_keys.end())
165 return it->second.get();
167 auto handle = m_backEnd->getKeyHandle(keyName);
168 if (handle ==
nullptr)
ConstBufferPtr sign(const uint8_t *buf, size_t size, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Sign blob using the key with name keyName and using the digest digestAlgorithm.
ConstBufferPtr sign(DigestAlgorithm digestAlgorithm, const uint8_t *buf, size_t size) const
ConstBufferPtr derivePublicKey() const
ConstBufferPtr decrypt(const uint8_t *cipherText, size_t cipherTextLen) const
bool hasKey(const Name &keyName) const
Check if a private key exists.
Abstraction of TPM key handle.
ConstBufferPtr getPublicKey(const Name &keyName) const
boost::logic::tribool verify(const uint8_t *buf, size_t bufLen, const uint8_t *sig, size_t sigLen, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Verify blob using the key with name keyName and using the digest digestAlgorithm. ...
bool unlockTpm(const char *password, size_t passwordLength) const
Unlock the TPM.
void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
Represents an absolute name.
std::string getTpmLocator() const
bool verify(DigestAlgorithm digestAlgorithm, const uint8_t *buf, size_t bufLen, const uint8_t *sig, size_t sigLen) const
Verify the signature sig created on buf using this key and digestAlgorithm.
Base class for key parameters.
ConstBufferPtr decrypt(const uint8_t *buf, size_t size, const Name &keyName) const
Decrypt blob using the key with name keyName.
bool isTerminalMode() const
Check if the TPM is in terminal mode.
shared_ptr< const Buffer > ConstBufferPtr