NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
key-chain.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #ifndef NDN_SECURITY_KEY_CHAIN_HPP
25 #define NDN_SECURITY_KEY_CHAIN_HPP
26 
27 #include "sec-public-info.hpp"
28 #include "sec-tpm.hpp"
29 #include "key-params.hpp"
30 #include "secured-bag.hpp"
33 #include "digest-sha256.hpp"
34 #include "signing-info.hpp"
35 
36 #include "../interest.hpp"
37 #include "../util/crypto.hpp"
38 #include "../util/random.hpp"
39 #include <initializer_list>
40 
41 namespace ndn {
42 namespace security {
43 
47 class KeyChain : noncopyable
48 {
49 public:
50  class Error : public std::runtime_error
51  {
52  public:
53  explicit
54  Error(const std::string& what)
55  : std::runtime_error(what)
56  {
57  }
58  };
59 
64  class MismatchError : public Error
65  {
66  public:
67  explicit
68  MismatchError(const std::string& what)
69  : Error(what)
70  {
71  }
72  };
73 
74  typedef function<unique_ptr<SecPublicInfo> (const std::string&)> PibCreateFunc;
75  typedef function<unique_ptr<SecTpm>(const std::string&)> TpmCreateFunc;
76 
82  template<class PibType>
83  static void
84  registerPib(std::initializer_list<std::string> aliases);
85 
91  template<class TpmType>
92  static void
93  registerTpm(std::initializer_list<std::string> aliases);
94 
98  static std::string
100 
104  static unique_ptr<SecPublicInfo>
105  createPib(const std::string& pibLocator);
106 
110  static std::string
112 
116  static unique_ptr<SecTpm>
117  createTpm(const std::string& tpmLocator);
118 
127  KeyChain();
128 
139  KeyChain(const std::string& pibLocator,
140  const std::string& tpmLocator,
141  bool allowReset = false);
142 
143  virtual
144  ~KeyChain();
145 
154  Name
155  createIdentity(const Name& identityName, const KeyParams& params = DEFAULT_KEY_PARAMS);
156 
166  Name
167  generateRsaKeyPair(const Name& identityName, bool isKsk = false, uint32_t keySize = 2048);
168 
178  Name
179  generateEcdsaKeyPair(const Name& identityName, bool isKsk = false, uint32_t keySize = 256);
180 
191  Name
192  generateRsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, uint32_t keySize = 2048);
193 
204  Name
205  generateEcdsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, uint32_t keySize = 256);
206 
222  shared_ptr<v1::IdentityCertificate>
224  const Name& signingIdentity,
225  const time::system_clock::TimePoint& notBefore,
226  const time::system_clock::TimePoint& notAfter,
227  const std::vector<security::v1::CertificateSubjectDescription>& subjectDescription,
228  const Name& certPrefix = DEFAULT_PREFIX);
229 
246  shared_ptr<v1::IdentityCertificate>
248  const v1::PublicKey& publicKey,
249  const Name& signingIdentity,
250  const time::system_clock::TimePoint& notBefore,
251  const time::system_clock::TimePoint& notAfter,
252  const std::vector<security::v1::CertificateSubjectDescription>& subjectDescription,
253  const Name& certPrefix = DEFAULT_PREFIX);
254 
271  void
272  sign(Data& data, const SigningInfo& params = DEFAULT_SIGNING_INFO);
273 
290  void
291  sign(Interest& interest, const SigningInfo& params = DEFAULT_SIGNING_INFO);
292 
303  Block
304  sign(const uint8_t* buffer, size_t bufferLength, const SigningInfo& params);
305 
314  template<typename T>
315  void
316  sign(T& packet, const Name& certificateName);
317 
328  Signature
329  sign(const uint8_t* buffer, size_t bufferLength, const Name& certificateName);
330 
341  template<typename T>
342  void
343  signByIdentity(T& packet, const Name& identityName);
344 
354  Signature
355  signByIdentity(const uint8_t* buffer, size_t bufferLength, const Name& identityName);
356 
361  void
362  signWithSha256(Data& data);
363 
368  void
369  signWithSha256(Interest& interest);
370 
377  shared_ptr<v1::IdentityCertificate>
378  selfSign(const Name& keyName);
379 
386  void
388 
395  void
396  deleteCertificate(const Name& certificateName);
397 
404  void
405  deleteKey(const Name& keyName);
406 
413  void
414  deleteIdentity(const Name& identity);
415 
424  shared_ptr<SecuredBag>
425  exportIdentity(const Name& identity, const std::string& passwordStr);
426 
433  void
434  importIdentity(const SecuredBag& securedBag, const std::string& passwordStr);
435 
438  {
439  return *m_pib;
440  }
441 
442  const SecPublicInfo&
443  getPib() const
444  {
445  return *m_pib;
446  }
447 
448  SecTpm&
450  {
451  return *m_tpm;
452  }
453 
454  const SecTpm&
455  getTpm() const
456  {
457  return *m_tpm;
458  }
459 
460  /*******************************
461  * Wrapper of SecPublicInfo *
462  *******************************/
463  bool
464  doesIdentityExist(const Name& identityName) const
465  {
466  return m_pib->doesIdentityExist(identityName);
467  }
468 
469  void
470  addIdentity(const Name& identityName)
471  {
472  return m_pib->addIdentity(identityName);
473  }
474 
475  bool
476  doesPublicKeyExist(const Name& keyName) const
477  {
478  return m_pib->doesPublicKeyExist(keyName);
479  }
480 
481  void
482  addPublicKey(const Name& keyName, KeyType keyType, const v1::PublicKey& publicKeyDer)
483  {
484  return m_pib->addKey(keyName, publicKeyDer);
485  }
486 
487  void
488  addKey(const Name& keyName, const v1::PublicKey& publicKeyDer)
489  {
490  return m_pib->addKey(keyName, publicKeyDer);
491  }
492 
493  shared_ptr<v1::PublicKey>
494  getPublicKey(const Name& keyName) const
495  {
496  return m_pib->getPublicKey(keyName);
497  }
498 
499  bool
500  doesCertificateExist(const Name& certificateName) const
501  {
502  return m_pib->doesCertificateExist(certificateName);
503  }
504 
505  void
507  {
508  return m_pib->addCertificate(certificate);
509  }
510 
511  shared_ptr<v1::IdentityCertificate>
512  getCertificate(const Name& certificateName) const
513  {
514  return m_pib->getCertificate(certificateName);
515  }
516 
517  Name
519  {
520  return m_pib->getDefaultIdentity();
521  }
522 
523  Name
524  getDefaultKeyNameForIdentity(const Name& identityName) const
525  {
526  return m_pib->getDefaultKeyNameForIdentity(identityName);
527  }
528 
536  const KeyParams&
537  getDefaultKeyParamsForIdentity(const Name& identityName) const;
538 
539  Name
540  getDefaultCertificateNameForKey(const Name& keyName) const
541  {
542  return m_pib->getDefaultCertificateNameForKey(keyName);
543  }
544 
545  void
546  getAllIdentities(std::vector<Name>& nameList, bool isDefault) const
547  {
548  return m_pib->getAllIdentities(nameList, isDefault);
549  }
550 
551  void
552  getAllKeyNames(std::vector<Name>& nameList, bool isDefault) const
553  {
554  return m_pib->getAllKeyNames(nameList, isDefault);
555  }
556 
557  void
558  getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault) const
559  {
560  return m_pib->getAllKeyNamesOfIdentity(identity, nameList, isDefault);
561  }
562 
563  void
564  getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) const
565  {
566  return m_pib->getAllCertificateNames(nameList, isDefault);
567  }
568 
569  void
571  std::vector<Name>& nameList,
572  bool isDefault) const
573  {
574  return m_pib->getAllCertificateNamesOfKey(keyName, nameList, isDefault);
575  }
576 
577  void
578  deleteCertificateInfo(const Name& certificateName)
579  {
580  return m_pib->deleteCertificateInfo(certificateName);
581  }
582 
583  void
584  deletePublicKeyInfo(const Name& keyName)
585  {
586  return m_pib->deletePublicKeyInfo(keyName);
587  }
588 
589  void
590  deleteIdentityInfo(const Name& identity)
591  {
592  return m_pib->deleteIdentityInfo(identity);
593  }
594 
595  void
596  setDefaultIdentity(const Name& identityName)
597  {
598  return m_pib->setDefaultIdentity(identityName);
599  }
600 
601  void
603  {
604  return m_pib->setDefaultKeyNameForIdentity(keyName);
605  }
606 
607  void
608  setDefaultCertificateNameForKey(const Name& certificateName)
609  {
610  return m_pib->setDefaultCertificateNameForKey(certificateName);
611  }
612 
613  Name
614  getNewKeyName(const Name& identityName, bool useKsk)
615  {
616  return m_pib->getNewKeyName(identityName, useKsk);
617  }
618 
619  Name
620  getDefaultCertificateNameForIdentity(const Name& identityName) const
621  {
622  return m_pib->getDefaultCertificateNameForIdentity(identityName);
623  }
624 
625  Name
627  {
628  return m_pib->getDefaultCertificateName();
629  }
630 
631  void
633  {
634  return m_pib->addCertificateAsKeyDefault(certificate);
635  }
636 
637  void
639  {
640  return m_pib->addCertificateAsIdentityDefault(certificate);
641  }
642 
643  void
645  {
646  return m_pib->addCertificateAsSystemDefault(certificate);
647  }
648 
649  shared_ptr<v1::IdentityCertificate>
651  {
652  if (!static_cast<bool>(m_pib->getDefaultCertificate()))
653  const_cast<KeyChain*>(this)->setDefaultCertificateInternal();
654 
655  return m_pib->getDefaultCertificate();
656  }
657 
658  void
660  {
661  return m_pib->refreshDefaultCertificate();
662  }
663 
664  /*******************************
665  * Wrapper of SecTpm *
666  *******************************/
667 
668  void
669  setTpmPassword(const uint8_t* password, size_t passwordLength)
670  {
671  return m_tpm->setTpmPassword(password, passwordLength);
672  }
673 
674  void
676  {
677  return m_tpm->resetTpmPassword();
678  }
679 
680  void
681  setInTerminal(bool inTerminal)
682  {
683  return m_tpm->setInTerminal(inTerminal);
684  }
685 
686  bool
688  {
689  return m_tpm->getInTerminal();
690  }
691 
692  bool
693  isLocked() const
694  {
695  return m_tpm->isLocked();
696  }
697 
698  bool
699  unlockTpm(const char* password, size_t passwordLength, bool usePassword)
700  {
701  return m_tpm->unlockTpm(password, passwordLength, usePassword);
702  }
703 
704  void
705  generateKeyPairInTpm(const Name& keyName, const KeyParams& params)
706  {
707  return m_tpm->generateKeyPairInTpm(keyName, params);
708  }
709 
710  void
711  deleteKeyPairInTpm(const Name& keyName)
712  {
713  return m_tpm->deleteKeyPairInTpm(keyName);
714  }
715 
716  shared_ptr<v1::PublicKey>
717  getPublicKeyFromTpm(const Name& keyName) const
718  {
719  return m_tpm->getPublicKeyFromTpm(keyName);
720  }
721 
722  Block
723  signInTpm(const uint8_t* data, size_t dataLength,
724  const Name& keyName,
725  DigestAlgorithm digestAlgorithm)
726  {
727  return m_tpm->signInTpm(data, dataLength, keyName, digestAlgorithm);
728  }
729 
731  decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric)
732  {
733  return m_tpm->decryptInTpm(data, dataLength, keyName, isSymmetric);
734  }
735 
737  encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric)
738  {
739  return m_tpm->encryptInTpm(data, dataLength, keyName, isSymmetric);
740  }
741 
742  void
743  generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params)
744  {
745  return m_tpm->generateSymmetricKeyInTpm(keyName, params);
746  }
747 
748  bool
749  doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) const
750  {
751  return m_tpm->doesKeyExistInTpm(keyName, keyClass);
752  }
753 
754  bool
755  generateRandomBlock(uint8_t* res, size_t size) const
756  {
757  return m_tpm->generateRandomBlock(res, size);
758  }
759 
760  void
761  addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl)
762  {
763  return m_tpm->addAppToAcl(keyName, keyClass, appPath, acl);
764  }
765 
767  exportPrivateKeyPkcs5FromTpm(const Name& keyName, const std::string& password)
768  {
769  return m_tpm->exportPrivateKeyPkcs5FromTpm(keyName, password);
770  }
771 
772  bool
774  const uint8_t* buf, size_t size,
775  const std::string& password)
776  {
777  return m_tpm->importPrivateKeyPkcs5IntoTpm(keyName, buf, size, password);
778  }
779 
780 private:
781  void
782  initialize(const std::string& pibLocatorUri,
783  const std::string& tpmLocatorUri,
784  bool needReset);
785 
793  std::tuple<Name, SignatureInfo>
794  prepareSignatureInfo(const SigningInfo& params);
795 
803  template<typename T>
804  void
805  signImpl(T& packet, const SigningInfo& params);
806 
810  void
811  setDefaultCertificateInternal();
812 
821  Name
822  generateKeyPair(const Name& identityName, bool isKsk = false,
823  const KeyParams& params = DEFAULT_KEY_PARAMS);
824 
834  void
835  signPacketWrapper(Data& data, const Signature& signature,
836  const Name& keyName, DigestAlgorithm digestAlgorithm);
837 
847  void
848  signPacketWrapper(Interest& interest, const Signature& signature,
849  const Name& keyName, DigestAlgorithm digestAlgorithm);
850 
855  Block
856  pureSign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const;
857 
858  static void
859  registerPibImpl(const std::string& canonicalName,
860  std::initializer_list<std::string> aliases, PibCreateFunc createFunc);
861 
862  static void
863  registerTpmImpl(const std::string& canonicalName,
864  std::initializer_list<std::string> aliases, TpmCreateFunc createFunc);
865 
866 public:
868  getSignatureType(KeyType keyType, DigestAlgorithm digestAlgorithm);
869 
870 public:
871  static const Name DEFAULT_PREFIX;
873 
879 
880  // RsaKeyParams is set to be default for backward compatibility.
882 
883  typedef std::map<std::string, Block> SignParams;
884 
885 private:
886  std::unique_ptr<SecPublicInfo> m_pib;
887  std::unique_ptr<SecTpm> m_tpm;
888  time::milliseconds m_lastTimestamp;
889 };
890 
891 template<typename T>
892 void
893 KeyChain::signImpl(T& packet, const SigningInfo& params)
894 {
895  Name keyName;
896  SignatureInfo sigInfo;
897  std::tie(keyName, sigInfo) = prepareSignatureInfo(params);
898 
899  signPacketWrapper(packet, Signature(sigInfo),
900  keyName, params.getDigestAlgorithm());
901 }
902 
903 template<typename T>
904 void
905 KeyChain::sign(T& packet, const Name& certificateName)
906 {
907  signImpl(packet, SigningInfo(SigningInfo::SIGNER_TYPE_CERT, certificateName));
908 }
909 
910 template<typename T>
911 void
912 KeyChain::signByIdentity(T& packet, const Name& identityName)
913 {
914  signImpl(packet, SigningInfo(SigningInfo::SIGNER_TYPE_ID, identityName));
915 }
916 
917 template<class PibType>
918 inline void
919 KeyChain::registerPib(std::initializer_list<std::string> aliases)
920 {
921  registerPibImpl(*aliases.begin(), aliases, [] (const std::string& locator) {
922  return make_unique<PibType>(locator);
923  });
924 }
925 
926 template<class TpmType>
927 inline void
928 KeyChain::registerTpm(std::initializer_list<std::string> aliases)
929 {
930  registerTpmImpl(*aliases.begin(), aliases, [] (const std::string& locator) {
931  return make_unique<TpmType>(locator);
932  });
933 }
934 
941 #define NDN_CXX_KEYCHAIN_REGISTER_PIB(PibType, ...) \
942 static class NdnCxxAuto ## PibType ## PibRegistrationClass \
943 { \
944 public: \
945  NdnCxxAuto ## PibType ## PibRegistrationClass() \
946  { \
947  ::ndn::KeyChain::registerPib<PibType>({__VA_ARGS__}); \
948  } \
949 } ndnCxxAuto ## PibType ## PibRegistrationVariable
950 
957 #define NDN_CXX_KEYCHAIN_REGISTER_TPM(TpmType, ...) \
958 static class NdnCxxAuto ## TpmType ## TpmRegistrationClass \
959 { \
960 public: \
961  NdnCxxAuto ## TpmType ## TpmRegistrationClass() \
962  { \
963  ::ndn::KeyChain::registerTpm<TpmType>({__VA_ARGS__}); \
964  } \
965 } ndnCxxAuto ## TpmType ## TpmRegistrationVariable
966 
967 } // namespace security
968 
969 using security::KeyChain;
970 
971 } // namespace ndn
972 
973 #endif // NDN_SECURITY_KEY_CHAIN_HPP
static const RsaKeyParams DEFAULT_KEY_PARAMS
Definition: key-chain.hpp:881
const SecPublicInfo & getPib() const
Definition: key-chain.hpp:443
void addCertificateAsIdentityDefault(const v1::IdentityCertificate &certificate)
Definition: key-chain.hpp:638
Name getNewKeyName(const Name &identityName, bool useKsk)
Definition: key-chain.hpp:614
bool unlockTpm(const char *password, size_t passwordLength, bool usePassword)
Definition: key-chain.hpp:699
const SecTpm & getTpm() const
Definition: key-chain.hpp:455
MismatchError(const std::string &what)
Definition: key-chain.hpp:68
Copyright (c) 2011-2015 Regents of the University of California.
function< unique_ptr< SecPublicInfo >const std::string &)> PibCreateFunc
Definition: key-chain.hpp:74
bool doesCertificateExist(const Name &certificateName) const
Definition: key-chain.hpp:500
Name getDefaultCertificateName() const
Definition: key-chain.hpp:626
shared_ptr< v1::IdentityCertificate > getCertificate(const Name &certificateName) const
Definition: key-chain.hpp:512
bool doesIdentityExist(const Name &identityName) const
Definition: key-chain.hpp:464
void getAllIdentities(std::vector< Name > &nameList, bool isDefault) const
Definition: key-chain.hpp:546
void addIdentity(const Name &identityName)
Definition: key-chain.hpp:470
void importIdentity(const SecuredBag &securedBag, const std::string &passwordStr)
import an identity.
Definition: key-chain.cpp:632
void setDefaultIdentity(const Name &identityName)
Definition: key-chain.hpp:596
shared_ptr< v1::IdentityCertificate > getDefaultCertificate() const
Definition: key-chain.hpp:650
static unique_ptr< SecPublicInfo > createPib(const std::string &pibLocator)
Create a PIB according to pibLocator.
Definition: key-chain.cpp:207
Name getDefaultCertificateNameForIdentity(const Name &identityName) const
Definition: key-chain.hpp:620
DigestAlgorithm getDigestAlgorithm() const
The packet signing interface.
Definition: key-chain.hpp:47
void signByIdentity(T &packet, const Name &identityName)
Sign packet using the default certificate of a particular identity.
Definition: key-chain.hpp:912
void generateSymmetricKeyInTpm(const Name &keyName, const KeyParams &params)
Definition: key-chain.hpp:743
SecTpm is the base class of the TPM classes.
Definition: sec-tpm.hpp:42
bool doesKeyExistInTpm(const Name &keyName, KeyClass keyClass) const
Definition: key-chain.hpp:749
STL namespace.
ConstBufferPtr encryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Definition: key-chain.hpp:737
Error thrown when the supplied TPM locator to KeyChain constructor does not match the locator stored ...
Definition: key-chain.hpp:64
shared_ptr< v1::IdentityCertificate > selfSign(const Name &keyName)
Generate a self-signed certificate for a public key.
Definition: key-chain.cpp:557
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
represents an Interest packet
Definition: interest.hpp:42
void deleteKeyPairInTpm(const Name &keyName)
Definition: key-chain.hpp:711
void sign(Data &data, const SigningInfo &params=DEFAULT_SIGNING_INFO)
Sign data according to the supplied signing information.
Definition: key-chain.cpp:517
void setTpmPassword(const uint8_t *password, size_t passwordLength)
Definition: key-chain.hpp:669
Signing parameters passed to KeyChain.
shared_ptr< SecuredBag > exportIdentity(const Name &identity, const std::string &passwordStr)
export an identity.
Definition: key-chain.cpp:603
void getAllCertificateNames(std::vector< Name > &nameList, bool isDefault) const
Definition: key-chain.hpp:564
static void registerPib(std::initializer_list< std::string > aliases)
Register a new PIB.
Definition: key-chain.hpp:919
shared_ptr< v1::PublicKey > getPublicKeyFromTpm(const Name &keyName) const
Definition: key-chain.hpp:717
Name generateEcdsaKeyPairAsDefault(const Name &identityName, bool isKsk=false, uint32_t keySize=256)
Generate a pair of ECDSA keys for the specified identity and set it as default key for the identity...
Definition: key-chain.cpp:353
bool doesPublicKeyExist(const Name &keyName) const
Definition: key-chain.hpp:476
static const SigningInfo DEFAULT_SIGNING_INFO
Definition: key-chain.hpp:872
void generateKeyPairInTpm(const Name &keyName, const KeyParams &params)
Definition: key-chain.hpp:705
Name getDefaultCertificateNameForKey(const Name &keyName) const
Definition: key-chain.hpp:540
Name createIdentity(const Name &identityName, const KeyParams &params=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.cpp:293
void addPublicKey(const Name &keyName, KeyType keyType, const v1::PublicKey &publicKeyDer)
Definition: key-chain.hpp:482
SecPublicInfo & getPib()
Definition: key-chain.hpp:437
function< unique_ptr< SecTpm >const std::string &)> TpmCreateFunc
Definition: key-chain.hpp:75
static std::string getDefaultTpmLocator()
Get default TPM locator.
Definition: key-chain.cpp:219
void addAppToAcl(const Name &keyName, KeyClass keyClass, const std::string &appPath, AclType acl)
Definition: key-chain.hpp:761
void addKey(const Name &keyName, const v1::PublicKey &publicKeyDer)
Definition: key-chain.hpp:488
bool generateRandomBlock(uint8_t *res, size_t size) const
Definition: key-chain.hpp:755
void setInTerminal(bool inTerminal)
Definition: key-chain.hpp:681
void getAllCertificateNamesOfKey(const Name &keyName, std::vector< Name > &nameList, bool isDefault) const
Definition: key-chain.hpp:570
std::map< std::string, Block > SignParams
Definition: key-chain.hpp:883
void deletePublicKeyInfo(const Name &keyName)
Definition: key-chain.hpp:584
Block signInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm)
Definition: key-chain.hpp:723
Name abstraction to represent an absolute name.
Definition: name.hpp:46
signer is a certificate, use it directly
shared_ptr< v1::PublicKey > getPublicKey(const Name &keyName) const
Definition: key-chain.hpp:494
Name getDefaultKeyNameForIdentity(const Name &identityName) const
Definition: key-chain.hpp:524
void deleteIdentity(const Name &identity)
delete an identity.
Definition: key-chain.cpp:819
void deleteIdentityInfo(const Name &identity)
Definition: key-chain.hpp:590
time_point TimePoint
Definition: time.hpp:90
Name generateRsaKeyPair(const Name &identityName, bool isKsk=false, uint32_t keySize=2048)
Generate a pair of RSA keys for the specified identity.
Definition: key-chain.cpp:327
void addCertificate(const v1::IdentityCertificate &certificate)
Definition: key-chain.hpp:506
static tlv::SignatureTypeValue getSignatureType(KeyType keyType, DigestAlgorithm digestAlgorithm)
Definition: key-chain.cpp:832
KeyChain()
Constructor to create KeyChain with default PIB and TPM.
Definition: key-chain.cpp:121
static unique_ptr< SecTpm > createTpm(const std::string &tpmLocator)
Create a TPM according to tpmLocator.
Definition: key-chain.cpp:244
static std::string getDefaultPibLocator()
Get default PIB locator.
Definition: key-chain.cpp:181
SecPublicInfo is a base class for the storage of public information.
SignatureTypeValue
Definition: tlv.hpp:95
void addCertificateAsKeyDefault(const v1::IdentityCertificate &certificate)
Definition: key-chain.hpp:632
Base class of key parameters.
Definition: key-params.hpp:35
signer is an identity, use its default key and default certificate
void getAllKeyNamesOfIdentity(const Name &identity, std::vector< Name > &nameList, bool isDefault) const
Definition: key-chain.hpp:558
Name generateEcdsaKeyPair(const Name &identityName, bool isKsk=false, uint32_t keySize=256)
Generate a pair of ECDSA keys for the specified identity.
Definition: key-chain.cpp:334
void getAllKeyNames(std::vector< Name > &nameList, bool isDefault) const
Definition: key-chain.hpp:552
ConstBufferPtr decryptInTpm(const uint8_t *data, size_t dataLength, const Name &keyName, bool isSymmetric)
Definition: key-chain.hpp:731
void setDefaultKeyNameForIdentity(const Name &keyName)
Definition: key-chain.hpp:602
void addCertificateAsSystemDefault(const v1::IdentityCertificate &certificate)
Definition: key-chain.hpp:644
static const Name DEFAULT_PREFIX
Definition: key-chain.hpp:871
Name getDefaultIdentity() const
Definition: key-chain.hpp:518
bool getInTerminal() const
Definition: key-chain.hpp:687
void signWithSha256(Data &data)
Set Sha256 weak signature for data.
Definition: key-chain.cpp:776
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33
void setDefaultCertificateNameForKey(const Name &certificateName)
Definition: key-chain.hpp:608
const KeyParams & getDefaultKeyParamsForIdentity(const Name &identityName) const
Get default key parameters for the specified identity.
Definition: key-chain.cpp:657
represents a Data packet
Definition: data.hpp:37
SimplePublicKeyParams is a template for public keys with only one parameter: size.
Definition: key-params.hpp:110
shared_ptr< v1::IdentityCertificate > prepareUnsignedIdentityCertificate(const Name &keyName, const Name &signingIdentity, const time::system_clock::TimePoint &notBefore, const time::system_clock::TimePoint &notAfter, const std::vector< security::v1::CertificateSubjectDescription > &subjectDescription, const Name &certPrefix=DEFAULT_PREFIX)
prepare an unsigned identity certificate
Definition: key-chain.cpp:366
Name generateRsaKeyPairAsDefault(const Name &identityName, bool isKsk=false, uint32_t keySize=2048)
Generate a pair of RSA keys for the specified identity and set it as default key for the identity...
Definition: key-chain.cpp:341
static const Name DIGEST_SHA256_IDENTITY
A localhost identity which indicates that signature is generated using SHA-256.
Definition: key-chain.hpp:878
void deleteCertificateInfo(const Name &certificateName)
Definition: key-chain.hpp:578
void deleteKey(const Name &keyName)
delete a key.
Definition: key-chain.cpp:812
static void registerTpm(std::initializer_list< std::string > aliases)
Register a new TPM.
Definition: key-chain.hpp:928
ConstBufferPtr exportPrivateKeyPkcs5FromTpm(const Name &keyName, const std::string &password)
Definition: key-chain.hpp:767
void deleteCertificate(const Name &certificateName)
delete a certificate.
Definition: key-chain.cpp:806
bool importPrivateKeyPkcs5IntoTpm(const Name &keyName, const uint8_t *buf, size_t size, const std::string &password)
Definition: key-chain.hpp:773
Error(const std::string &what)
Definition: key-chain.hpp:54
A Signature is storage for the signature-related information (info and value) in a Data packet...
Definition: signature.hpp:33