22 #ifndef NDN_CXX_SECURITY_KEY_CHAIN_HPP
23 #define NDN_CXX_SECURITY_KEY_CHAIN_HPP
48 class Error :
public std::runtime_error
51 using std::runtime_error::runtime_error;
94 KeyChain(
const std::string& pibLocator,
const std::string& tpmLocator,
bool allowReset =
false);
336 template<
class PibBackendType>
340 getPibFactories().emplace(scheme, [] (
const std::string& locator) {
341 return shared_ptr<pib::PibImpl>(
new PibBackendType(locator));
351 template<
class TpmBackendType>
355 getTpmFactories().emplace(scheme, [] (
const std::string& locator) {
356 return unique_ptr<tpm::BackEnd>(
new TpmBackendType(locator));
361 using PibFactories = std::map<std::string, std::function<shared_ptr<pib::PibImpl>(
const std::string&)>>;
362 using TpmFactories = std::map<std::string, std::function<unique_ptr<tpm::BackEnd>(
const std::string&)>>;
370 static std::tuple<std::string, std::string>
371 parseAndCheckPibLocator(
const std::string& pibLocator);
373 static std::tuple<std::string, std::string>
374 parseAndCheckTpmLocator(
const std::string& tpmLocator);
376 static const std::string&
377 getDefaultPibScheme();
379 static const std::string&
380 getDefaultTpmScheme();
385 static unique_ptr<Pib>
386 createPib(
const std::string& pibLocator);
391 static unique_ptr<Tpm>
392 createTpm(
const std::string& tpmLocator);
395 static const std::string&
396 getDefaultPibLocator();
398 static const std::string&
399 getDefaultTpmLocator();
424 std::tuple<Name, SignatureInfo>
435 unique_ptr<Pib> m_pib;
436 unique_ptr<Tpm> m_tpm;
438 static std::string s_defaultPibLocator;
439 static std::string s_defaultTpmLocator;
450 #define NDN_CXX_KEYCHAIN_REGISTER_PIB_BACKEND(PibType) \
451 static class NdnCxxAuto ## PibType ## PibRegistrationClass \
454 NdnCxxAuto ## PibType ## PibRegistrationClass() \
456 ::ndn::security::KeyChain::registerPibBackend<PibType>(PibType::getScheme()); \
458 } ndnCxxAuto ## PibType ## PibRegistrationVariable
468 #define NDN_CXX_KEYCHAIN_REGISTER_TPM_BACKEND(TpmType) \
469 static class NdnCxxAuto ## TpmType ## TpmRegistrationClass \
472 NdnCxxAuto ## TpmType ## TpmRegistrationClass() \
474 ::ndn::security::KeyChain::registerTpmBackend<TpmType>(TpmType::getScheme()); \
476 } ndnCxxAuto ## TpmType ## TpmRegistrationVariable
481 using security::KeyChain;
Represents a Data packet.
Represents an Interest packet.
Base class for key parameters.
Represents an absolute name.
SimpleSymmetricKeyParams is a template for symmetric keys with only one parameter: size.
A secured container for sensitive information (certificate, private key)
Signing parameters passed to KeyChain.
static const Name & getHmacIdentity()
A localhost identity to indicate that the signature is generated using an HMAC key.
A frontend handle of an Identity.
A frontend handle of a key instance.
Represents an NDN certificate following the version 2.0 format.
Error indicating that the supplied SigningInfo is invalid.
Error indicating that the supplied TPM locator does not match the locator stored in PIB.
The interface of signing key management.
void setDefaultIdentity(const Identity &identity)
Set identity as the default identity.
void deleteKey(const Identity &identity, const Key &key)
Delete a key key of identity.
void setDefaultCertificate(const Key &key, const Certificate &certificate)
Set cert as the default certificate of key.
const Tpm & getTpm() const noexcept
Identity createIdentity(const Name &identityName, const KeyParams ¶ms=getDefaultKeyParams())
Create an identity identityName.
Key createKey(const Identity &identity, const KeyParams ¶ms=getDefaultKeyParams())
Create a new key for identity.
void deleteIdentity(const Identity &identity)
delete identity.
static const KeyParams & getDefaultKeyParams()
void sign(Data &data, const SigningInfo ¶ms=SigningInfo())
Sign a Data packet according to the supplied signing information.
void deleteCertificate(const Key &key, const Name &certificateName)
delete a certificate with name certificateName of key.
void setDefaultKey(const Identity &identity, const Key &key)
Set key as the default key of identity.
void importSafeBag(const SafeBag &safeBag, const char *pw, size_t pwLen)
Import a certificate and its corresponding private key from a SafeBag.
const Pib & getPib() const noexcept
Name createHmacKey(const Name &prefix=SigningInfo::getHmacIdentity(), const HmacKeyParams ¶ms=HmacKeyParams())
Create a new HMAC key.
void importPrivateKey(const Name &keyName, shared_ptr< transform::PrivateKey > key)
Import a private key into the TPM.
void addCertificate(const Key &key, const Certificate &certificate)
Add a certificate certificate for key.
KeyChain()
Constructor to create KeyChain with default PIB and TPM.
static void registerTpmBackend(const std::string &scheme)
Register a new TPM backend.
static void registerPibBackend(const std::string &scheme)
Register a new PIB backend.
shared_ptr< SafeBag > exportSafeBag(const Certificate &certificate, const char *pw, size_t pwLen)
Export a certificate and its corresponding private key.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
SignatureTypeValue
SignatureType values.
SimpleSymmetricKeyParams< detail::HmacKeyParamsInfo > HmacKeyParams
HmacKeyParams carries parameters for HMAC key.
shared_ptr< const Buffer > ConstBufferPtr
KeyType
The type of a cryptographic key.