25 #include "../transform.hpp"
26 #include "../../encoding/buffer-stream.hpp"
27 #include "../../util/random.hpp"
28 #include "../pib/key.hpp"
39 return doHasKey(keyName);
45 return doGetKeyHandle(keyName);
56 BOOST_THROW_EXCEPTION(
Tpm::Error(
"Key `" + keyName.
toUri() +
"` already exists"));
72 const_cast<KeyParams&
>(params).setKeyId(keyId);
76 BOOST_THROW_EXCEPTION(
Error(
"Unsupported key id type"));
80 return doCreateKey(identity, params);
93 BOOST_THROW_EXCEPTION(
Error(
"Key `" + keyName.
toUri() +
"` does not exist"));
95 return doExportKey(keyName, pw, pwLen);
102 BOOST_THROW_EXCEPTION(
Error(
"Key `" + keyName.
toUri() +
"` already exists"));
104 doImportKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
void setKeyName(const Name &keyName)
static Component fromNumber(uint64_t number)
Create a component encoded as nonNegativeInteger.
Copyright (c) 2013-2016 Regents of the University of California.
ConstBufferPtr derivePublicKey() const
unique_ptr< KeyHandle > createKey(const Name &identity, const KeyParams ¶ms)
Create key for identity according to params.
uint64_t generateSecureWord64()
Generate a cryptographically secure random integer from the range [0, 2^64)
virtual void setTerminalMode(bool isTerminal) const
Set the terminal mode of TPM.
void importKey(const Name &keyName, const uint8_t *pkcs8, size_t pkcs8Len, const char *pw, size_t pwLen)
Import a private key in encrypted PKCS #8 format.
void deleteKey(const Name &keyName)
Delete a key with name keyName.
Abstraction of TPM key handle.
virtual bool isTpmLocked() const
std::string toUri() const
Encode this name as a URI.
ConstBufferPtr exportKey(const Name &keyName, const char *pw, size_t pwLen)
virtual bool isTerminalMode() const
Check if TPM is in terminal mode.
bool hasKey(const Name &keyName) const
Use the SHA256 hash of the public key as the key id.
Name abstraction to represent an absolute name.
static void setKeyName(KeyHandle &keyHandle, const Name &identity, const KeyParams ¶ms)
Set the key name in keyHandle according to identity and params.
virtual bool unlockTpm(const char *pw, size_t pwLen) const
Unlock TPM.
KeyIdType getKeyIdType() const
unique_ptr< KeyHandle > getKeyHandle(const Name &keyName) const
Component holds a read-only name component value.
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Name constructKeyName(const Name &identity, const name::Component &keyId)
Construct key name based on the appropriate naming conventions.
Use a 64-bit random number as the key id.
Base class of key parameters.
implements an output stream that constructs ndn::Buffer
shared_ptr< const Buffer > ConstBufferPtr
const name::Component & getKeyId() const