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 | 47c93cf | 2013-08-09 00:38:48 -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. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_KEY_CHAIN_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 9 | #define NDN_KEY_CHAIN_HPP |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 10 | |
Jeff Thompson | 7a67cb6 | 2013-08-26 11:43:18 -0700 | [diff] [blame] | 11 | #include "../data.hpp" |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 12 | #include "../face.hpp" |
| 13 | #include "identity/identity-manager.hpp" |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 14 | #include "encryption/encryption-manager.hpp" |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 15 | |
| 16 | namespace ndn { |
| 17 | |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 18 | class PolicyManager; |
Jeff Thompson | cda349e | 2013-11-05 17:37:39 -0800 | [diff] [blame] | 19 | class ValidationRequest; |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 20 | |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 21 | /** |
| 22 | * An OnVerified function object is used to pass a callback to verifyData to report a successful verification. |
| 23 | */ |
| 24 | typedef func_lib::function<void(const ptr_lib::shared_ptr<Data>& data)> OnVerified; |
| 25 | |
| 26 | /** |
| 27 | * An OnVerifyFailed function object is used to pass a callback to verifyData to report a failed verification. |
| 28 | */ |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 29 | typedef func_lib::function<void(const ptr_lib::shared_ptr<Data>& data)> OnVerifyFailed; |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 30 | |
Jeff Thompson | ffa36f9 | 2013-09-20 08:42:41 -0700 | [diff] [blame] | 31 | /** |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 32 | * Keychain is the main class of the security library. |
Jeff Thompson | ffa36f9 | 2013-09-20 08:42:41 -0700 | [diff] [blame] | 33 | * |
| 34 | * The Keychain class provides a set of interfaces to the security library such as identity management, policy configuration |
| 35 | * and packet signing and verification. |
| 36 | */ |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 37 | class KeyChain { |
| 38 | public: |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 39 | KeyChain |
| 40 | (const ptr_lib::shared_ptr<IdentityManager>& identityManager, const ptr_lib::shared_ptr<PolicyManager>& policyManager); |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 41 | |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 42 | /***************************************** |
| 43 | * Identity Management * |
| 44 | *****************************************/ |
| 45 | |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed certificate of the KSK. |
| 48 | * @param identityName The name of the identity. |
| 49 | * @return The key name of the auto-generated KSK of the identity. |
| 50 | */ |
| 51 | Name |
| 52 | createIdentity(const Name& identityName) |
| 53 | { |
| 54 | return identityManager_->createIdentity(identityName); |
| 55 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Get the default identity. |
| 59 | * @return The default identity name. |
| 60 | */ |
| 61 | Name |
| 62 | getDefaultIdentity() |
| 63 | { |
| 64 | return identityManager_->getDefaultIdentity(); |
| 65 | } |
| 66 | |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 67 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 68 | * Generate a pair of RSA keys for the specified identity. |
| 69 | * @param identityName The name of the identity. |
| 70 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 71 | * @param keySize The size of the key. |
| 72 | * @return The generated key name. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 73 | */ |
| 74 | Name |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 75 | generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048) |
| 76 | { |
| 77 | return identityManager_->generateRSAKeyPair(identityName, isKsk, keySize); |
| 78 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 81 | * Set a key as the default key of an identity. |
| 82 | * @param keyName The name of the key. |
| 83 | * @param identityName the name of the identity. If not specified, the identity name is inferred from the keyName. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 84 | */ |
| 85 | void |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 86 | setDefaultKeyForIdentity(const Name& keyName, const Name& identityName = Name()) |
| 87 | { |
| 88 | return identityManager_->setDefaultKeyForIdentity(keyName, identityName); |
| 89 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 92 | * Generate a pair of RSA keys for the specified identity and set it as default key for the identity. |
| 93 | * @param identityName The name of the identity. |
| 94 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 95 | * @param keySize The size of the key. |
| 96 | * @return The generated key name. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 97 | */ |
| 98 | Name |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 99 | generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048) |
| 100 | { |
| 101 | return identityManager_->generateRSAKeyPairAsDefault(identityName, isKsk, keySize); |
| 102 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 105 | * Create a public key signing request. |
| 106 | * @param keyName The name of the key. |
| 107 | * @returns The signing request data. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 108 | */ |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 109 | Blob |
| 110 | createSigningRequest(const Name& keyName) |
| 111 | { |
| 112 | return identityManager_->getPublicKey(keyName)->getKeyDer(); |
| 113 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Jeff Thompson | b63abf5 | 2013-10-04 11:23:34 -0700 | [diff] [blame] | 116 | * Install an identity certificate into the public key identity storage. |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 117 | * @param certificate The certificate to to added. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 118 | */ |
| 119 | void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 120 | installIdentityCertificate(const IdentityCertificate& certificate) |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 121 | { |
| 122 | identityManager_->addCertificate(certificate); |
| 123 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 126 | * Set the certificate as the default for its corresponding key. |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 127 | * @param certificateName The certificate. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 128 | */ |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 129 | void |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 130 | setDefaultCertificateForKey(const IdentityCertificate& certificate) |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 131 | { |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 132 | identityManager_->setDefaultCertificateForKey(certificate); |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 133 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 136 | * Get a certificate with the specified name. |
| 137 | * @param certificateName The name of the requested certificate. |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 138 | * @return the requested certificate which is valid. |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 139 | */ |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 140 | ptr_lib::shared_ptr<Certificate> |
| 141 | getCertificate(const Name& certificateName) |
| 142 | { |
| 143 | return identityManager_->getCertificate(certificateName); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Get a certificate even if the certificate is not valid anymore. |
| 148 | * @param certificateName The name of the requested certificate. |
| 149 | * @return the requested certificate. |
| 150 | */ |
| 151 | ptr_lib::shared_ptr<Certificate> |
| 152 | getAnyCertificate(const Name& certificateName) |
| 153 | { |
| 154 | return identityManager_->getAnyCertificate(certificateName); |
| 155 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 158 | * Get an identity certificate with the specified name. |
| 159 | * @param certificateName The name of the requested certificate. |
| 160 | * @return the requested certificate which is valid. |
| 161 | */ |
| 162 | ptr_lib::shared_ptr<IdentityCertificate> |
| 163 | getIdentityCertificate(const Name& certificateName) |
| 164 | { |
| 165 | return identityManager_->getCertificate(certificateName); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Get an identity certificate even if the certificate is not valid anymore. |
| 170 | * @param certificateName The name of the requested certificate. |
| 171 | * @return the requested certificate. |
| 172 | */ |
| 173 | ptr_lib::shared_ptr<IdentityCertificate> |
| 174 | getAnyIdentityCertificate(const Name& certificateName) |
| 175 | { |
| 176 | return identityManager_->getAnyCertificate(certificateName); |
| 177 | } |
| 178 | |
| 179 | /** |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 180 | * Revoke a key |
| 181 | * @param keyName the name of the key that will be revoked |
| 182 | */ |
| 183 | void |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 184 | revokeKey(const Name & keyName) |
| 185 | { |
| 186 | //TODO: Implement |
| 187 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Revoke a certificate |
| 191 | * @param certificateName the name of the certificate that will be revoked |
| 192 | */ |
| 193 | void |
Jeff Thompson | e7e069b | 2013-09-27 15:48:48 -0700 | [diff] [blame] | 194 | revokeCertificate(const Name & certificateName) |
| 195 | { |
| 196 | //TODO: Implement |
| 197 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 198 | |
Jeff Thompson | 418b05a | 2013-10-22 17:48:54 -0700 | [diff] [blame] | 199 | ptr_lib::shared_ptr<IdentityManager> |
| 200 | getIdentityManager() { return identityManager_; } |
| 201 | |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 202 | /***************************************** |
| 203 | * Policy Management * |
| 204 | *****************************************/ |
| 205 | |
| 206 | const ptr_lib::shared_ptr<PolicyManager>& |
| 207 | getPolicyManager() { return policyManager_; } |
| 208 | |
| 209 | /***************************************** |
| 210 | * Sign/Verify * |
| 211 | *****************************************/ |
| 212 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 213 | /** |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 214 | * Wire encode the Data object, sign it and set its signature. |
Jeff Thompson | ade5b1e | 2013-08-09 12:16:45 -0700 | [diff] [blame] | 215 | * Note: the caller must make sure the timestamp is correct, for example with |
Jeff Thompson | fec716d | 2013-09-11 13:54:36 -0700 | [diff] [blame] | 216 | * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0). |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 217 | * @param data The Data object to be signed. This updates its signature and key locator field and wireEncoding. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 218 | * @param certificateName The certificate name of the key to use for signing. If omitted, infer the signing identity from the data packet name. |
Jeff Thompson | 8d24fe1 | 2013-09-18 15:54:51 -0700 | [diff] [blame] | 219 | * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat(). |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 220 | */ |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 221 | void |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 222 | sign(Data& data, const Name& certificateName, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 223 | |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 224 | /** |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 225 | * Sign the byte array using a certificate name and return a Signature object. |
| 226 | * @param buffer The byte array to be signed. |
| 227 | * @param bufferLength the length of buffer. |
| 228 | * @param certificateName The certificate name used to get the signing key and which will be put into KeyLocator. |
| 229 | * @return The Signature. |
| 230 | */ |
| 231 | ptr_lib::shared_ptr<Signature> |
| 232 | sign(const uint8_t* buffer, size_t bufferLength, const Name& certificateName); |
| 233 | |
| 234 | /** |
| 235 | * Sign the byte array using a certificate name and return a Signature object. |
| 236 | * @param buffer The byte array to be signed. |
| 237 | * @param certificateName The certificate name used to get the signing key and which will be put into KeyLocator. |
| 238 | * @return The Signature. |
| 239 | */ |
| 240 | ptr_lib::shared_ptr<Signature> |
| 241 | sign(const std::vector<uint8_t>& buffer, const Name& certificateName) |
| 242 | { |
| 243 | return sign(&buffer[0], buffer.size(), certificateName); |
| 244 | } |
| 245 | |
| 246 | /** |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 247 | * Wire encode the Data object, sign it and set its signature. |
| 248 | * Note: the caller must make sure the timestamp is correct, for example with |
| 249 | * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0). |
| 250 | * @param data The Data object to be signed. This updates its signature and key locator field and wireEncoding. |
| 251 | * @param identityName The identity name for the key to use for signing. If omitted, infer the signing identity from the data packet name. |
| 252 | * @param wireFormat A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat(). |
| 253 | */ |
| 254 | void |
| 255 | signByIdentity(Data& data, const Name& identityName = Name(), WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()); |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 256 | |
| 257 | /** |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 258 | * Sign the byte array using an identity name and return a Signature object. |
| 259 | * @param buffer The byte array to be signed. |
| 260 | * @param bufferLength the length of buffer. |
| 261 | * @param identityName The identity name. |
| 262 | * @return The Signature. |
| 263 | */ |
| 264 | ptr_lib::shared_ptr<Signature> |
| 265 | signByIdentity(const uint8_t* buffer, size_t bufferLength, const Name& identityName); |
| 266 | |
| 267 | /** |
| 268 | * Sign the byte array using an identity name and return a Signature object. |
| 269 | * @param buffer The byte array to be signed. |
| 270 | * @param identityName The identity name. |
| 271 | * @return The Signature. |
| 272 | */ |
| 273 | ptr_lib::shared_ptr<Signature> |
| 274 | signByIdentity(const std::vector<uint8_t>& buffer, const Name& identityName) |
| 275 | { |
| 276 | return signByIdentity(&buffer[0], buffer.size(), identityName); |
| 277 | } |
| 278 | |
| 279 | /** |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 280 | * Check the signature on the Data object and call either onVerify or onVerifyFailed. |
| 281 | * We use callback functions because verify may fetch information to check the signature. |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 282 | * @param data The Data object with the signature to check. It is an error if data does not have a wireEncoding. |
| 283 | * To set the wireEncoding, you can call data.wireDecode. |
| 284 | * @param onVerified If the signature is verified, this calls onVerified(data). |
| 285 | * @param onVerifyFailed If the signature check fails, this calls onVerifyFailed(data). |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 286 | */ |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 287 | void |
Jeff Thompson | 7c5d231 | 2013-09-25 16:07:15 -0700 | [diff] [blame] | 288 | verifyData |
| 289 | (const ptr_lib::shared_ptr<Data>& data, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed, int stepCount = 0); |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 290 | |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 291 | /***************************************** |
| 292 | * Encrypt/Decrypt * |
| 293 | *****************************************/ |
| 294 | |
| 295 | /** |
| 296 | * Generate a symmetric key. |
| 297 | * @param keyName The name of the generated key. |
| 298 | * @param keyType The type of the key, e.g. KEY_TYPE_AES |
| 299 | */ |
| 300 | void |
| 301 | generateSymmetricKey(const Name& keyName, KeyType keyType) |
| 302 | { |
| 303 | encryptionManager_->createSymmetricKey(keyName, keyType); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Encrypt a byte array. |
| 308 | * @param keyName The name of the encrypting key. |
| 309 | * @param data The byte array that will be encrypted. |
| 310 | * @param dataLength The length of data. |
| 311 | * @param useSymmetric If true then symmetric encryption is used, otherwise asymmetric encryption is used. |
| 312 | * @param encryptMode the encryption mode |
| 313 | * @return the encrypted data as an immutable Blob. |
| 314 | */ |
| 315 | Blob |
| 316 | encrypt(const Name &keyName, const uint8_t* data, size_t dataLength, bool useSymmetric = true, |
| 317 | EncryptMode encryptMode = ENCRYPT_MODE_DEFAULT) |
| 318 | { |
| 319 | return encryptionManager_->encrypt(keyName, data, dataLength, useSymmetric, encryptMode); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Decrypt a byte array. |
| 324 | * @param keyName The name of the decrypting key. |
| 325 | * @param data The byte array that will be decrypted. |
| 326 | * @param dataLength The length of data. |
| 327 | * @param useSymmetric If true then symmetric encryption is used, otherwise asymmetric encryption is used. |
| 328 | * @param encryptMode the encryption mode |
| 329 | * @return the decrypted data as an immutable Blob. |
| 330 | */ |
| 331 | Blob |
| 332 | decrypt(const Name &keyName, const uint8_t* data, size_t dataLength, bool useSymmetric = true, |
| 333 | EncryptMode encryptMode = ENCRYPT_MODE_DEFAULT) |
| 334 | { |
| 335 | return encryptionManager_->decrypt(keyName, data, dataLength, useSymmetric, encryptMode); |
| 336 | } |
| 337 | |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 338 | /** |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 339 | * Set the Face which will be used to fetch required certificates. |
| 340 | * @param face A pointer to the Face object. |
Jeff Thompson | 1e90d8c | 2013-08-12 16:09:25 -0700 | [diff] [blame] | 341 | */ |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 342 | void |
| 343 | setFace(Face* face) { face_ = face; } |
| 344 | |
| 345 | private: |
Jeff Thompson | cda349e | 2013-11-05 17:37:39 -0800 | [diff] [blame] | 346 | void |
| 347 | onCertificateData |
| 348 | (const ptr_lib::shared_ptr<const Interest> &interest, const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep); |
| 349 | |
| 350 | void |
| 351 | onCertificateInterestTimeout |
| 352 | (const ptr_lib::shared_ptr<const Interest> &interest, int retry, const OnVerifyFailed& onVerifyFailed, |
| 353 | const ptr_lib::shared_ptr<Data> &data, ptr_lib::shared_ptr<ValidationRequest> nextStep); |
| 354 | |
Jeff Thompson | 40f361a | 2013-09-25 13:12:48 -0700 | [diff] [blame] | 355 | ptr_lib::shared_ptr<IdentityManager> identityManager_; |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 356 | ptr_lib::shared_ptr<PolicyManager> policyManager_; |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 357 | ptr_lib::shared_ptr<EncryptionManager> encryptionManager_; |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 358 | Face* face_; |
| 359 | const int maxSteps_; |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | } |
| 363 | |
| 364 | #endif |