| /** |
| * Copyright (C) 2013 Regents of the University of California. |
| * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| * See COPYING for copyright and distribution information. |
| */ |
| |
| #ifndef NDN_IDENTITY_MANAGER_HPP |
| #define NDN_IDENTITY_MANAGER_HPP |
| |
| #include "../../data.hpp" |
| #include "identity-storage.hpp" |
| #include "private-key-storage.hpp" |
| |
| namespace ndn { |
| |
| /** |
| * An IdentityManager is the interface of operations related to identity, keys, and certificates. |
| */ |
| class IdentityManager { |
| public: |
| IdentityManager(const ptr_lib::shared_ptr<IdentityStorage>& identityStorage, const ptr_lib::shared_ptr<PrivateKeyStorage>& privateKeyStorage) |
| : identityStorage_(identityStorage), privateKeyStorage_(privateKeyStorage) |
| { |
| } |
| |
| #if 0 |
| /** |
| * Create identity, by default it will create a pair of Key-Signing-Key(KSK) for this identity and a self-signed certificate of the KSK |
| * @param identityName the name of the identity |
| * @return the key name of the auto-generated KSK of the identity |
| */ |
| Name |
| createIdentity(const Name& identityName); |
| #endif |
| |
| /** |
| * Get the default identity. |
| * @return The default identity name. |
| */ |
| Name |
| getDefaultIdentity() |
| { |
| return identityStorage_->getDefaultIdentity(); |
| } |
| |
| #if 0 |
| /** |
| * Generate a pair of RSA keys for the specified identity |
| * @param identityName the name of the identity |
| * @param ksk create a KSK or not, true for KSK, false for DSK |
| * @param keySize the size of the key |
| * @return the generated key name |
| */ |
| Name |
| generateRSAKeyPair(const Name& identityName, bool ksk = false, int keySize = 2048); |
| |
| /** |
| * Set a key as the default key of an identity |
| * @param keyName the name of the key |
| * @param identityName the name of the identity, if not specified the identity name can be inferred from the keyName |
| */ |
| void |
| setDefaultKeyForIdentity(const Name& keyName, const Name& identityName = Name()); |
| |
| /** |
| * Generate a pair of RSA keys for the specified identity and set it as default key of the identity |
| * @param identityName the name of the identity |
| * @param ksk create a KSK or not, true for KSK, false for DSK |
| * @param keySize the size of the key |
| * @return the generated key name |
| */ |
| Name |
| generateRSAKeyPairAsDefault(const Name& identityName, bool ksk = false, int keySize = 2048); |
| |
| /** |
| * Get public key with the specified name |
| * @param keyName name of the key |
| * @return the public key |
| */ |
| Ptr<Publickey> |
| getPublickey(const Name& keyName); |
| |
| /** |
| * Add a certificate into the public storage |
| * @param certificate the certificate to to added |
| */ |
| void |
| addCertificate(Ptr<Certificate> certificate); |
| |
| /** |
| * Set the certificate as the default of its corresponding key |
| * @param certificateName name of the certificate |
| */ |
| void |
| setDefaultCertificateForKey(const Name& certificateName); |
| |
| /** |
| * Add a certificate into the public storage and set the certificate as the default of its corresponding identity |
| * @param certificate the certificate to be added |
| */ |
| void |
| addCertificateAsIdentityDefault(const Certificate& certificate); |
| |
| /** |
| * Add a certificate into the public storage and set the certificate as the default of its corresponding key |
| * certificate the certificate to be added |
| */ |
| void |
| addCertificateAsDefault(const Certificate& certificate); |
| |
| /** |
| * Get a certificate with the specified name |
| * @param certificateName name of the requested certificate |
| * @return the requested certificate |
| */ |
| Ptr<Certificate> |
| getCertificate(const Name& certificateName); |
| |
| /** |
| * Get a certificate even if the certificate is not valid anymore |
| * @param certificateName name of the requested certificate |
| * @return the requested certificate |
| */ |
| Ptr<Certificate> |
| getAnyCertificate(const Name& certificateName); |
| #endif |
| |
| /** |
| * Get the default certificate name for the specified identity, which will be used when signing is performed based on identity. |
| * @param identityName The name of the specified identity. |
| * @return The requested certificate name. |
| */ |
| Name |
| getDefaultCertificateNameForIdentity(const Name& identityName) |
| { |
| return identityStorage_->getDefaultCertificateNameForIdentity(identityName); |
| } |
| |
| /** |
| * Get the default certificate name of the default identity, which will be used when signing is based on identity and |
| * the identity is not specified. |
| * @return The requested certificate name. |
| */ |
| Name |
| getDefaultCertificateName() |
| { |
| return identityStorage_->getDefaultCertificateNameForIdentity(getDefaultIdentity()); |
| } |
| |
| #if 0 |
| /** |
| * Sign blob based on identity |
| * @param blob the blob to be signed |
| * @param identityName the signing identity name |
| * @return the generated signature |
| */ |
| Ptr<Signature> |
| signByIdentity(const Blob& blob, const Name& identityName); |
| |
| /** |
| * Sign data based on identity |
| * @param data the data packet to be signed, on return the Signature inside the data packet will be set |
| * @param identityName the signing identity name |
| */ |
| void |
| signByIdentity(Data& data, const Name& identityName); |
| |
| /** |
| * sign blob based on certificate name |
| * @param blob the blob to be signed |
| * @param certificateName the signing certificate name |
| * @return the generated signature |
| */ |
| Ptr<Signature> |
| signByCertificate(const Blob& blob, const Name& certificateName); |
| #endif |
| |
| /** |
| * Sign data packet based on the certificate name. |
| * Note: the caller must make sure the timestamp in data is correct, for example with |
| * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0). |
| * @param data The Data object to sign and update its signature. |
| * @param certificateName The Name identifying the certificate which identifies the signing key. |
| * @param wireFormat The WireFormat for calling encodeData, or WireFormat::getDefaultWireFormat() if omitted. |
| */ |
| void |
| signByCertificate(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
| |
| private: |
| ptr_lib::shared_ptr<IdentityStorage> identityStorage_; |
| ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage_; |
| }; |
| |
| } |
| |
| #endif |