23 #ifndef NDN_KEY_CHAIN_HPP
24 #define NDN_KEY_CHAIN_HPP
26 #include "../data.hpp"
27 #include "../interest.hpp"
28 #include "../face.hpp"
29 #include "identity/identity-manager.hpp"
30 #include "policy/validation-request.hpp"
31 #include "key-params.hpp"
53 (
const ptr_lib::shared_ptr<IdentityManager>& identityManager,
54 const ptr_lib::shared_ptr<PolicyManager>& policyManager);
61 KeyChain(
const ptr_lib::shared_ptr<IdentityManager>& identityManager);
84 (
const Name& identityName,
const KeyParams& params = DEFAULT_KEY_PARAMS)
86 return identityManager_->createIdentityAndCertificate(identityName, params);
118 identityManager_->deleteIdentity(identityName);
129 return identityManager_->getDefaultIdentity();
142 return identityManager_->getDefaultCertificateName();
157 return identityManager_->generateRSAKeyPair(identityName, isKsk, keySize);
172 return identityManager_->generateEcdsaKeyPair(identityName, isKsk, keySize);
184 return identityManager_->setDefaultKeyForIdentity(keyName, identityName);
199 return identityManager_->generateRSAKeyPairAsDefault(identityName, isKsk, keySize);
214 return identityManager_->generateEcdsaKeyPairAsDefault(identityName, isKsk, keySize);
225 return identityManager_->getPublicKey(keyName)->getKeyDer();
235 identityManager_->addCertificate(certificate);
245 identityManager_->setDefaultCertificateForKey(certificate);
253 ptr_lib::shared_ptr<IdentityCertificate>
256 return identityManager_->getCertificate(certificateName);
264 ptr_lib::shared_ptr<IdentityCertificate>
267 return identityManager_->getAnyCertificate(certificateName);
275 ptr_lib::shared_ptr<IdentityCertificate>
278 return identityManager_->getCertificate(certificateName);
286 ptr_lib::shared_ptr<IdentityCertificate>
289 return identityManager_->getAnyCertificate(certificateName);
316 const ptr_lib::shared_ptr<IdentityManager>&
327 const ptr_lib::shared_ptr<PolicyManager>&
344 identityManager_->signByCertificate(data, certificateName, wireFormat);
361 identityManager_->signInterestByCertificate
362 (interest, certificateName, wireFormat);
372 ptr_lib::shared_ptr<Signature>
373 sign(
const uint8_t* buffer,
size_t bufferLength,
const Name& certificateName)
375 return identityManager_->signByCertificate
376 (buffer, bufferLength, certificateName);
385 ptr_lib::shared_ptr<Signature>
386 sign(
const std::vector<uint8_t>& buffer,
const Name& certificateName)
388 return sign(&buffer[0], buffer.size(), certificateName);
407 ptr_lib::shared_ptr<Signature>
416 ptr_lib::shared_ptr<Signature>
434 identityManager_->signWithSha256(data, wireFormat);
450 identityManager_->signInterestWithSha256(interest, wireFormat);
462 (
const ptr_lib::shared_ptr<Data>& data,
const OnVerified& onVerified,
const OnVerifyFailed& onVerifyFailed,
int stepCount = 0);
474 (
const ptr_lib::shared_ptr<Interest>& interest,
491 (
const ptr_lib::shared_ptr<const Interest> &interest,
const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep);
494 onCertificateInterestTimeout
495 (
const ptr_lib::shared_ptr<const Interest> &interest,
int retry,
const OnVerifyFailed& onVerifyFailed,
496 const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep);
503 onCertificateInterestTimeoutForVerifyInterest
504 (
const ptr_lib::shared_ptr<const Interest> &interest,
int retry,
506 const ptr_lib::shared_ptr<Interest>& originalInterest,
507 ptr_lib::shared_ptr<ValidationRequest> nextStep);
509 ptr_lib::shared_ptr<IdentityManager> identityManager_;
510 ptr_lib::shared_ptr<PolicyManager> policyManager_;
void revokeKey(const Name &keyName)
Revoke a key.
Definition: key-chain.hpp:297
const ptr_lib::shared_ptr< PolicyManager > & getPolicyManager()
Get the policy manager given to or created by the constructor.
Definition: key-chain.hpp:328
func_lib::function< void(const ptr_lib::shared_ptr< Interest > &interest)> OnVerifyInterestFailed
An OnVerifyInterestFailed function object is used to pass a callback to verifyInterest to report a fa...
Definition: validation-request.hpp:52
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
func_lib::function< void(const ptr_lib::shared_ptr< Interest > &interest)> OnVerifiedInterest
An OnVerifiedInterest function object is used to pass a callback to verifyInterest to report a succes...
Definition: validation-request.hpp:45
Name getDefaultIdentity()
Get the default identity.
Definition: key-chain.hpp:127
void verifyData(const ptr_lib::shared_ptr< Data > &data, const OnVerified &onVerified, const OnVerifyFailed &onVerifyFailed, int stepCount=0)
Check the signature on the Data object and call either onVerify or onVerifyFailed.
Definition: key-chain.cpp:98
void installIdentityCertificate(const IdentityCertificate &certificate)
Install an identity certificate into the public key identity storage.
Definition: key-chain.hpp:233
void signWithSha256(Data &data, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, digest it and set its SignatureInfo to a DigestSha256.
Definition: key-chain.hpp:432
Definition: key-params.hpp:58
The Face class provides the main methods for NDN communication.
Definition: face.hpp:72
Definition: identity-certificate.hpp:30
ptr_lib::shared_ptr< Signature > sign(const std::vector< uint8_t > &buffer, const Name &certificateName)
Sign the byte array using a certificate name and return a Signature object.
Definition: key-chain.hpp:386
Name createIdentityAndCertificate(const Name &identityName, const KeyParams ¶ms=DEFAULT_KEY_PARAMS)
Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed ce...
Definition: key-chain.hpp:84
void signByIdentity(Data &data, const Name &identityName=Name(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, sign it and set its signature.
Definition: key-chain.cpp:62
Name generateEcdsaKeyPairAsDefault(const Name &identityName, bool isKsk=false, int keySize=256)
Generate a pair of ECDSA keys for the specified identity and set it as default key for the identity...
Definition: key-chain.hpp:212
func_lib::function< void(const ptr_lib::shared_ptr< Data > &data)> OnVerified
An OnVerified function object is used to pass a callback to verifyData to report a successful verific...
Definition: validation-request.hpp:33
ptr_lib::shared_ptr< IdentityCertificate > getIdentityCertificate(const Name &certificateName)
Get an identity certificate with the specified name.
Definition: key-chain.hpp:276
Name generateRSAKeyPairAsDefault(const Name &identityName, bool isKsk=false, int keySize=2048)
Generate a pair of RSA keys for the specified identity and set it as default key for the identity...
Definition: key-chain.hpp:197
void setFace(Face *face)
Set the Face which will be used to fetch required certificates.
Definition: key-chain.hpp:484
ptr_lib::shared_ptr< Signature > signByIdentity(const std::vector< uint8_t > &buffer, const Name &identityName)
Sign the byte array using an identity name and return a Signature object.
Definition: key-chain.hpp:417
ptr_lib::shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)
Get a certificate with the specified name.
Definition: key-chain.hpp:254
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
Definition: identity-certificate.cpp:101
void sign(Data &data, const Name &certificateName, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, sign it and set its signature.
Definition: key-chain.hpp:341
KeyChain is the main class of the security library.
Definition: key-chain.hpp:45
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
void deleteIdentity(const Name &identityName)
Delete the identity from the public and private key storage.
Definition: key-chain.hpp:116
void verifyInterest(const ptr_lib::shared_ptr< Interest > &interest, const OnVerifiedInterest &onVerified, const OnVerifyInterestFailed &onVerifyFailed, int stepCount=0, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Check the signature on the signed interest and call either onVerify or onVerifyFailed.
Definition: key-chain.cpp:119
ptr_lib::shared_ptr< Signature > sign(const uint8_t *buffer, size_t bufferLength, const Name &certificateName)
Sign the byte array using a certificate name and return a Signature object.
Definition: key-chain.hpp:373
ptr_lib::shared_ptr< IdentityCertificate > getAnyCertificate(const Name &certificateName)
Get a certificate even if the certificate is not valid anymore.
Definition: key-chain.hpp:265
Blob createSigningRequest(const Name &keyName)
Create a public key signing request.
Definition: key-chain.hpp:223
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
KeyChain()
Create a new KeyChain with the the default IdentityManager and a NoVerifyPolicyManager.
Definition: key-chain.cpp:54
void setDefaultCertificateForKey(const IdentityCertificate &certificate)
Set the certificate as the default for its corresponding key.
Definition: key-chain.hpp:243
Name DEPRECATED_IN_NDN_CPP createIdentity(const Name &identityName, const KeyParams ¶ms=DEFAULT_KEY_PARAMS)
Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed ce...
Definition: key-chain.hpp:103
void setDefaultKeyForIdentity(const Name &keyName, const Name &identityName=Name())
Set a key as the default key of an identity.
Definition: key-chain.hpp:182
KeyParams is a base class for key parameters.
Definition: key-params.hpp:34
Name generateEcdsaKeyPair(const Name &identityName, bool isKsk=false, int keySize=256)
Generate a pair of ECDSA keys for the specified identity.
Definition: key-chain.hpp:170
func_lib::function< void(const ptr_lib::shared_ptr< Data > &data)> OnVerifyFailed
An OnVerifyFailed function object is used to pass a callback to verifyData to report a failed verific...
Definition: validation-request.hpp:38
Name generateRSAKeyPair(const Name &identityName, bool isKsk=false, int keySize=2048)
Generate a pair of RSA keys for the specified identity.
Definition: key-chain.hpp:155
Name getDefaultCertificateName()
Get the default certificate name of the default identity.
Definition: key-chain.hpp:140
const ptr_lib::shared_ptr< IdentityManager > & getIdentityManager()
Get the identity manager given to or created by the constructor.
Definition: key-chain.hpp:317
ptr_lib::shared_ptr< IdentityCertificate > getAnyIdentityCertificate(const Name &certificateName)
Get an identity certificate even if the certificate is not valid anymore.
Definition: key-chain.hpp:287
void revokeCertificate(const Name &certificateName)
Revoke a certificate.
Definition: key-chain.hpp:307