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);
56 auto keyHandle = m_backEnd->createKey(identityName, params);
57 auto keyName = keyHandle->getKeyName();
65 auto it = m_keys.find(keyName);
66 if (it != m_keys.end())
69 m_backEnd->deleteKey(keyName);
83 return key ? key->
sign(digestAlgorithm, bufs) :
nullptr;
92 return boost::logic::indeterminate;
94 return key->
verify(digestAlgorithm, bufs, sig);
101 return key ? key->
decrypt(buf) :
nullptr;
107 return m_backEnd->isTerminalMode();
113 m_backEnd->setTerminalMode(isTerminal);
119 return m_backEnd->isTpmLocked();
125 return m_backEnd->unlockTpm(password, passwordLength);
131 return m_backEnd->exportKey(keyName, pw, pwLen);
137 m_backEnd->importKey(keyName, pkcs8, pw, pwLen);
143 m_backEnd->importKey(keyName,
std::move(key));
147 Tpm::findKey(
const Name& keyName)
const 149 auto it = m_keys.find(keyName);
150 if (it != m_keys.end())
151 return it->second.get();
153 auto handle = m_backEnd->getKeyHandle(keyName);
154 if (handle ==
nullptr)
ConstBufferPtr sign(DigestAlgorithm digestAlgorithm, const InputBuffers &bufs) const
Generate a digital signature for bufs using this key with digestAlgorithm.
Copyright (c) 2011-2015 Regents of the University of California.
NDN_CXX_NODISCARD boost::logic::tribool verify(const InputBuffers &bufs, span< const uint8_t > sig, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Verify discontiguous ranges using the key with name keyName and using the digest digestAlgorithm.
ConstBufferPtr derivePublicKey() const
void importPrivateKey(const Name &keyName, span< const uint8_t > pkcs8, const char *pw, size_t pwLen)
Import a private key.
bool hasKey(const Name &keyName) const
Check if a private key exists.
Abstraction of TPM key handle.
Name createKey(const Name &identityName, const KeyParams ¶ms)
Create key for identityName according to params.
ConstBufferPtr getPublicKey(const Name &keyName) const
ConstBufferPtr sign(const InputBuffers &bufs, const Name &keyName, DigestAlgorithm digestAlgorithm) const
Sign discontiguous ranges using the key with name keyName and using the digest digestAlgorithm.
ConstBufferPtr exportPrivateKey(const Name &keyName, const char *pw, size_t pwLen) const
Export a private key.
NDN_CXX_NODISCARD 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.
void deleteKey(const Name &keyName)
Delete a key pair with name keyName.
std::string getTpmLocator() const
Base class for key parameters.
ConstBufferPtr decrypt(span< const uint8_t > cipherText) const
Return plain text content decrypted from cipherText using this key.
bool isTerminalMode() const
Check if the TPM is in terminal mode.
ConstBufferPtr decrypt(span< const uint8_t > buf, const Name &keyName) const
Decrypt blob using the key with name keyName.
bool verify(DigestAlgorithm digestAlgorithm, const InputBuffers &bufs, span< const uint8_t > sig) const
Verify the signature sig over bufs using this key and digestAlgorithm.
span< const uint8_t > sig
shared_ptr< const Buffer > ConstBufferPtr