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)
145 m_backEnd->importKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
149 Tpm::findKey(
const Name& keyName)
const 151 auto it = m_keys.find(keyName);
152 if (it != m_keys.end())
153 return it->second.get();
155 auto handle = m_backEnd->getKeyHandle(keyName);
156 if (handle ==
nullptr)
160 m_keys[keyName] = std::move(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.
ConstBufferPtr sign(DigestAlgorithm digestAlgorithm, const uint8_t *buf, size_t size) const
Copyright (c) 2011-2015 Regents of the University of California.
ConstBufferPtr derivePublicKey() const
ConstBufferPtr decrypt(const uint8_t *cipherText, size_t cipherTextLen) const
RSA key, supports sign/verify and encrypt/decrypt operations.
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 exportPrivateKey(const Name &keyName, const char *pw, size_t pwLen) const
Export a private key.
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
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.
KeyType getKeyType() const
void deleteKey(const Name &keyName)
Delete a key pair with name keyName.
std::string getTpmLocator() const
void importPrivateKey(const Name &keyName, const uint8_t *pkcs8, size_t pkcs8Len, const char *pw, size_t pwLen)
Import a private key.
Base class of 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