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