All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
key-chain.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_KEY_CHAIN_HPP
24 #define NDN_KEY_CHAIN_HPP
25 
26 #include <map>
27 #include <stdexcept>
28 #include "../data.hpp"
29 #include "../interest.hpp"
30 #include "../face.hpp"
31 #include "identity/identity-manager.hpp"
32 #include "policy/validation-request.hpp"
33 #include "pib/pib.hpp"
34 #include "pib/pib.hpp"
35 #include "tpm/tpm.hpp"
36 #include "signing-info.hpp"
37 #include "key-params.hpp"
38 #include "safe-bag.hpp"
39 
40 namespace ndn {
41 
42 class PolicyManager;
43 class ConfigFile;
44 
53 class KeyChain {
54 public:
59  class Error : public std::runtime_error
60  {
61  public:
62  Error(const std::string& what)
63  : std::runtime_error(what)
64  {
65  }
66  };
67 
73  {
74  public:
75  InvalidSigningInfoError(const std::string& what)
76  : Error(what)
77  {
78  }
79  };
80 
85  class LocatorMismatchError : public Error
86  {
87  public:
88  LocatorMismatchError(const std::string& what)
89  : Error(what)
90  {
91  }
92  };
93 
94  typedef func_lib::function<ptr_lib::shared_ptr<PibImpl>
95  (const std::string& location)> MakePibImpl;
96 
97  typedef func_lib::function<ptr_lib::shared_ptr<TpmBackEnd>
98  (const std::string& location)> MakeTpmBackEnd;
99 
113  KeyChain
114  (const std::string& pibLocator, const std::string& tpmLocator,
115  bool allowReset = false);
116 
126  KeyChain
127  (const ptr_lib::shared_ptr<PibImpl>& pibImpl,
128  const ptr_lib::shared_ptr<TpmBackEnd>& tpmBackEnd,
129  const ptr_lib::shared_ptr<PolicyManager>& policyManager =
130  ptr_lib::shared_ptr<PolicyManager>());
131 
139  KeyChain
140  (const ptr_lib::shared_ptr<IdentityManager>& identityManager,
141  const ptr_lib::shared_ptr<PolicyManager>& policyManager);
142 
149  KeyChain(const ptr_lib::shared_ptr<IdentityManager>& identityManager);
150 
160  KeyChain();
161 
162  Pib&
163  getPib()
164  {
165  if (isSecurityV1_)
166  throw Error("getPib is not supported for security v1");
167 
168  return *pib_;
169  }
170 
171  Tpm&
172  getTpm()
173  {
174  if (isSecurityV1_)
175  throw Error("getTpm is not supported for security v1");
176 
177  return *tpm_;
178  }
179 
185  bool
186  getIsSecurityV1() const { return isSecurityV1_; }
187 
188  // Identity management
189 
205  ptr_lib::shared_ptr<PibIdentity>
207  (const Name& identityName, const KeyParams& params = getDefaultKeyParams());
208 
213  void
214  deleteIdentity(PibIdentity& identity);
215 
220  void
221  setDefaultIdentity(PibIdentity& identity);
222 
223  // Key management
224 
235  ptr_lib::shared_ptr<PibKey>
236  createKey
237  (PibIdentity& identity, const KeyParams& params = getDefaultKeyParams());
238 
245  void
246  deleteKey(PibIdentity& identity, PibKey& key);
247 
254  void
255  setDefaultKey(PibIdentity& identity, PibKey& key);
256 
257  // Certificate management
258 
269  void
270  addCertificate(PibKey& key, const CertificateV2& certificate);
271 
280  void
281  deleteCertificate(PibKey& key, const Name& certificateName);
282 
291  void
292  setDefaultCertificate(PibKey& key, const CertificateV2& certificate);
293 
294  // Signing
295 
309  void
310  sign(Data& data, const SigningInfo& params,
312 
324  void
326  {
327  if (isSecurityV1_) {
328  identityManager_->signByCertificate
329  (data, prepareDefaultCertificateName(), wireFormat);
330  return;
331  }
332 
333  sign(data, getDefaultSigningInfo(), wireFormat);
334  }
335 
350  void
351  sign(Interest& interest, const SigningInfo& params,
353 
366  void
367  sign(Interest& interest,
369  {
370  if (isSecurityV1_) {
371  identityManager_->signInterestByCertificate
372  (interest, prepareDefaultCertificateName(), wireFormat);
373  return;
374  }
375 
376  sign(interest, getDefaultSigningInfo(), wireFormat);
377  }
378 
390  Blob
391  sign(const uint8_t* buffer, size_t bufferLength,
392  const SigningInfo& params = getDefaultSigningInfo());
393 
405  ptr_lib::shared_ptr<CertificateV2>
406  selfSign
407  (ptr_lib::shared_ptr<PibKey>& key,
409 
410  // Import and export
411 
412  // TODO: exportSafeBag
413 
431  void
433  (const SafeBag& safeBag, const uint8_t* password = 0,
434  size_t passwordLength = 0);
435 
436  // PIB & TPM backend registry
437 
446  static void
447  registerPibBackend(const std::string& scheme, const MakePibImpl& makePibImpl)
448  {
449  getPibFactories()[scheme] = makePibImpl;
450  }
451 
460  static void
462  (const std::string& scheme, const MakeTpmBackEnd& makeTpmBackEnd)
463  {
464  getTpmFactories()[scheme] = makeTpmBackEnd;
465  }
466 
467  // Security v1 methods
468 
469  /*****************************************
470  * Identity Management *
471  *****************************************/
472 
483  Name
485  (const Name& identityName, const KeyParams& params = getDefaultKeyParams())
486  {
487  if (!isSecurityV1_) {
488  ptr_lib::shared_ptr<PibIdentity> identity = createIdentityV2
489  (identityName, params);
490  return identity->getDefaultKey()->getDefaultCertificate()->getName();
491  }
492 
493  return identityManager_->createIdentityAndCertificate(identityName, params);
494  }
495 
509  Name
510  DEPRECATED_IN_NDN_CPP createIdentity
511  (const Name& identityName, const KeyParams& params = getDefaultKeyParams())
512  {
514  (createIdentityAndCertificate(identityName, params));
515  }
516 
523  void
524  deleteIdentity(const Name& identityName)
525  {
526  if (!isSecurityV1_) {
527  try {
528  deleteIdentity(*pib_->getIdentity(identityName));
529  } catch (const Pib::Error& ex) {
530  }
531  return;
532  }
533 
534  identityManager_->deleteIdentity(identityName);
535  }
536 
543  Name
545  {
546  if (!isSecurityV1_)
547  return pib_->getDefaultIdentity()->getName();
548 
549  return identityManager_->getDefaultIdentity();
550  }
551 
560  Name
562  {
563  if (!isSecurityV1_)
564  return pib_->getDefaultIdentity()->getDefaultKey()->getDefaultCertificate()
565  ->getName();
566 
567  return identityManager_->getDefaultCertificateName();
568  }
569 
579  Name
580  generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048)
581  {
582  if (!isSecurityV1_)
583  throw Error
584  ("generateRSAKeyPair is not supported for security v2. Use createIdentityV2.");
585 
586  return identityManager_->generateRSAKeyPair(identityName, isKsk, keySize);
587  }
588 
598  Name
599  generateEcdsaKeyPair(const Name& identityName, bool isKsk = false, int keySize = 256)
600  {
601  if (!isSecurityV1_)
602  throw Error
603  ("generateEcdsaKeyPair is not supported for security v2. Use createIdentityV2.");
604 
605  return identityManager_->generateEcdsaKeyPair(identityName, isKsk, keySize);
606  }
607 
615  void
616  setDefaultKeyForIdentity(const Name& keyName, const Name& identityNameCheck = Name())
617  {
618  if (!isSecurityV1_)
619  throw Error
620  ("setDefaultKeyForIdentity is not supported for security v2. Use getPib() methods.");
621 
622  return identityManager_->setDefaultKeyForIdentity(keyName, identityNameCheck);
623  }
624 
635  Name
636  generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048)
637  {
638  if (!isSecurityV1_)
639  throw Error
640  ("generateRSAKeyPairAsDefault is not supported for security v2. Use createIdentityV2.");
641 
642  return identityManager_->generateRSAKeyPairAsDefault(identityName, isKsk, keySize);
643  }
644 
655  Name
656  generateEcdsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 256)
657  {
658  if (!isSecurityV1_)
659  throw Error
660  ("generateEcdsaKeyPairAsDefault is not supported for security v2. Use createIdentityV2.");
661 
662  return identityManager_->generateEcdsaKeyPairAsDefault(identityName, isKsk, keySize);
663  }
664 
670  Blob
671  createSigningRequest(const Name& keyName)
672  {
673  if (!isSecurityV1_)
674  return pib_->getIdentity(PibKey::extractIdentityFromKeyName(keyName))
675  ->getKey(keyName)->getPublicKey();
676 
677  return identityManager_->getPublicKey(keyName)->getKeyDer();
678  }
679 
684  void
686  {
687  if (!isSecurityV1_)
688  throw Error
689  ("installIdentityCertificate is not supported for security v2. Use getPib() methods.");
690 
691  identityManager_->addCertificate(certificate);
692  }
693 
698  void
700  {
701  if (!isSecurityV1_)
702  throw Error
703  ("setDefaultCertificateForKey is not supported for security v2. Use getPib() methods.");
704 
705  identityManager_->setDefaultCertificateForKey(certificate);
706  }
707 
713  ptr_lib::shared_ptr<IdentityCertificate>
714  getCertificate(const Name& certificateName)
715  {
716  if (!isSecurityV1_)
717  throw Error
718  ("getCertificate is not supported for security v2. Use getPib() methods.");
719 
720  return identityManager_->getCertificate(certificateName);
721  }
722 
726  ptr_lib::shared_ptr<IdentityCertificate>
727  DEPRECATED_IN_NDN_CPP getIdentityCertificate(const Name& certificateName)
728  {
729  if (!isSecurityV1_)
730  throw Error
731  ("getIdentityCertificate is not supported for security v2. Use getPib() methods.");
732 
733  return identityManager_->getCertificate(certificateName);
734  }
735 
740  void
741  revokeKey(const Name & keyName)
742  {
743  //TODO: Implement
744  }
745 
750  void
751  revokeCertificate(const Name & certificateName)
752  {
753  //TODO: Implement
754  }
755 
760  const ptr_lib::shared_ptr<IdentityManager>&
762  {
763  if (!isSecurityV1_)
764  throw Error("getIdentityManager is not supported for security v2");
765 
766  return identityManager_;
767  }
768 
769  /*****************************************
770  * Policy Management *
771  *****************************************/
772 
777  const ptr_lib::shared_ptr<PolicyManager>&
778  getPolicyManager() { return policyManager_; }
779 
780  /*****************************************
781  * Sign/Verify *
782  *****************************************/
783 
790  void
791  sign(Data& data, const Name& certificateName,
793  {
794  if (!isSecurityV1_) {
795  SigningInfo signingInfo;
796  signingInfo.setSigningCertificateName(certificateName);
797  sign(data, signingInfo, wireFormat);
798  return;
799  }
800 
801  identityManager_->signByCertificate(data, certificateName, wireFormat);
802  }
803 
813  void
814  sign
815  (Interest& interest, const Name& certificateName,
817  {
818  if (!isSecurityV1_) {
819  SigningInfo signingInfo;
820  signingInfo.setSigningCertificateName(certificateName);
821  sign(interest, signingInfo, wireFormat);
822  return;
823  }
824 
825  identityManager_->signInterestByCertificate
826  (interest, certificateName, wireFormat);
827  }
828 
836  ptr_lib::shared_ptr<Signature>
837  sign(const uint8_t* buffer, size_t bufferLength, const Name& certificateName)
838  {
839  if (!isSecurityV1_)
840  throw Error
841  ("sign(buffer, certificateName) is not supported for security v2. Use sign with SigningInfo.");
842 
843  return identityManager_->signByCertificate
844  (buffer, bufferLength, certificateName);
845  }
846 
853  ptr_lib::shared_ptr<Signature>
854  sign(const std::vector<uint8_t>& buffer, const Name& certificateName)
855  {
856  return sign(&buffer[0], buffer.size(), certificateName);
857  }
858 
865  void
866  signByIdentity(Data& data, const Name& identityName = Name(), WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
867 
875  ptr_lib::shared_ptr<Signature>
876  signByIdentity(const uint8_t* buffer, size_t bufferLength, const Name& identityName);
877 
884  ptr_lib::shared_ptr<Signature>
885  signByIdentity(const std::vector<uint8_t>& buffer, const Name& identityName)
886  {
887  return signByIdentity(&buffer[0], buffer.size(), identityName);
888  }
889 
898  void
901  {
902  if (!isSecurityV1_) {
903  SigningInfo signingInfo;
904  signingInfo.setSha256Signing();
905  sign(data, signingInfo, wireFormat);
906  return;
907  }
908 
909  identityManager_->signWithSha256(data, wireFormat);
910  }
911 
921  void
924  {
925  if (!isSecurityV1_) {
926  SigningInfo signingInfo;
927  signingInfo.setSha256Signing();
928  sign(interest, signingInfo, wireFormat);
929  return;
930  }
931 
932  identityManager_->signInterestWithSha256(interest, wireFormat);
933  }
934 
950  void
951  verifyData
952  (const ptr_lib::shared_ptr<Data>& data, const OnVerified& onVerified,
953  const OnDataValidationFailed& onValidationFailed, int stepCount = 0);
954 
971  void
972  DEPRECATED_IN_NDN_CPP verifyData
973  (const ptr_lib::shared_ptr<Data>& data, const OnVerified& onVerified,
974  const OnVerifyFailed& onVerifyFailed, int stepCount = 0);
975 
991  void
993  (const ptr_lib::shared_ptr<Interest>& interest,
994  const OnVerifiedInterest& onVerified,
995  const OnInterestValidationFailed& onValidationFailed, int stepCount = 0,
997 
1014  void
1015  DEPRECATED_IN_NDN_CPP verifyInterest
1016  (const ptr_lib::shared_ptr<Interest>& interest,
1017  const OnVerifiedInterest& onVerified,
1018  const OnVerifyInterestFailed& onVerifyFailed, int stepCount = 0,
1019  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
1020 
1025  void
1026  setFace(Face* face) { face_ = face; }
1027 
1039  static void
1041  (Data& data, const Blob& key,
1042  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
1043 
1056  static void
1058  (Interest& interest, const Blob& key, const Name& keyName,
1059  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
1060 
1071  static bool
1073  (const Data& data, const Blob& key,
1074  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
1075 
1086  static bool
1088  (const Interest& interest, const Blob& key,
1089  WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
1090 
1091  static const KeyParams&
1092  getDefaultKeyParams();
1093 
1097  static const RsaKeyParams DEPRECATED_IN_NDN_CPP DEFAULT_KEY_PARAMS;
1098 
1099 private:
1100  friend class CommandInterestSigner;
1101 
1111  void
1112  construct
1113  (const std::string& pibLocator, const std::string& tpmLocator,
1114  bool allowReset);
1115 
1122  static std::map<std::string, MakePibImpl>&
1123  getPibFactories();
1124 
1131  static std::map<std::string, MakeTpmBackEnd>&
1132  getTpmFactories();
1133 
1137  static void
1138  parseLocatorUri
1139  (const std::string& uri, std::string& scheme, std::string& location);
1140 
1144  static void
1145  parseAndCheckPibLocator
1146  (const std::string& pibLocator, std::string& pibScheme,
1147  std::string& pibLocation);
1148 
1152  static void
1153  parseAndCheckTpmLocator
1154  (const std::string& tpmLocator, std::string& tpmScheme,
1155  std::string& tpmLocation);
1156 
1157  static std::string
1158  getDefaultPibScheme();
1159 
1160  static std::string
1161  getDefaultTpmScheme();
1162 
1168  static ptr_lib::shared_ptr<Pib>
1169  createPib(const std::string& pibLocator);
1170 
1176  static ptr_lib::shared_ptr<Tpm>
1177  createTpm(const std::string& tpmLocator);
1178 
1179  static std::string
1180  getDefaultPibLocator(ConfigFile& config);
1181 
1182  static std::string
1183  getDefaultTpmLocator(ConfigFile& config);
1184 
1194  ptr_lib::shared_ptr<Signature>
1195  prepareSignatureInfo(const SigningInfo& params, Name& keyName);
1196 
1206  Blob
1207  sign(const uint8_t* buffer, size_t bufferLength, const Name& keyName,
1208  DigestAlgorithm digestAlgorithm) const;
1209 
1210  static const SigningInfo&
1211  getDefaultSigningInfo();
1212 
1213  // Private security v1 methods
1214 
1215  void
1216  onCertificateData
1217  (const ptr_lib::shared_ptr<const Interest> &interest, const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep);
1218 
1219  void
1220  onCertificateInterestTimeout
1221  (const ptr_lib::shared_ptr<const Interest> &interest, int retry,
1222  const OnDataValidationFailed& onValidationFailed,
1223  const ptr_lib::shared_ptr<Data> &data,
1224  ptr_lib::shared_ptr<ValidationRequest> nextStep);
1225 
1230  void
1231  onCertificateInterestTimeoutForVerifyInterest
1232  (const ptr_lib::shared_ptr<const Interest> &interest, int retry,
1233  const OnInterestValidationFailed& onValidationFailed,
1234  const ptr_lib::shared_ptr<Interest>& originalInterest,
1235  ptr_lib::shared_ptr<ValidationRequest> nextStep);
1236 
1242  Name
1243  prepareDefaultCertificateName();
1244 
1249  void
1251 
1252  bool isSecurityV1_;
1253  ptr_lib::shared_ptr<IdentityManager> identityManager_; // for security v1
1254  ptr_lib::shared_ptr<PolicyManager> policyManager_; // for security v1
1255  Face* face_; // for security v1
1256 
1257  ptr_lib::shared_ptr<Pib> pib_;
1258  ptr_lib::shared_ptr<Tpm> tpm_;
1259 
1260  static std::string* defaultPibLocator_;
1261  static std::string* defaultTpmLocator_;
1262  static std::map<std::string, MakePibImpl>* pibFactories_;
1263  static std::map<std::string, MakeTpmBackEnd>* tpmFactories_;
1264  static SigningInfo* defaultSigningInfo_;
1265  static KeyParams* defaultKeyParams_;
1266 };
1267 
1268 }
1269 
1270 #endif
void revokeKey(const Name &keyName)
Revoke a key.
Definition: key-chain.hpp:741
CommandInterestSigner is a helper class to create command interests.
Definition: command-interest-signer.hpp:38
const ptr_lib::shared_ptr< PolicyManager > & getPolicyManager()
Get the policy manager given to or created by the constructor.
Definition: key-chain.hpp:778
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:68
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:53
Name getDefaultIdentity()
Get the default identity.
Definition: key-chain.hpp:544
ptr_lib::shared_ptr< CertificateV2 > selfSign(ptr_lib::shared_ptr< PibKey > &key, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Generate a self-signed certificate for the public key and add it to the PIB.
Definition: key-chain.cpp:392
static bool verifyDataWithHmacWithSha256(const Data &data, const Blob &key, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Compute a new HmacWithSha256 for the data packet and verify it against the signature value...
A SigningInfo holds the signing parameters passed to the KeyChain.
Definition: signing-info.hpp:39
void installIdentityCertificate(const IdentityCertificate &certificate)
Install an identity certificate into the public key identity storage.
Definition: key-chain.hpp:685
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:900
static void registerPibBackend(const std::string &scheme, const MakePibImpl &makePibImpl)
Add to the PIB factories map where scheme is the key and makePibImpl is the value.
Definition: key-chain.hpp:447
Definition: data.hpp:37
Definition: key-params.hpp:80
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
A KeyChain::LocatorMismatchError extends KeyChain::Error to indicate that the supplied TPM locator do...
Definition: key-chain.hpp:85
Definition: identity-certificate.hpp:30
bool getIsSecurityV1() const
Get the flag set by the constructor if this is a security v1 or v2 KeyChain.
Definition: key-chain.hpp:186
void verifyInterest(const ptr_lib::shared_ptr< Interest > &interest, const OnVerifiedInterest &onVerified, const OnInterestValidationFailed &onValidationFailed, int stepCount=0, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Check the signature on the signed interest and call either onVerify or onValidationFailed.
Definition: key-chain.cpp:588
static void registerTpmBackend(const std::string &scheme, const MakeTpmBackEnd &makeTpmBackEnd)
Add to the TPM factories map where scheme is the key and makeTpmBackEnd is the value.
Definition: key-chain.hpp:462
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:854
The TPM (Trusted Platform Module) stores the private portion of a user's cryptography keys...
Definition: tpm.hpp:54
static void signWithHmacWithSha256(Data &data, const Blob &key, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, compute an HmacWithSha256 and update the signature value.
void sign(Interest &interest, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Sign the Interest with the default key of the default identity.
Definition: key-chain.hpp:367
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:482
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 the default key for the identi...
Definition: key-chain.hpp:656
void addCertificate(PibKey &key, const CertificateV2 &certificate)
Add a certificate for the key.
Definition: key-chain.cpp:305
ptr_lib::shared_ptr< PibIdentity > createIdentityV2(const Name &identityName, const KeyParams &params=getDefaultKeyParams())
Create a security V2 identity for identityName.
Definition: key-chain.cpp:222
CertificateV2 represents a certificate following the certificate format naming convention.
Definition: certificate-v2.hpp:81
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
static const RsaKeyParams DEPRECATED_IN_NDN_CPP DEFAULT_KEY_PARAMS
Definition: key-chain.hpp:1097
SigningInfo & setSigningCertificateName(const Name &certificateName)
Set this to type SIGNER_TYPE_CERT and a certificate with name certificateName.
Definition: signing-info.hpp:151
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 the default key for the identity...
Definition: key-chain.hpp:636
Name createIdentityAndCertificate(const Name &identityName, const KeyParams &params=getDefaultKeyParams())
Create a security v1 identity by creating a pair of Key-Signing-Key (KSK) for this identity and a sel...
Definition: key-chain.hpp:485
void setFace(Face *face)
Set the Face which will be used to fetch required certificates.
Definition: key-chain.hpp:1026
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:885
ptr_lib::shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)
Get a certificate with the specified name.
Definition: key-chain.hpp:714
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
Definition: identity-certificate.cpp:101
ptr_lib::shared_ptr< IdentityCertificate > DEPRECATED_IN_NDN_CPP getIdentityCertificate(const Name &certificateName)
Definition: key-chain.hpp:727
void setDefaultKey(PibIdentity &identity, PibKey &key)
Set the key as the default key of identity.
Definition: key-chain.cpp:295
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:791
Name DEPRECATED_IN_NDN_CPP createIdentity(const Name &identityName, const KeyParams &params=getDefaultKeyParams())
Create a security v1 identity by creating a pair of Key-Signing-Key (KSK) for this identity and a sel...
Definition: key-chain.hpp:511
The PibKey class provides access to a key at the second level in the PIB's Identity-Key-Certificate h...
Definition: pib-key.hpp:43
KeyChain is the main class of the security library.
Definition: key-chain.hpp:53
ptr_lib::shared_ptr< PibKey > createKey(PibIdentity &identity, const KeyParams &params=getDefaultKeyParams())
Create a key for the identity according to params.
Definition: key-chain.cpp:266
void sign(Data &data, const SigningInfo &params, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, sign it according to the supplied signing parameters, and set its signature.
Definition: key-chain.cpp:335
PibIdentity is at the top level in PIB's Identity-Key-Certificate hierarchy.
Definition: pib-identity.hpp:48
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
void deleteIdentity(const Name &identityName)
Delete the identity from the public and private key storage.
Definition: key-chain.hpp:524
A KeyChain::Error extends runtime_error and represents an error in KeyChain processing.
Definition: key-chain.hpp:59
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:837
Blob createSigningRequest(const Name &keyName)
Create a public key signing request.
Definition: key-chain.hpp:671
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
A KeyChain::InvalidSigningInfoError extends KeyChain::Error to indicate that the supplied SigningInfo...
Definition: key-chain.hpp:72
void sign(Data &data, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, sign it with the default key of the default identity, and set its signature.
Definition: key-chain.hpp:325
void setDefaultKeyForIdentity(const Name &keyName, const Name &identityNameCheck=Name())
Set a key as the default key of an identity.
Definition: key-chain.hpp:616
KeyChain()
Create a KeyChain with the default PIB and TPM, which are platform-dependent and can be overridden sy...
Definition: key-chain.cpp:141
A SafeBag represents a container for sensitive related information such as a certificate and private ...
Definition: safe-bag.hpp:35
void setDefaultCertificateForKey(const IdentityCertificate &certificate)
Set the certificate as the default for its corresponding key.
Definition: key-chain.hpp:699
func_lib::function< void(const ptr_lib::shared_ptr< Interest > &interest, const std::string &reason)> OnInterestValidationFailed
An OnInterestValidationFailed function object is used to pass a callback to verifyInterest to report ...
Definition: validation-request.hpp:61
void deleteKey(PibIdentity &identity, PibKey &key)
Delete the given key of the given identity.
Definition: key-chain.cpp:283
void deleteCertificate(PibKey &key, const Name &certificateName)
Delete the certificate with the given name from the given key.
Definition: key-chain.cpp:316
static Name extractIdentityFromKeyName(const Name &keyName)
Extract the identity namespace from keyName.
Definition: pib-key.cpp:90
static bool verifyInterestWithHmacWithSha256(const Interest &interest, const Blob &key, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Compute a new HmacWithSha256 for all but the final name component and verify it against the signature...
KeyParams is a base class for key parameters.
Definition: key-params.hpp:36
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:599
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:46
void setDefaultIdentity(PibIdentity &identity)
Set the identity as the default identity.
Definition: key-chain.cpp:260
void setDefaultCertificate(PibKey &key, const CertificateV2 &certificate)
Set the certificate as the default certificate of the key.
Definition: key-chain.cpp:326
A ConfigFile locates, opens, and parses a library configuration file, and holds the values for the ap...
Definition: config-file.hpp:36
SigningInfo & setSha256Signing()
Set this to type SIGNER_TYPE_SHA256, and set the digest algorithm to DIGEST_ALGORITHM_SHA256.
Definition: signing-info.hpp:164
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
void deleteIdentity(PibIdentity &identity)
Delete the identity.
Definition: key-chain.cpp:246
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:580
Name getDefaultCertificateName()
Get the default certificate name of the default identity.
Definition: key-chain.hpp:561
const ptr_lib::shared_ptr< IdentityManager > & getIdentityManager()
Get the identity manager given to or created by the constructor.
Definition: key-chain.hpp:761
Definition: wire-format.hpp:39
A Pib::Error extends runtime_error and represents a semantic error in PIB processing.
Definition: pib.hpp:60
void importSafeBag(const SafeBag &safeBag, const uint8_t *password=0, size_t passwordLength=0)
Import a certificate and its corresponding private key encapsulated in a SafeBag. ...
Definition: key-chain.cpp:424
void verifyData(const ptr_lib::shared_ptr< Data > &data, const OnVerified &onVerified, const OnDataValidationFailed &onValidationFailed, int stepCount=0)
Check the signature on the Data object and call either onVerify or onValidationFailed.
Definition: key-chain.cpp:529
In general, a PIB (Public Information Base) stores the public portion of a user's cryptography keys...
Definition: pib.hpp:54
void revokeCertificate(const Name &certificateName)
Revoke a certificate.
Definition: key-chain.hpp:751
func_lib::function< void(const ptr_lib::shared_ptr< Data > &data, const std::string &reason)> OnDataValidationFailed
An OnDataValidationFailed function object is used to pass a callback to verifyData to report a failed...
Definition: validation-request.hpp:41