Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
Jeff Thompson | 06e787d | 2013-09-12 19:00:55 -0700 | [diff] [blame] | 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
| 9 | #ifndef NDN_IDENTITY_MANAGER_HPP |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 10 | #define NDN_IDENTITY_MANAGER_HPP |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 11 | |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 12 | #include "identity-storage.hpp" |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 13 | #include "private-key-storage.hpp" |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 14 | #include "../certificate/public-key.hpp" |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 15 | |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 16 | #include "../../data.hpp" |
| 17 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 18 | namespace ndn { |
| 19 | |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 20 | class IdentityCertificate; |
| 21 | |
Jeff Thompson | ffa36f9 | 2013-09-20 08:42:41 -0700 | [diff] [blame] | 22 | /** |
| 23 | * An IdentityManager is the interface of operations related to identity, keys, and certificates. |
| 24 | */ |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 25 | class IdentityManager { |
| 26 | public: |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 27 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 28 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 29 | IdentityManager(const ptr_lib::shared_ptr<IdentityStorage> &identityStorage = DefaultIdentityStorage, |
| 30 | const ptr_lib::shared_ptr<PrivateKeyStorage> &privateKeyStorage = DefaultPrivateKeyStorage); |
| 31 | |
| 32 | inline IdentityStorage& |
| 33 | info(); |
| 34 | |
| 35 | inline const IdentityStorage& |
| 36 | info() const; |
| 37 | |
| 38 | inline PrivateKeyStorage& |
| 39 | tpm(); |
| 40 | |
| 41 | inline const PrivateKeyStorage& |
| 42 | tpm() const; |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 43 | |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 44 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 45 | * Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed certificate of the KSK. |
| 46 | * @param identityName The name of the identity. |
| 47 | * @return The key name of the auto-generated KSK of the identity. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 48 | */ |
| 49 | Name |
| 50 | createIdentity(const Name& identityName); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * Get the default identity. |
| 54 | * @return The default identity name. |
| 55 | */ |
| 56 | Name |
| 57 | getDefaultIdentity() |
| 58 | { |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 59 | return info().getDefaultIdentity(); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 62 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 63 | * Generate a pair of RSA keys for the specified identity. |
| 64 | * @param identityName The name of the identity. |
| 65 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 66 | * @param keySize The size of the key. |
| 67 | * @return The generated key name. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 68 | */ |
| 69 | Name |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 70 | generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 73 | * Set a key as the default key of an identity. |
| 74 | * @param keyName The name of the key. |
| 75 | * @param identityName the name of the identity. If not specified, the identity name is inferred from the keyName. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 76 | */ |
| 77 | void |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 78 | setDefaultKeyForIdentity(const Name& keyName, const Name& identityName = Name()) |
| 79 | { |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 80 | info().setDefaultKeyNameForIdentity(keyName, identityName); |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame^] | 81 | defaultCertificate_.reset(); |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 82 | } |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
Jeff Thompson | 18bf631 | 2013-10-04 11:23:55 -0700 | [diff] [blame] | 85 | * Get the default key for an identity. |
| 86 | * @param identityName the name of the identity. If omitted, the identity name is inferred from the keyName. |
| 87 | * @return The default key name. |
| 88 | */ |
| 89 | Name |
| 90 | getDefaultKeyNameForIdentity(const Name& identityName = Name()) |
| 91 | { |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 92 | return info().getDefaultKeyNameForIdentity(identityName); |
Jeff Thompson | 18bf631 | 2013-10-04 11:23:55 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 96 | * Generate a pair of RSA keys for the specified identity and set it as default key for the identity. |
| 97 | * @param identityName The name of the identity. |
| 98 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 99 | * @param keySize The size of the key. |
| 100 | * @return The generated key name. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 101 | */ |
| 102 | Name |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 103 | generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 106 | * Get the public key with the specified name. |
| 107 | * @param keyName The name of the key. |
| 108 | * @return The public key. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 109 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 110 | ptr_lib::shared_ptr<PublicKey> |
| 111 | getPublicKey(const Name& keyName) |
| 112 | { |
| 113 | return info().getKey(keyName); |
| 114 | } |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 117 | * Create an identity certificate for a public key managed by this IdentityManager. |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 118 | * @param certificatePrefix The name of public key to be signed. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 119 | * @param signerCertificateName The name of signing certificate. |
| 120 | * @param notBefore The notBefore value in the validity field of the generated certificate. |
| 121 | * @param notAfter The notAfter vallue in validity field of the generated certificate. |
| 122 | * @return The name of generated identity certificate. |
| 123 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 124 | ptr_lib::shared_ptr<IdentityCertificate> |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 125 | createIdentityCertificate |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 126 | (const Name& certificatePrefix, |
| 127 | const Name& signerCertificateName, |
| 128 | const MillisecondsSince1970& notBefore, |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 129 | const MillisecondsSince1970& notAfter); |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * Create an identity certificate for a public key supplied by the caller. |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 133 | * @param certificatePrefix The name of public key to be signed. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 134 | * @param publickey The public key to be signed. |
| 135 | * @param signerCertificateName The name of signing certificate. |
| 136 | * @param notBefore The notBefore value in the validity field of the generated certificate. |
| 137 | * @param notAfter The notAfter vallue in validity field of the generated certificate. |
| 138 | * @return The generated identity certificate. |
| 139 | */ |
| 140 | ptr_lib::shared_ptr<IdentityCertificate> |
| 141 | createIdentityCertificate |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 142 | (const Name& certificatePrefix, |
| 143 | const PublicKey& publickey, |
| 144 | const Name& signerCertificateName, |
| 145 | const MillisecondsSince1970& notBefore, |
| 146 | const MillisecondsSince1970& notAfter); |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 149 | * Add a certificate into the public key identity storage. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 150 | * @param certificate The certificate to to added. This makes a copy of the certificate. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 151 | */ |
| 152 | void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 153 | addCertificate(const IdentityCertificate& certificate) |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 154 | { |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 155 | info().addCertificate(certificate); |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 156 | } |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 159 | * Set the certificate as the default for its corresponding key. |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 160 | * @param certificateName The certificate. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 161 | */ |
| 162 | void |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 163 | setDefaultCertificateForKey(const IdentityCertificate& certificate); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 164 | |
| 165 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 166 | * Add a certificate into the public key identity storage and set the certificate as the default for its corresponding identity. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 167 | * @param certificate The certificate to be added. This makes a copy of the certificate. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 168 | */ |
| 169 | void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 170 | addCertificateAsIdentityDefault(const IdentityCertificate& certificate); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 171 | |
| 172 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 173 | * Add a certificate into the public key identity storage and set the certificate as the default of its corresponding key. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 174 | * @param certificate The certificate to be added. This makes a copy of the certificate. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 175 | */ |
| 176 | void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 177 | addCertificateAsDefault(const IdentityCertificate& certificate); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 180 | * Get a certificate with the specified name. |
| 181 | * @param certificateName The name of the requested certificate. |
| 182 | * @return the requested certificate which is valid. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 183 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 184 | ptr_lib::shared_ptr<IdentityCertificate> |
| 185 | getCertificate(const Name& certificateName) |
| 186 | { |
| 187 | return info().getCertificate(certificateName, false); |
| 188 | } |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 191 | * Get a certificate even if the certificate is not valid anymore. |
| 192 | * @param certificateName The name of the requested certificate. |
| 193 | * @return the requested certificate. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 194 | */ |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 195 | ptr_lib::shared_ptr<IdentityCertificate> |
| 196 | getAnyCertificate(const Name& certificateName) |
| 197 | { |
| 198 | return info().getCertificate(certificateName, true); |
| 199 | } |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * Get the default certificate name for the specified identity, which will be used when signing is performed based on identity. |
| 203 | * @param identityName The name of the specified identity. |
| 204 | * @return The requested certificate name. |
| 205 | */ |
| 206 | Name |
| 207 | getDefaultCertificateNameForIdentity(const Name& identityName) |
| 208 | { |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 209 | return info().getDefaultCertificateNameForIdentity(identityName); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Get the default certificate name of the default identity, which will be used when signing is based on identity and |
| 214 | * the identity is not specified. |
| 215 | * @return The requested certificate name. |
| 216 | */ |
| 217 | Name |
| 218 | getDefaultCertificateName() |
| 219 | { |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 220 | return info().getDefaultCertificateNameForIdentity(getDefaultIdentity()); |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 221 | } |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame^] | 222 | |
| 223 | void |
| 224 | sign(Data &data); |
| 225 | |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 226 | /** |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 227 | * Sign the byte array data based on the certificate name. |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 228 | * @param buffer The byte array to be signed. |
| 229 | * @param bufferLength the length of buffer. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 230 | * @param certificateName The signing certificate name. |
| 231 | * @return The generated signature. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 232 | */ |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 233 | Signature |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 234 | signByCertificate(const uint8_t* buffer, size_t bufferLength, const Name& certificateName); |
| 235 | |
| 236 | /** |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 237 | * Sign data packet based on the certificate name. |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 238 | * Note: the caller must make sure the timestamp in data is correct, for example with |
| 239 | * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0). |
| 240 | * @param data The Data object to sign and update its signature. |
| 241 | * @param certificateName The Name identifying the certificate which identifies the signing key. |
| 242 | * @param wireFormat The WireFormat for calling encodeData, or WireFormat::getDefaultWireFormat() if omitted. |
| 243 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 244 | void |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 245 | signByCertificate(Data& data, const Name& certificateName); |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 246 | |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame^] | 247 | void |
| 248 | signByCertificate(Data& data, const IdentityCertificate& certificate); |
| 249 | |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 250 | /** |
| 251 | * Generate a self-signed certificate for a public key. |
| 252 | * @param keyName The name of the public key. |
| 253 | * @return The generated certificate. |
| 254 | */ |
| 255 | ptr_lib::shared_ptr<IdentityCertificate> |
| 256 | selfSign(const Name& keyName); |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * @brief Self-sign the supplied identity certificate |
| 260 | */ |
| 261 | void |
| 262 | selfSign (IdentityCertificate& cert); |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame^] | 263 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 264 | public: |
| 265 | static const ptr_lib::shared_ptr<IdentityStorage> DefaultIdentityStorage; |
| 266 | static const ptr_lib::shared_ptr<PrivateKeyStorage> DefaultPrivateKeyStorage; |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame^] | 267 | |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 268 | private: |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 269 | /** |
| 270 | * Generate a key pair for the specified identity. |
| 271 | * @param identityName The name of the specified identity. |
| 272 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 273 | * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA. |
| 274 | * @param keySize The size of the key pair. |
| 275 | * @return The name of the generated key. |
| 276 | */ |
| 277 | Name |
| 278 | generateKeyPair(const Name& identityName, bool isKsk = false, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048); |
| 279 | |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 280 | static Name |
| 281 | getKeyNameFromCertificatePrefix(const Name& certificatePrefix); |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 282 | |
| 283 | private: |
| 284 | ptr_lib::shared_ptr<IdentityStorage> identityStorage_; |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 285 | ptr_lib::shared_ptr<PrivateKeyStorage> privateKeyStorage_; |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame^] | 286 | |
| 287 | ptr_lib::shared_ptr<IdentityCertificate> defaultCertificate_; |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 288 | }; |
| 289 | |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 290 | inline IdentityStorage& |
| 291 | IdentityManager::info() |
| 292 | { |
| 293 | if (!identityStorage_) |
| 294 | throw Error("IdentityStorage is not assigned to IdentityManager"); |
| 295 | |
| 296 | return *identityStorage_; |
| 297 | } |
| 298 | |
| 299 | inline const IdentityStorage& |
| 300 | IdentityManager::info() const |
| 301 | { |
| 302 | if (!identityStorage_) |
| 303 | throw Error("IdentityStorage is not assigned to IdentityManager"); |
| 304 | |
| 305 | return *identityStorage_; |
| 306 | } |
| 307 | |
| 308 | inline PrivateKeyStorage& |
| 309 | IdentityManager::tpm() |
| 310 | { |
| 311 | if (!identityStorage_) |
| 312 | throw Error("PrivateKeyStorage is not assigned to IdentityManager"); |
| 313 | |
| 314 | return *privateKeyStorage_; |
| 315 | } |
| 316 | |
| 317 | inline const PrivateKeyStorage& |
| 318 | IdentityManager::tpm() const |
| 319 | { |
| 320 | if (!identityStorage_) |
| 321 | throw Error("PrivateKeyStorage is not assigned to IdentityManager"); |
| 322 | return *privateKeyStorage_; |
| 323 | } |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 324 | |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | #endif |