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))
37 Tpm::~Tpm() =
default;
40 Tpm::getTpmLocator()
const 42 return m_scheme +
":" + m_location;
46 Tpm::hasKey(
const Name& keyName)
const 48 return m_backEnd->hasKey(keyName);
52 Tpm::createKey(
const Name& identityName,
const KeyParams& params)
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"));
69 Tpm::deleteKey(
const Name& keyName)
71 auto it = m_keys.find(keyName);
72 if (it != m_keys.end())
75 m_backEnd->deleteKey(keyName);
79 Tpm::getPublicKey(
const Name& keyName)
const 90 Tpm::sign(
const uint8_t* buf,
size_t size,
const Name& keyName,
DigestAlgorithm digestAlgorithm)
const 97 return key->
sign(digestAlgorithm, buf, size);
101 Tpm::decrypt(
const uint8_t* buf,
size_t size,
const Name& keyName)
const 108 return key->
decrypt(buf, size);
112 Tpm::isTerminalMode()
const 114 return m_backEnd->isTerminalMode();
118 Tpm::setTerminalMode(
bool isTerminal)
const 120 m_backEnd->setTerminalMode(isTerminal);
124 Tpm::isTpmLocked()
const 126 return m_backEnd->isTpmLocked();
130 Tpm::unlockTpm(
const char* password,
size_t passwordLength)
const 132 return m_backEnd->unlockTpm(password, passwordLength);
136 Tpm::exportPrivateKey(
const Name& keyName,
const char* pw,
size_t pwLen)
const 138 return m_backEnd->exportKey(keyName, pw, pwLen);
142 Tpm::importPrivateKey(
const Name& keyName,
const uint8_t* pkcs8,
size_t pkcs8Len,
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) 2013-2017 Regents of the University of California.
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.
Elliptic Curve key (e.g. for ECDSA), supports sign/verify operations.
Represents an absolute name.
Base class of key parameters.
ConstBufferPtr decrypt(const uint8_t *cipherText, size_t cipherTextLen) const
shared_ptr< const Buffer > ConstBufferPtr