22 #ifndef NDN_SECURITY_V2_KEY_CHAIN_HPP
23 #define NDN_SECURITY_V2_KEY_CHAIN_HPP
25 #include "../security-common.hpp"
27 #include "../key-params.hpp"
28 #include "../pib/pib.hpp"
29 #include "../safe-bag.hpp"
30 #include "../signing-info.hpp"
31 #include "../tpm/tpm.hpp"
32 #include "../../interest.hpp"
49 class Error :
public std::runtime_error
54 :
std::runtime_error(what)
107 KeyChain(
const std::string& pibLocator,
const std::string& tpmLocator,
bool allowReset =
false);
186 deleteKey(
const Identity& identity,
const Key& key);
350 template<
class PibBackendType>
360 template<
class TpmBackendType>
365 typedef std::map<std::string, function<unique_ptr<pib::PibImpl>(
const std::string& location)>> PibFactories;
366 typedef std::map<std::string, function<unique_ptr<tpm::BackEnd>(
const std::string& location)>> TpmFactories;
374 static std::tuple<std::string, std::string>
375 parseAndCheckPibLocator(
const std::string& pibLocator);
377 static std::tuple<std::string, std::string>
378 parseAndCheckTpmLocator(
const std::string& tpmLocator);
380 static const std::string&
381 getDefaultPibScheme();
383 static const std::string&
384 getDefaultTpmScheme();
389 static unique_ptr<Pib>
390 createPib(
const std::string& pibLocator);
395 static unique_ptr<Tpm>
396 createTpm(
const std::string& tpmLocator);
399 static const std::string&
400 getDefaultPibLocator();
402 static const std::string&
403 getDefaultTpmLocator();
426 std::tuple<Name, SignatureInfo>
444 std::unique_ptr<Pib> m_pib;
445 std::unique_ptr<Tpm> m_tpm;
447 static std::string s_defaultPibLocator;
448 static std::string s_defaultTpmLocator;
451 template<
class PibType>
455 getPibFactories().emplace(scheme, [] (
const std::string& locator) {
456 return unique_ptr<pib::PibImpl>(
new PibType(locator));
460 template<
class TpmType>
464 getTpmFactories().emplace(scheme, [] (
const std::string& locator) {
465 return unique_ptr<tpm::BackEnd>(
new TpmType(locator));
477 #define NDN_CXX_V2_KEYCHAIN_REGISTER_PIB_BACKEND(PibType) \
478 static class NdnCxxAuto ## PibType ## PibRegistrationClass \
481 NdnCxxAuto ## PibType ## PibRegistrationClass() \
483 ::ndn::security::v2::KeyChain::registerPibBackend<PibType>(PibType::getScheme()); \
485 } ndnCxxAuto ## PibType ## PibRegistrationVariable
495 #define NDN_CXX_V2_KEYCHAIN_REGISTER_TPM_BACKEND(TpmType) \
496 static class NdnCxxAuto ## TpmType ## TpmRegistrationClass \
499 NdnCxxAuto ## TpmType ## TpmRegistrationClass() \
501 ::ndn::security::v2::KeyChain::registerTpmBackend<TpmType>(TpmType::getScheme()); \
503 } ndnCxxAuto ## TpmType ## TpmRegistrationVariable
509 #endif // NDN_SECURITY_V2_KEY_CHAIN_HPP
void deleteKey(const Identity &identity, const Key &key)
Delete a key key of identity.
Copyright (c) 2013-2016 Regents of the University of California.
The certificate following the certificate format naming convention.
The interface of signing key management.
void addCertificate(const Key &key, const Certificate &certificate)
Add a certificate certificate for key.
const Pib & getPib() const
Key createKey(const Identity &identity, const KeyParams ¶ms=getDefaultKeyParams())
Create a key for identity according to params.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
KeyChain()
Constructor to create KeyChain with default PIB and TPM.
Class representing a wire element of NDN-TLV packet format.
Error indicating that the supplied TPM locator does not match the locator stored in PIB...
represents an Interest packet
Signing parameters passed to KeyChain.
void deleteCertificate(const Key &key, const Name &certificateName)
delete a certificate with name certificateName of key.
Identity createIdentity(const Name &identityName, const KeyParams ¶ms=getDefaultKeyParams())
Create an identity identityName.
void importSafeBag(const SafeBag &safeBag, const char *pw, size_t pwLen)
Import a pair of certificate and its corresponding private key encapsulated in a SafeBag.
shared_ptr< SafeBag > exportSafeBag(const Certificate &certificate, const char *pw, size_t pwLen)
export a certificate of name certificateName and its corresponding private key.
LocatorMismatchError(const std::string &what)
void setDefaultIdentity(const Identity &identity)
Set identity as the default identity.
static void registerPibBackend(const std::string &scheme)
Register a new PIB backend.
static const SigningInfo & getDefaultSigningInfo()
static void registerTpmBackend(const std::string &scheme)
Register a new TPM backend.
Error(const std::string &what)
Name abstraction to represent an absolute name.
Error indicating that the supplied SigningInfo is invalid.
void sign(Data &data, const SigningInfo ¶ms=getDefaultSigningInfo())
Sign data according to the supplied signing information.
void deleteIdentity(const Identity &identity)
delete identity.
static const KeyParams & getDefaultKeyParams()
a secured container for sensitive information(certificate, private key)
void setDefaultKey(const Identity &identity, const Key &key)
Set key as the default key of identity.
void setDefaultCertificate(const Key &key, const Certificate &cert)
Set cert as the default certificate of key.
Base class of key parameters.
const Tpm & getTpm() const
InvalidSigningInfoError(const std::string &what)