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