22 #ifndef NDN_CXX_SECURITY_KEY_CHAIN_HPP
23 #define NDN_CXX_SECURITY_KEY_CHAIN_HPP
89 class Error :
public std::runtime_error
92 using std::runtime_error::runtime_error;
133 KeyChain(
const std::string& pibLocator,
const std::string& tpmLocator,
bool allowReset =
false);
361 makeCertificate(
const Certificate& certRequest,
const SigningInfo& params = SigningInfo(),
362 const MakeCertificateOptions& opts = {});
375 exportSafeBag(
const Certificate& certificate,
const char* pw,
size_t pwLen);
406 template<
class PibBackendType>
410 getPibFactories().emplace(scheme, [] (
const std::string& location) {
411 return shared_ptr<pib::PibImpl>(
new PibBackendType(location));
419 template<
class TpmBackendType>
423 getTpmFactories().emplace(scheme, [] (
const std::string& location) {
424 return unique_ptr<tpm::BackEnd>(
new TpmBackendType(location));
431 KeyChain(Locator pibLocator, Locator tpmLocator,
bool allowReset);
433 using PibFactories = std::map<std::string, std::function<shared_ptr<pib::PibImpl>(
const std::string&)>>;
434 using TpmFactories = std::map<std::string, std::function<unique_ptr<tpm::BackEnd>(
const std::string&)>>;
443 parseAndCheckPibLocator(
const std::string& pibLocator);
446 parseAndCheckTpmLocator(
const std::string& tpmLocator);
449 static const Locator&
450 getDefaultPibLocator();
452 static const Locator&
453 getDefaultTpmLocator();
455 #ifdef NDN_CXX_WITH_TESTS
457 resetDefaultLocators();
487 std::tuple<Name, SignatureInfo>
490 static std::tuple<Name, SignatureInfo>
491 prepareSignatureInfoSha256(
const SigningInfo& params);
493 static std::tuple<Name, SignatureInfo>
496 static std::tuple<Name, SignatureInfo>
499 static std::tuple<Name, SignatureInfo>
501 const std::optional<Name>& certName = std::nullopt);
511 unique_ptr<Pib> m_pib;
512 unique_ptr<Tpm> m_tpm;
514 static Locator s_defaultPibLocator;
515 static Locator s_defaultTpmLocator;
521 using security::KeyChain;
530 #define NDN_CXX_KEYCHAIN_REGISTER_PIB_BACKEND(PibType) \
531 static class NdnCxxAuto ## PibType ## PibRegistrationClass \
534 NdnCxxAuto ## PibType ## PibRegistrationClass() \
536 ::ndn::security::KeyChain::registerPibBackend<PibType>(PibType::getScheme()); \
538 } ndnCxxAuto ## PibType ## PibRegistrationVariable
546 #define NDN_CXX_KEYCHAIN_REGISTER_TPM_BACKEND(TpmType) \
547 static class NdnCxxAuto ## TpmType ## TpmRegistrationClass \
550 NdnCxxAuto ## TpmType ## TpmRegistrationClass() \
552 ::ndn::security::KeyChain::registerTpmBackend<TpmType>(TpmType::getScheme()); \
554 } ndnCxxAuto ## TpmType ## TpmRegistrationVariable
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.
Represents a name component.
Represents an NDN certificate.
static const name::Component DEFAULT_ISSUER_ID
Error indicating that the supplied SigningInfo is invalid.
Error indicating that the supplied TPM locator does not match the locator stored in PIB.
The main interface for signing key management.
void sign(Data &data, const SigningInfo ¶ms=SigningInfo())
Sign a Data packet according to the supplied signing information.
void setDefaultCertificate(const Key &key, const Certificate &cert)
Set cert as the default certificate of key.
void addCertificate(const Key &key, const Certificate &cert)
Add a certificate cert for key.
const Pib & getPib() const noexcept
void importPrivateKey(const Name &keyName, shared_ptr< transform::PrivateKey > key)
Import a private key into the TPM.
void importSafeBag(const SafeBag &safeBag, const char *pw, size_t pwLen)
Import a certificate and its corresponding private key from a SafeBag.
static const KeyParams & getDefaultKeyParams()
static void registerTpmBackend(const std::string &scheme)
Register a new TPM backend type.
shared_ptr< SafeBag > exportSafeBag(const Certificate &certificate, const char *pw, size_t pwLen)
Export a certificate and its corresponding private key.
void deleteIdentity(const Identity &identity)
Delete identity from this KeyChain.
Key createKey(const Identity &identity, const KeyParams ¶ms=getDefaultKeyParams())
Create a new key for identity.
void setDefaultIdentity(const Identity &identity)
Set identity as the default identity.
void setDefaultKey(const Identity &identity, const Key &key)
Set key as the default key of identity.
const Tpm & getTpm() const noexcept
Name createHmacKey(const Name &prefix=SigningInfo::getHmacIdentity(), const HmacKeyParams ¶ms=HmacKeyParams())
Create a new HMAC key.
KeyChain()
Constructor to create KeyChain with default PIB and TPM.
Certificate makeCertificate(const pib::Key &publicKey, const SigningInfo ¶ms=SigningInfo(), const MakeCertificateOptions &opts={})
Create and sign a certificate packet.
static void registerPibBackend(const std::string &scheme)
Register a new PIB backend type.
Identity createIdentity(const Name &identityName, const KeyParams ¶ms=getDefaultKeyParams())
Create an identity identityName.
void deleteKey(const Identity &identity, const Key &key)
Delete key from identity.
void deleteCertificate(const Key &key, const Name &certName)
Delete a certificate with name certName from key.
Signing parameters passed to KeyChain.
static const Name & getHmacIdentity()
A localhost identity to indicate that the signature is generated using an HMAC key.
Frontend handle for an identity in the PIB.
Frontend handle for a key in the PIB.
Frontend to the Public Information Base.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Contains the ndn-cxx security framework.
::boost::chrono::milliseconds milliseconds
SignatureTypeValue
SignatureType values.
KeyType
The type of a cryptographic key.
SimpleSymmetricKeyParams< detail::HmacKeyParamsInfo > HmacKeyParams
HmacKeyParams carries parameters for HMAC key.
std::shared_ptr< const Buffer > ConstBufferPtr
Options to KeyChain::makeCertificate().
name::Component issuerId
Certificate name IssuerId component.
std::optional< uint64_t > version
Certificate name version component.
time::milliseconds freshnessPeriod
Certificate packet FreshnessPeriod.
std::optional< ValidityPeriod > validity
Certificate ValidityPeriod.