Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
| 9 | #ifndef NDN_IDENTITY_STORAGE_HPP |
| 10 | #define NDN_IDENTITY_STORAGE_HPP |
| 11 | |
| 12 | #include "../../name.hpp" |
| 13 | #include "../security-common.hpp" |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | class Certificate; |
| 18 | class Data; |
| 19 | |
| 20 | /** |
| 21 | * IdentityStorage is a base class for the storage of identity, public keys and certificates. |
| 22 | * Private keys are stored in PrivateKeyStorage. |
| 23 | * This is an abstract base class. A subclass must implement the methods. |
| 24 | */ |
| 25 | class IdentityStorage { |
| 26 | public: |
| 27 | /** |
| 28 | * The virtual Destructor. |
| 29 | */ |
| 30 | virtual |
| 31 | ~IdentityStorage() {} |
| 32 | |
| 33 | /** |
| 34 | * Check if the specified identity already exists. |
| 35 | * @param identityName The identity name. |
| 36 | * @return true if the identity exists, otherwise false. |
| 37 | */ |
| 38 | virtual bool |
| 39 | doesIdentityExist(const Name& identityName) = 0; |
| 40 | |
| 41 | /** |
| 42 | * Add a new identity. An exception will be thrown if the identity already exists. |
| 43 | * @param identityName The identity name to be added. |
| 44 | */ |
| 45 | virtual void |
| 46 | addIdentity(const Name& identityName) = 0; |
| 47 | |
| 48 | /** |
| 49 | * Revoke the identity. |
| 50 | * @return true if the identity was revoked, false if not. |
| 51 | */ |
| 52 | virtual bool |
| 53 | revokeIdentity() = 0; |
| 54 | |
| 55 | /** |
| 56 | * Generate a name for a new key belonging to the identity. |
| 57 | * @param identityName The identity name. |
| 58 | * @param useKsk If true, generate a KSK name, otherwise a DSK name. |
| 59 | * @return The generated key name. |
| 60 | */ |
| 61 | virtual Name |
| 62 | getNewKeyName(const Name& identityName, bool useKsk) = 0; |
| 63 | |
| 64 | /** |
| 65 | * Check if the specified key already exists. |
| 66 | * @param keyName The name of the key. |
| 67 | * @return true if the key exists, otherwise false. |
| 68 | */ |
| 69 | virtual bool |
| 70 | doesKeyExist(const Name& keyName) = 0; |
| 71 | |
| 72 | /** |
| 73 | * Extract the key name from the certificate name. |
| 74 | * @param certificateName The certificate name to be processed. |
| 75 | */ |
| 76 | virtual Name |
| 77 | getKeyNameForCertificate(const Name& certificateName) = 0; |
| 78 | |
| 79 | /** |
| 80 | * Add a public key to the identity storage. |
| 81 | * @param keyName The name of the public key to be added. |
| 82 | * @param keyType Type of the public key to be added. |
| 83 | * @param publicKeyDer A blob of the public key DER to be added. |
| 84 | */ |
| 85 | virtual void |
Jeff Thompson | bd04b07 | 2013-09-27 15:14:09 -0700 | [diff] [blame] | 86 | addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Get the public key DER blob from the identity storage. |
| 90 | * @param keyName The name of the requested public key. |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame^] | 91 | * @return The DER Blob. If not found, return a Blob with a null pointer. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 92 | */ |
| 93 | virtual Blob |
| 94 | getKey(const Name& keyName) = 0; |
| 95 | |
| 96 | /** |
| 97 | * Activate a key. If a key is marked as inactive, its private part will not be used in packet signing. |
| 98 | * @param keyName name of the key |
| 99 | */ |
| 100 | virtual void |
| 101 | activateKey(const Name& keyName) = 0; |
| 102 | |
| 103 | /** |
| 104 | * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing. |
| 105 | * @param keyName name of the key |
| 106 | */ |
| 107 | virtual void |
| 108 | deactivateKey(const Name& keyName) = 0; |
| 109 | |
| 110 | /** |
| 111 | * Check if the specified certificate already exists. |
| 112 | * @param certificateName The name of the certificate. |
| 113 | * @return true if the certificate exists, otherwise false. |
| 114 | */ |
| 115 | virtual bool |
| 116 | doesCertificateExist(const Name& certificateName) = 0; |
| 117 | |
| 118 | /** |
| 119 | * Add a certificate to the identity storage. |
| 120 | * @param certificate The certificate to be added. |
| 121 | */ |
| 122 | virtual void |
| 123 | addCertificate(const Certificate& certificate) = 0; |
| 124 | |
| 125 | /** |
| 126 | * Get a certificate from the identity storage. |
| 127 | * @param certificateName The name of the requested certificate. |
| 128 | * @param allowAny If false, only a valid certificate will be returned, otherwise validity is disregarded. |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame^] | 129 | * @return The requested certificate. If not found, return a shared_ptr with a null pointer. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 130 | */ |
Jeff Thompson | a6fd638 | 2013-09-24 15:23:37 -0700 | [diff] [blame] | 131 | virtual ptr_lib::shared_ptr<Certificate> |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 132 | getCertificate(const Name &certificateName, bool allowAny = false) = 0; |
| 133 | |
| 134 | |
| 135 | /***************************************** |
| 136 | * Get/Set Default * |
| 137 | *****************************************/ |
| 138 | |
| 139 | /** |
| 140 | * Get the default identity. |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 141 | * @param return The name of default identity, or an empty name if there is no default. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 142 | */ |
| 143 | virtual Name |
| 144 | getDefaultIdentity() = 0; |
| 145 | |
| 146 | /** |
| 147 | * Get the default key name for the specified identity. |
| 148 | * @param identityName The identity name. |
| 149 | * @return The default key name. |
| 150 | */ |
| 151 | virtual Name |
| 152 | getDefaultKeyNameForIdentity(const Name& identityName) = 0; |
| 153 | |
| 154 | /** |
| 155 | * Get the default certificate name for the specified identity. |
| 156 | * @param identityName The identity name. |
| 157 | * @return The default certificate name. |
| 158 | */ |
| 159 | Name |
| 160 | getDefaultCertificateNameForIdentity(const Name& identityName) |
| 161 | { |
| 162 | return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName)); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Get the default certificate name for the specified key. |
| 167 | * @param keyName The key name. |
| 168 | * @return The default certificate name. |
| 169 | */ |
| 170 | virtual Name |
| 171 | getDefaultCertificateNameForKey(const Name& keyName) = 0; |
| 172 | |
| 173 | /** |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 174 | * Set the default identity. If the identityName does not exist, then clear the default identity |
| 175 | * so that getDefaultIdentity() returns an empty name. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 176 | * @param identityName The default identity name. |
| 177 | */ |
| 178 | virtual void |
| 179 | setDefaultIdentity(const Name& identityName) = 0; |
| 180 | |
| 181 | /** |
| 182 | * Set the default key name for the specified identity. |
| 183 | * @param keyName The key name. |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame^] | 184 | * @param identityNameCheck (optional) The identity name to check the keyName. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 185 | */ |
| 186 | virtual void |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame^] | 187 | setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Set the default key name for the specified identity. |
| 191 | * @param keyName The key name. |
| 192 | * @param certificateName The certificate name. |
| 193 | */ |
| 194 | virtual void |
| 195 | setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0; |
| 196 | }; |
| 197 | |
| 198 | } |
| 199 | |
| 200 | #endif |