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 
101  void
102  deleteIdentity(const Name& identityName);
103 
109  void
110  setDefaultIdentity(const Name& identityName)
111  {
112  identityStorage_->setDefaultIdentity(identityName);
113  }
114 
120  Name
122  {
123  return identityStorage_->getDefaultIdentity();
124  }
125 
135  Name
136  generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048);
137 
147  Name
148  generateEcdsaKeyPair(const Name& identityName, bool isKsk = false, int keySize = 256);
149 
156  void
157  setDefaultKeyForIdentity(const Name& keyName, const Name& identityName = Name())
158  {
159  identityStorage_->setDefaultKeyNameForIdentity(keyName, identityName);
160  }
161 
168  Name
169  getDefaultKeyNameForIdentity(const Name& identityName)
170  {
171  return identityStorage_->getDefaultKeyNameForIdentity(identityName);
172  }
173 
183  Name
184  generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048);
185 
195  Name
196  generateEcdsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 256);
197 
203  ptr_lib::shared_ptr<PublicKey>
204  getPublicKey(const Name& keyName)
205  {
206  return ptr_lib::shared_ptr<PublicKey>(new PublicKey
207  (identityStorage_->getKey(keyName)));
208  }
209 
218  Name
220  (const Name& certificatePrefix, const Name& signerCertificateName, const MillisecondsSince1970& notBefore,
221  const MillisecondsSince1970& notAfter);
222 
232  ptr_lib::shared_ptr<IdentityCertificate>
234  (const Name& certificatePrefix, const PublicKey& publickey, const Name& signerCertificateName,
235  const MillisecondsSince1970& notBefore, const MillisecondsSince1970& notAfter);
236 
241  void
243  {
244  identityStorage_->addCertificate(certificate);
245  }
246 
251  void
253 
258  void
260 
265  void
266  addCertificateAsDefault(const IdentityCertificate& certificate);
267 
273  ptr_lib::shared_ptr<IdentityCertificate>
274  getCertificate(const Name& certificateName)
275  {
276  return identityStorage_->getCertificate(certificateName, false);
277  }
278 
284  ptr_lib::shared_ptr<IdentityCertificate>
285  getAnyCertificate(const Name& certificateName)
286  {
287  return identityStorage_->getCertificate(certificateName, true);
288  }
289 
297  Name
299  {
300  return identityStorage_->getDefaultCertificateNameForIdentity(identityName);
301  }
302 
311  Name
313  {
314  return identityStorage_->getDefaultCertificateNameForIdentity(getDefaultIdentity());
315  }
316 
324  ptr_lib::shared_ptr<Signature>
325  signByCertificate(const uint8_t* buffer, size_t bufferLength, const Name& certificateName);
326 
333  ptr_lib::shared_ptr<Signature>
334  signByCertificate(const std::vector<uint8_t>& buffer, const Name& certificateName)
335  {
336  return signByCertificate(&buffer[0], buffer.size(), certificateName);
337  }
338 
345  void
346  signByCertificate(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
347 
357  void
359  (Interest& interest, const Name& certificateName,
361 
370  void
372  (Data& data, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
373 
383  void
385  (Interest& interest, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
386 
392  ptr_lib::shared_ptr<IdentityCertificate>
393  selfSign(const Name& keyName);
394 
395 private:
403  Name
404  generateKeyPair(const Name& identityName, bool isKsk, const KeyParams& params);
405 
406  static Name
407  getKeyNameFromCertificatePrefix(const Name& certificatePrefix);
408 
417  ptr_lib::shared_ptr<Signature>
418  makeSignatureByCertificate
419  (const Name& certificateName, DigestAlgorithm& digestAlgorithm);
420 
421  ptr_lib::shared_ptr<IdentityStorage> identityStorage_;
422  ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage_;
423 };
424 
425 }
426 
427 #endif
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
ptr_lib::shared_ptr< IdentityCertificate > getAnyCertificate(const Name &certificateName)
Get a certificate even if the certificate is not valid anymore.
Definition: identity-manager.hpp:285
ptr_lib::shared_ptr< IdentityCertificate > getCertificate(const Name &certificateName)
Get a certificate with the specified name.
Definition: identity-manager.hpp:274
Name getDefaultKeyNameForIdentity(const Name &identityName)
Get the default key for an identity.
Definition: identity-manager.hpp:169
Definition: data.hpp:36
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:302
void setDefaultIdentity(const Name &identityName)
Set the default identity.
Definition: identity-manager.hpp:110
Definition: identity-certificate.hpp:30
Name getDefaultIdentity()
Get the default identity.
Definition: identity-manager.hpp:121
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:171
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:186
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:298
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:271
void deleteIdentity(const Name &identityName)
Delete the identity from the public and private key storage.
Definition: identity-manager.cpp:137
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:42
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:382
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
void setDefaultKeyForIdentity(const Name &keyName, const Name &identityName=Name())
Set a key as the default key of an identity.
Definition: identity-manager.hpp:157
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:362
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:196
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:204
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:334
void addCertificate(const IdentityCertificate &certificate)
Add a certificate into the public key identity storage.
Definition: identity-manager.hpp:242
ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)
Get the public key with the specified name.
Definition: identity-manager.hpp:204
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:279
static WireFormat * getDefaultWireFormat()
Return the default WireFormat used by default encoding and decoding methods which was set with setDef...
Definition: wire-format.cpp:36
Name getDefaultCertificateName()
Get the default certificate name of the default identity, which will be used when signing is based on...
Definition: identity-manager.hpp:312
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:179
Definition: wire-format.hpp:37
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:338
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:291
ptr_lib::shared_ptr< IdentityCertificate > selfSign(const Name &keyName)
Generate a self-signed certificate for a public key.
Definition: identity-manager.cpp:405