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 
38 public:
46  (const ptr_lib::shared_ptr<IdentityStorage>& identityStorage,
47  const ptr_lib::shared_ptr<PrivateKeyStorage>& privateKeyStorage);
48 
55  IdentityManager(const ptr_lib::shared_ptr<IdentityStorage>& identityStorage);
56 
64 
73  Name
74  createIdentityAndCertificate(const Name& identityName, const KeyParams& params);
75 
87  Name
88  DEPRECATED_IN_NDN_CPP createIdentity
89  (const Name& identityName, const KeyParams& params)
90  {
92  (createIdentityAndCertificate(identityName, params));
93  }
94 
114  ptr_lib::shared_ptr<IdentityCertificate>
116  (const Name& keyName, const Name& signingIdentity,
117  MillisecondsSince1970 notBefore, MillisecondsSince1970 notAfter,
118  std::vector<CertificateSubjectDescription>& subjectDescription,
119  const Name* certPrefix = 0);
120 
140  ptr_lib::shared_ptr<IdentityCertificate>
142  (const Name& keyName, const PublicKey& publicKey,
143  const Name& signingIdentity, MillisecondsSince1970 notBefore,
144  MillisecondsSince1970 notAfter,
145  std::vector<CertificateSubjectDescription>& subjectDescription,
146  const Name* certPrefix = 0);
147 
154  void
155  deleteIdentity(const Name& identityName);
156 
162  void
163  setDefaultIdentity(const Name& identityName)
164  {
165  identityStorage_->setDefaultIdentity(identityName);
166  }
167 
173  Name
175  {
176  return identityStorage_->getDefaultIdentity();
177  }
178 
184  ptr_lib::shared_ptr<IdentityCertificate>
186  {
187  return identityStorage_->getDefaultCertificate();
188  }
189 
199  Name
200  generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048);
201 
211  Name
212  generateEcdsaKeyPair(const Name& identityName, bool isKsk = false, int keySize = 256);
213 
221  void
222  setDefaultKeyForIdentity(const Name& keyName, const Name& identityNameCheck = Name())
223  {
224  identityStorage_->setDefaultKeyNameForIdentity(keyName, identityNameCheck);
225  }
226 
233  Name
234  getDefaultKeyNameForIdentity(const Name& identityName)
235  {
236  return identityStorage_->getDefaultKeyNameForIdentity(identityName);
237  }
238 
248  Name
249  generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048);
250 
260  Name
261  generateEcdsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 256);
262 
268  ptr_lib::shared_ptr<PublicKey>
269  getPublicKey(const Name& keyName)
270  {
271  return ptr_lib::shared_ptr<PublicKey>(new PublicKey
272  (identityStorage_->getKey(keyName)));
273  }
274 
283  Name
285  (const Name& certificatePrefix, const Name& signerCertificateName, const MillisecondsSince1970& notBefore,
286  const MillisecondsSince1970& notAfter);
287 
297  ptr_lib::shared_ptr<IdentityCertificate>
299  (const Name& certificatePrefix, const PublicKey& publickey, const Name& signerCertificateName,
300  const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter);
301 
306  void
308  {
309  identityStorage_->addCertificate(certificate);
310  }
311 
316  void
318 
323  void
325 
330  void
331  addCertificateAsDefault(const IdentityCertificate& certificate);
332 
338  ptr_lib::shared_ptr<IdentityCertificate>
339  getCertificate(const Name& certificateName)
340  {
341  return identityStorage_->getCertificate(certificateName);
342  }
343 
351  Name
353  {
354  return identityStorage_->getDefaultCertificateNameForIdentity(identityName);
355  }
356 
365  Name
367  {
368  return identityStorage_->getDefaultCertificateNameForIdentity(getDefaultIdentity());
369  }
370 
377  void
378  getAllIdentities(std::vector<Name>& nameList, bool isDefault)
379  {
380  identityStorage_->getAllIdentities(nameList, isDefault);
381  }
382 
390  void
392  (const Name& identityName, std::vector<Name>& nameList, bool isDefault)
393  {
394  identityStorage_->getAllKeyNamesOfIdentity(identityName, nameList, isDefault);
395  }
396 
404  void
406  (const Name& keyName, std::vector<Name>& nameList, bool isDefault)
407  {
408  identityStorage_->getAllCertificateNamesOfKey(keyName, nameList, isDefault);
409  }
410 
418  ptr_lib::shared_ptr<Signature>
419  signByCertificate(const uint8_t* buffer, size_t bufferLength, const Name& certificateName);
420 
427  ptr_lib::shared_ptr<Signature>
428  signByCertificate(const std::vector<uint8_t>& buffer, const Name& certificateName)
429  {
430  return signByCertificate(&buffer[0], buffer.size(), certificateName);
431  }
432 
439  void
440  signByCertificate(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
441 
451  void
453  (Interest& interest, const Name& certificateName,
455 
464  void
466  (Data& data, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
467 
477  void
479  (Interest& interest, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
480 
486  ptr_lib::shared_ptr<IdentityCertificate>
487  selfSign(const Name& keyName);
488 
489 private:
497  Name
498  generateKeyPair(const Name& identityName, bool isKsk, const KeyParams& params);
499 
500  static Name
501  getKeyNameFromCertificatePrefix(const Name& certificatePrefix);
502 
511  ptr_lib::shared_ptr<Signature>
512  makeSignatureByCertificate
513  (const Name& certificateName, DigestAlgorithm& digestAlgorithm);
514 
515  ptr_lib::shared_ptr<IdentityStorage> identityStorage_;
516  ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage_;
517 };
518 
519 }
520 
521 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
ptr_lib::shared_ptr< IdentityCertificate > getDefaultCertificate()
Get the certificate of the default identity.
Definition: identity-manager.hpp:185
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:339
Name getDefaultKeyNameForIdentity(const Name &identityName)
Get the default key for an identity.
Definition: identity-manager.hpp:234
void getAllIdentities(std::vector< Name > &nameList, bool isDefault)
Append all the identity names to the nameList.
Definition: identity-manager.hpp:378
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:402
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:392
void setDefaultIdentity(const Name &identityName)
Set the default identity.
Definition: identity-manager.hpp:163
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:222
Name getDefaultIdentity()
Get the default identity.
Definition: identity-manager.hpp:174
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:192
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:207
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:352
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:371
void deleteIdentity(const Name &identityName)
Delete the identity from the public and private key storage.
Definition: identity-manager.cpp:158
An IdentityManager is the interface of operations related to identity, keys, and certificates.
Definition: identity-manager.hpp:37
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:482
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
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:121
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:462
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:217
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
KeyParams is a base class for key parameters.
Definition: key-params.hpp:34
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:225
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:428
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:406
void addCertificate(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage.
Definition: identity-manager.hpp:307
ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)
Get the public key with the specified name.
Definition: identity-manager.hpp:269
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:379
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:366
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:200
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:438
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:89
IdentityManager()
Create a new IdentityManager to use BasicIdentityStorage and the default PrivateKeyStorage for your s...
Definition: identity-manager.cpp:110
void setDefaultCertificateForKey(const IdentityCertificate &certificate)
Set the certificate as the default for its corresponding key.
Definition: identity-manager.cpp:391
ptr_lib::shared_ptr< IdentityCertificate > selfSign(const Name &keyName)
Generate a self-signed certificate for a public key.
Definition: identity-manager.cpp:505