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 | */ |
| 62 | virtual Name |
| 63 | getNewKeyName(const Name& identityName, bool useKsk) = 0; |
| 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 | /** |
| 74 | * Extract the key name from the certificate name. |
| 75 | * @param certificateName The certificate name to be processed. |
| 76 | */ |
| 77 | virtual Name |
| 78 | getKeyNameForCertificate(const Name& certificateName) = 0; |
| 79 | |
| 80 | /** |
| 81 | * Add a public key to the identity storage. |
| 82 | * @param keyName The name of the public key to be added. |
| 83 | * @param keyType Type of the public key to be added. |
| 84 | * @param publicKeyDer A blob of the public key DER to be added. |
| 85 | */ |
| 86 | virtual void |
Jeff Thompson | bd04b07 | 2013-09-27 15:14:09 -0700 | [diff] [blame] | 87 | addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Get the public key DER blob from the identity storage. |
| 91 | * @param keyName The name of the requested public key. |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame] | 92 | * @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] | 93 | */ |
| 94 | virtual Blob |
| 95 | getKey(const Name& keyName) = 0; |
| 96 | |
| 97 | /** |
| 98 | * Activate 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 | activateKey(const Name& keyName) = 0; |
| 103 | |
| 104 | /** |
| 105 | * Deactivate a key. If a key is marked as inactive, its private part will not be used in packet signing. |
| 106 | * @param keyName name of the key |
| 107 | */ |
| 108 | virtual void |
| 109 | deactivateKey(const Name& keyName) = 0; |
| 110 | |
| 111 | /** |
| 112 | * Check if the specified certificate already exists. |
| 113 | * @param certificateName The name of the certificate. |
| 114 | * @return true if the certificate exists, otherwise false. |
| 115 | */ |
| 116 | virtual bool |
| 117 | doesCertificateExist(const Name& certificateName) = 0; |
| 118 | |
| 119 | /** |
| 120 | * Add a certificate to the identity storage. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 121 | * @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] | 122 | */ |
| 123 | virtual void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 124 | addCertificate(const IdentityCertificate& certificate) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * Get a certificate from the identity storage. |
| 128 | * @param certificateName The name of the requested certificate. |
| 129 | * @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] | 130 | * @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] | 131 | */ |
Jeff Thompson | 3bd90bc | 2013-10-19 16:40:14 -0700 | [diff] [blame^] | 132 | virtual ptr_lib::shared_ptr<Data> |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 133 | getCertificate(const Name &certificateName, bool allowAny = false) = 0; |
| 134 | |
| 135 | |
| 136 | /***************************************** |
| 137 | * Get/Set Default * |
| 138 | *****************************************/ |
| 139 | |
| 140 | /** |
| 141 | * Get the default identity. |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 142 | * @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] | 143 | */ |
| 144 | virtual Name |
| 145 | getDefaultIdentity() = 0; |
| 146 | |
| 147 | /** |
| 148 | * Get the default key name for the specified identity. |
| 149 | * @param identityName The identity name. |
| 150 | * @return The default key name. |
| 151 | */ |
| 152 | virtual Name |
| 153 | getDefaultKeyNameForIdentity(const Name& identityName) = 0; |
| 154 | |
| 155 | /** |
| 156 | * Get the default certificate name for the specified identity. |
| 157 | * @param identityName The identity name. |
| 158 | * @return The default certificate name. |
| 159 | */ |
| 160 | Name |
| 161 | getDefaultCertificateNameForIdentity(const Name& identityName) |
| 162 | { |
| 163 | return getDefaultCertificateNameForKey(getDefaultKeyNameForIdentity(identityName)); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get the default certificate name for the specified key. |
| 168 | * @param keyName The key name. |
| 169 | * @return The default certificate name. |
| 170 | */ |
| 171 | virtual Name |
| 172 | getDefaultCertificateNameForKey(const Name& keyName) = 0; |
| 173 | |
| 174 | /** |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 175 | * Set the default identity. If the identityName does not exist, then clear the default identity |
| 176 | * so that getDefaultIdentity() returns an empty name. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 177 | * @param identityName The default identity name. |
| 178 | */ |
| 179 | virtual void |
| 180 | setDefaultIdentity(const Name& identityName) = 0; |
| 181 | |
| 182 | /** |
| 183 | * Set the default key name for the specified identity. |
| 184 | * @param keyName The key name. |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame] | 185 | * @param identityNameCheck (optional) The identity name to check the keyName. |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 186 | */ |
| 187 | virtual void |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame] | 188 | setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck = Name()) = 0; |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Set the default key name for the specified identity. |
| 192 | * @param keyName The key name. |
| 193 | * @param certificateName The certificate name. |
| 194 | */ |
| 195 | virtual void |
| 196 | setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) = 0; |
| 197 | }; |
| 198 | |
| 199 | } |
| 200 | |
| 201 | #endif |