24 #include "../../encoding/buffer-stream.hpp" 30 Tpm::Tpm(
const std::string& scheme,
const std::string& location, unique_ptr<BackEnd> backEnd)
32 , m_location(location)
33 , m_backEnd(
std::move(backEnd))
42 return m_scheme +
":" + m_location;
48 return m_backEnd->hasKey(keyName);
57 unique_ptr<KeyHandle> keyHandle = m_backEnd->createKey(identityName, params);
58 Name keyName = keyHandle->getKeyName();
59 m_keys[keyName] = std::move(keyHandle);
63 BOOST_THROW_EXCEPTION(
Error(
"Fail to create a key pair: Unsupported key type"));
71 auto it = m_keys.find(keyName);
72 if (it != m_keys.end())
75 m_backEnd->deleteKey(keyName);
97 return key->
sign(digestAlgorithm, buf, size);
108 return key->
decrypt(buf, size);
114 return m_backEnd->isTerminalMode();
120 m_backEnd->setTerminalMode(isTerminal);
126 return m_backEnd->isTpmLocked();
132 return m_backEnd->unlockTpm(password, passwordLength);
138 return m_backEnd->exportKey(keyName, pw, pwLen);
143 const char* pw,
size_t pwLen)
146 m_backEnd->importKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
155 Tpm::findKey(
const Name& keyName)
const 157 auto it = m_keys.find(keyName);
159 if (it != m_keys.end())
160 return it->second.get();
162 unique_ptr<KeyHandle> handle = m_backEnd->getKeyHandle(keyName);
164 if (handle !=
nullptr) {
166 m_keys[keyName] = std::move(handle);
Copyright (c) 2011-2015 Regents of the University of California.
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.
Name createKey(const Name &identityName, const KeyParams ¶ms)
Create key for identityName according to params.
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.
Catch-all error for security policy errors that don't fit in other categories.
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 deleteKey(const Name &keyName)
Delete a key pair with name keyName.
ConstBufferPtr exportPrivateKey(const Name &keyName, const char *pw, size_t pwLen) const
Export a private key.
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.
bool importPrivateKey(const Name &keyName, const uint8_t *pkcs8, size_t pkcs8Len, const char *pw, size_t pwLen)
Import a private key.
ConstBufferPtr decrypt(const uint8_t *cipherText, size_t cipherTextLen) const
shared_ptr< const Buffer > ConstBufferPtr