identity-manager.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_IDENTITY_MANAGER_HPP
24 #define NDN_IDENTITY_MANAGER_HPP
25 
26 #include "../certificate/identity-certificate.hpp"
27 #include "../../interest.hpp"
28 #include "identity-storage.hpp"
29 #include "../certificate/public-key.hpp"
30 #include "private-key-storage.hpp"
31 
32 namespace ndn {
33 
34 class ConfigFile;
35 
40 public:
48  (const ptr_lib::shared_ptr<IdentityStorage>& identityStorage,
49  const ptr_lib::shared_ptr<PrivateKeyStorage>& privateKeyStorage);
50 
57  IdentityManager(const ptr_lib::shared_ptr<IdentityStorage>& identityStorage);
58 
66 
75  Name
76  createIdentityAndCertificate(const Name& identityName, const KeyParams& params);
77 
89  Name
90  DEPRECATED_IN_NDN_CPP createIdentity
91  (const Name& identityName, const KeyParams& params)
92  {
94  (createIdentityAndCertificate(identityName, params));
95  }
96 
116  ptr_lib::shared_ptr<IdentityCertificate>
118  (const Name& keyName, const Name& signingIdentity,
119  MillisecondsSince1970 notBefore, MillisecondsSince1970 notAfter,
120  std::vector<CertificateSubjectDescription>& subjectDescription,
121  const Name* certPrefix = 0);
122 
142  ptr_lib::shared_ptr<IdentityCertificate>
144  (const Name& keyName, const PublicKey& publicKey,
145  const Name& signingIdentity, MillisecondsSince1970 notBefore,
146  MillisecondsSince1970 notAfter,
147  std::vector<CertificateSubjectDescription>& subjectDescription,
148  const Name* certPrefix = 0);
149 
156  void
157  deleteIdentity(const Name& identityName);
158 
164  void
165  setDefaultIdentity(const Name& identityName)
166  {
167  identityStorage_->setDefaultIdentity(identityName);
168  }
169 
175  Name
177  {
178  return identityStorage_->getDefaultIdentity();
179  }
180 
186  ptr_lib::shared_ptr<IdentityCertificate>
188  {
189  return identityStorage_->getDefaultCertificate();
190  }
191 
201  Name
202  generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048);
203 
213  Name
214  generateEcdsaKeyPair(const Name& identityName, bool isKsk = false, int keySize = 256);
215 
223  void
224  setDefaultKeyForIdentity(const Name& keyName, const Name& identityNameCheck = Name())
225  {
226  identityStorage_->setDefaultKeyNameForIdentity(keyName, identityNameCheck);
227  }
228 
235  Name
236  getDefaultKeyNameForIdentity(const Name& identityName)
237  {
238  return identityStorage_->getDefaultKeyNameForIdentity(identityName);
239  }
240 
250  Name
251  generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048);
252 
262  Name
263  generateEcdsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 256);
264 
270  ptr_lib::shared_ptr<PublicKey>
271  getPublicKey(const Name& keyName)
272  {
273  return ptr_lib::shared_ptr<PublicKey>(new PublicKey
274  (identityStorage_->getKey(keyName)));
275  }
276 
285  Name
287  (const Name& certificatePrefix, const Name& signerCertificateName, const MillisecondsSince1970& notBefore,
288  const MillisecondsSince1970& notAfter);
289 
299  ptr_lib::shared_ptr<IdentityCertificate>
301  (const Name& certificatePrefix, const PublicKey& publickey, const Name& signerCertificateName,
302  const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter);
303 
308  void
310  {
311  identityStorage_->addCertificate(certificate);
312  }
313 
318  void
320 
325  void
327 
332  void
333  addCertificateAsDefault(const IdentityCertificate& certificate);
334 
340  ptr_lib::shared_ptr<IdentityCertificate>
341  getCertificate(const Name& certificateName)
342  {
343  return identityStorage_->getCertificate(certificateName);
344  }
345 
353  Name
355  {
356  return identityStorage_->getDefaultCertificateNameForIdentity(identityName);
357  }
358 
367  Name
369  {
370  return identityStorage_->getDefaultCertificateNameForIdentity(getDefaultIdentity());
371  }
372 
379  void
380  getAllIdentities(std::vector<Name>& nameList, bool isDefault)
381  {
382  identityStorage_->getAllIdentities(nameList, isDefault);
383  }
384 
392  void
394  (const Name& identityName, std::vector<Name>& nameList, bool isDefault)
395  {
396  identityStorage_->getAllKeyNamesOfIdentity(identityName, nameList, isDefault);
397  }
398 
406  void
408  (const Name& keyName, std::vector<Name>& nameList, bool isDefault)
409  {
410  identityStorage_->getAllCertificateNamesOfKey(keyName, nameList, isDefault);
411  }
412 
420  ptr_lib::shared_ptr<Signature>
421  signByCertificate(const uint8_t* buffer, size_t bufferLength, const Name& certificateName);
422 
429  ptr_lib::shared_ptr<Signature>
430  signByCertificate(const std::vector<uint8_t>& buffer, const Name& certificateName)
431  {
432  return signByCertificate(&buffer[0], buffer.size(), certificateName);
433  }
434 
441  void
442  signByCertificate(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
443 
453  void
455  (Interest& interest, const Name& certificateName,
457 
466  void
468  (Data& data, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
469 
479  void
481  (Interest& interest, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
482 
488  ptr_lib::shared_ptr<IdentityCertificate>
489  selfSign(const Name& keyName);
490 
491 private:
499  Name
500  generateKeyPair(const Name& identityName, bool isKsk, const KeyParams& params);
501 
502  static Name
503  getKeyNameFromCertificatePrefix(const Name& certificatePrefix);
504 
513  ptr_lib::shared_ptr<Signature>
514  makeSignatureByCertificate
515  (const Name& certificateName, DigestAlgorithm& digestAlgorithm);
516 
523  static ptr_lib::shared_ptr<IdentityStorage>
524  getDefaultIdentityStorage(ConfigFile& config);
525 
534  static ptr_lib::shared_ptr<PrivateKeyStorage>
535  getDefaultPrivateKeyStorage
536  (ConfigFile& config, std::string& canonicalTpmLocator);
537 
545  void
546  checkTpm(const std::string& canonicalTpmLocator);
547 
548  ptr_lib::shared_ptr<IdentityStorage> identityStorage_;
549  ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage_;
550 };
551 
552 }
553 
554 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
ptr_lib::shared_ptr< IdentityCertificate > getDefaultCertificate()
Get the certificate of the default identity.
Definition: identity-manager.hpp:187
ptr_lib::shared_ptr< IdentityCertificate > prepareUnsignedIdentityCertificate(const Name &keyName, const Name &signingIdentity, MillisecondsSince1970 notBefore, MillisecondsSince1970 notAfter, std::vector< CertificateSubjectDescription > &subjectDescription, const Name *certPrefix=0)
Use the keyName to get the public key from the identity storage and prepare an unsigned identity cert...
ptr_lib::shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)
Get a certificate with the specified name.
Definition: identity-manager.hpp:341
Name getDefaultKeyNameForIdentity(const Name &identityName)
Get the default key for an identity.
Definition: identity-manager.hpp:236
void getAllIdentities(std::vector< Name > &nameList, bool isDefault)
Append all the identity names to the nameList.
Definition: identity-manager.hpp:380
Definition: data.hpp:37
ptr_lib::shared_ptr< Signature > signByCertificate(const uint8_t *buffer, size_t bufferLength, const Name &certificateName)
Sign the byte array data based on the certificate name.
Definition: identity-manager.cpp:436
void getAllKeyNamesOfIdentity(const Name &identityName, std::vector< Name > &nameList, bool isDefault)
Append all the key names of a particular identity to the nameList.
Definition: identity-manager.hpp:394
void setDefaultIdentity(const Name &identityName)
Set the default identity.
Definition: identity-manager.hpp:165
Definition: identity-certificate.hpp:30
void setDefaultKeyForIdentity(const Name &keyName, const Name &identityNameCheck=Name())
Set a key as the default key of an identity.
Definition: identity-manager.hpp:224
Name getDefaultIdentity()
Get the default identity.
Definition: identity-manager.hpp:176
Name generateRSAKeyPair(const Name &identityName, bool isKsk=false, int keySize=2048)
Generate a pair of RSA keys for the specified identity.
Definition: identity-manager.cpp:226
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: identity-manager.cpp:241
Name getDefaultCertificateNameForIdentity(const Name &identityName)
Get the default certificate name for the specified identity, which will be used when signing is perfo...
Definition: identity-manager.hpp:354
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
Definition: identity-certificate.cpp:101
void addCertificateAsDefault(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default of its ...
Definition: identity-manager.cpp:405
void deleteIdentity(const Name &identityName)
Delete the identity from the public and private key storage.
Definition: identity-manager.cpp:192
An IdentityManager is the interface of operations related to identity, keys, and certificates.
Definition: identity-manager.hpp:39
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
void signInterestWithSha256(Interest &interest, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Append a SignatureInfo for DigestSha256 to the Interest name, digest the name components and append a...
Definition: identity-manager.cpp:516
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:42
Name createIdentityAndCertificate(const Name &identityName, const KeyParams &params)
Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed ce...
Definition: identity-manager.cpp:155
Definition: public-key.hpp:34
void signWithSha256(Data &data, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Wire encode the Data object, digest it and set its SignatureInfo to a DigestSha256.
Definition: identity-manager.cpp:496
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: identity-manager.cpp:251
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:117
KeyParams is a base class for key parameters.
Definition: key-params.hpp:35
Name createIdentityCertificate(const Name &certificatePrefix, const Name &signerCertificateName, const MillisecondsSince1970 &notBefore, const MillisecondsSince1970 &notAfter)
Create an identity certificate for a public key managed by this IdentityManager.
Definition: identity-manager.cpp:259
ptr_lib::shared_ptr< Signature > signByCertificate(const std::vector< uint8_t > &buffer, const Name &certificateName)
Sign the byte array data based on the certificate name.
Definition: identity-manager.hpp:430
void getAllCertificateNamesOfKey(const Name &keyName, std::vector< Name > &nameList, bool isDefault)
Append all the certificate names of a particular key name to the nameList.
Definition: identity-manager.hpp:408
A ConfigFile locates, opens, and parses a library configuration file, and holds the values for the ap...
Definition: config-file.hpp:36
void addCertificate(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage.
Definition: identity-manager.hpp:309
ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)
Get the public key with the specified name.
Definition: identity-manager.hpp:271
void addCertificateAsIdentityDefault(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage and set the certificate as the default for its...
Definition: identity-manager.cpp:413
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:34
Name getDefaultCertificateName()
Get the default certificate name of the default identity, which will be used when signing is based on...
Definition: identity-manager.hpp:368
Name generateEcdsaKeyPair(const Name &identityName, bool isKsk=false, int keySize=256)
Generate a pair of ECDSA keys for the specified identity.
Definition: identity-manager.cpp:234
Definition: wire-format.hpp:39
void signInterestByCertificate(Interest &interest, const Name &certificateName, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
Append a SignatureInfo to the Interest name, sign the name components and append a final name compone...
Definition: identity-manager.cpp:472
Name DEPRECATED_IN_NDN_CPP createIdentity(const Name &identityName, const KeyParams &params)
Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed ce...
Definition: identity-manager.hpp:91
IdentityManager()
Create a new IdentityManager to use BasicIdentityStorage and the default PrivateKeyStorage for your s...
Definition: identity-manager.cpp:69
void setDefaultCertificateForKey(const IdentityCertificate &certificate)
Set the certificate as the default for its corresponding key.
Definition: identity-manager.cpp:425
ptr_lib::shared_ptr< IdentityCertificate > selfSign(const Name &keyName)
Generate a self-signed certificate for a public key.
Definition: identity-manager.cpp:539