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)
59 unique_ptr<KeyHandle> keyHandle = m_backEnd->createKey(identityName, params);
60 Name keyName = keyHandle->getKeyName();
65 NDN_THROW(
Error(
"Failed to create key pair: Unsupported key type " +
66 boost::lexical_cast<std::string>(params.
getKeyType())));
72 Tpm::deleteKey(
const Name& keyName)
74 auto it = m_keys.find(keyName);
75 if (it != m_keys.end())
78 m_backEnd->deleteKey(keyName);
100 return key->
sign(digestAlgorithm, buf, size);
111 return key->
decrypt(buf, size);
117 return m_backEnd->isTerminalMode();
123 m_backEnd->setTerminalMode(isTerminal);
129 return m_backEnd->isTpmLocked();
135 return m_backEnd->unlockTpm(password, passwordLength);
139 Tpm::exportPrivateKey(
const Name& keyName,
const char* pw,
size_t pwLen)
const 141 return m_backEnd->exportKey(keyName, pw, pwLen);
145 Tpm::importPrivateKey(
const Name& keyName,
const uint8_t* pkcs8,
size_t pkcs8Len,
146 const char* pw,
size_t pwLen)
148 m_backEnd->importKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
152 Tpm::findKey(
const Name& keyName)
const 154 auto it = m_keys.find(keyName);
155 if (it != m_keys.end())
156 return it->second.get();
158 auto handle = m_backEnd->getKeyHandle(keyName);
159 if (handle ==
nullptr)
std::string getTpmLocator() const
ConstBufferPtr derivePublicKey() const
KeyType getKeyType() const
ConstBufferPtr sign(DigestAlgorithm digestAlgorithm, const uint8_t *buf, size_t size) const
RSA key, supports sign/verify and encrypt/decrypt operations.
Abstraction of TPM key handle.
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.
bool isTerminalMode() const
Check if the TPM is in terminal mode.
bool hasKey(const Name &keyName) const
Check if a private key exists.
bool unlockTpm(const char *password, size_t passwordLength) const
Unlock the TPM.
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
Represents an absolute name.
ConstBufferPtr getPublicKey(const Name &keyName) const
void setTerminalMode(bool isTerminal) const
Set the terminal mode of the TPM.
ConstBufferPtr decrypt(const uint8_t *buf, size_t size, const Name &keyName) const
Decrypt blob using the key with name keyName.
Base class of key parameters.
ConstBufferPtr decrypt(const uint8_t *cipherText, size_t cipherTextLen) const
shared_ptr< const Buffer > ConstBufferPtr