Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [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 | /** |
Yingdi Yu | fe4733a | 2015-10-22 14:24:12 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 24 | #ifndef NDN_SECURITY_KEY_CHAIN_HPP |
| 25 | #define NDN_SECURITY_KEY_CHAIN_HPP |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 26 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 27 | #include "sec-public-info.hpp" |
| 28 | #include "sec-tpm.hpp" |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 29 | #include "key-params.hpp" |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 30 | #include "secured-bag.hpp" |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 31 | #include "signature-sha256-with-rsa.hpp" |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 32 | #include "signature-sha256-with-ecdsa.hpp" |
Yingdi Yu | bf6a281 | 2014-06-17 15:32:11 -0700 | [diff] [blame] | 33 | #include "digest-sha256.hpp" |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 34 | #include "signing-info.hpp" |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 35 | |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 36 | #include "../interest.hpp" |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 37 | #include "../util/crypto.hpp" |
Yingdi Yu | 0f5fb69 | 2014-06-10 12:07:28 -0700 | [diff] [blame] | 38 | #include "../util/random.hpp" |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 39 | #include <initializer_list> |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 40 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 41 | namespace ndn { |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 42 | namespace security { |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 43 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 44 | /** |
| 45 | * @brief The packet signing interface. |
| 46 | */ |
Alexander Afanasyev | 45a3713 | 2014-04-28 16:54:57 -0700 | [diff] [blame] | 47 | class KeyChain : noncopyable |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 48 | { |
| 49 | public: |
| 50 | class Error : public std::runtime_error |
| 51 | { |
| 52 | public: |
| 53 | explicit |
| 54 | Error(const std::string& what) |
| 55 | : std::runtime_error(what) |
| 56 | { |
| 57 | } |
| 58 | }; |
| 59 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 60 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 61 | * @brief Error thrown when the supplied TPM locator to KeyChain constructor does not match |
| 62 | * the locator stored in PIB |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 63 | */ |
| 64 | class MismatchError : public Error |
| 65 | { |
| 66 | public: |
| 67 | explicit |
| 68 | MismatchError(const std::string& what) |
| 69 | : Error(what) |
| 70 | { |
| 71 | } |
| 72 | }; |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 74 | typedef function<unique_ptr<SecPublicInfo> (const std::string&)> PibCreateFunc; |
| 75 | typedef function<unique_ptr<SecTpm>(const std::string&)> TpmCreateFunc; |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 77 | /** |
| 78 | * @brief Register a new PIB |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 79 | * @param aliases List of schemes with which this PIB will be associated. |
| 80 | * The first alias in the list is considered a canonical name of the PIB instance. |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 81 | */ |
| 82 | template<class PibType> |
| 83 | static void |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 84 | registerPib(std::initializer_list<std::string> aliases); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * @brief Register a new TPM |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 88 | * @param aliases List of schemes with which this TPM will be associated |
| 89 | * The first alias in the list is considered a canonical name of the TPM instance. |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 90 | */ |
| 91 | template<class TpmType> |
| 92 | static void |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 93 | registerTpm(std::initializer_list<std::string> aliases); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 94 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 95 | /** |
| 96 | * @brief Get default PIB locator |
| 97 | */ |
Yingdi Yu | 281689a | 2015-06-13 14:32:32 -0700 | [diff] [blame] | 98 | static std::string |
| 99 | getDefaultPibLocator(); |
| 100 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 101 | /** |
| 102 | * @brief Create a PIB according to @p pibLocator |
| 103 | */ |
Yingdi Yu | 281689a | 2015-06-13 14:32:32 -0700 | [diff] [blame] | 104 | static unique_ptr<SecPublicInfo> |
| 105 | createPib(const std::string& pibLocator); |
| 106 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 107 | /** |
| 108 | * @brief Get default TPM locator |
| 109 | */ |
Yingdi Yu | 281689a | 2015-06-13 14:32:32 -0700 | [diff] [blame] | 110 | static std::string |
| 111 | getDefaultTpmLocator(); |
| 112 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 113 | /** |
| 114 | * @brief Create a TPM according to @p tpmLocator |
| 115 | */ |
Yingdi Yu | 281689a | 2015-06-13 14:32:32 -0700 | [diff] [blame] | 116 | static unique_ptr<SecTpm> |
| 117 | createTpm(const std::string& tpmLocator); |
| 118 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 119 | /** |
| 120 | * @brief Constructor to create KeyChain with default PIB and TPM |
| 121 | * |
| 122 | * Default PIB and TPM are platform-dependent and can be overriden system-wide or on |
| 123 | * per-use basis. |
| 124 | * |
| 125 | * @todo Add detailed description about config file behavior here |
| 126 | */ |
| 127 | KeyChain(); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 128 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 129 | /** |
| 130 | * @brief KeyChain constructor |
| 131 | * |
| 132 | * @sa http://redmine.named-data.net/issues/2260 |
| 133 | * |
Davide Pesavento | 18cf81b | 2015-09-12 23:36:43 +0200 | [diff] [blame] | 134 | * @param pibLocator PIB locator |
| 135 | * @param tpmLocator TPM locator |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 136 | * @param allowReset if true, the PIB will be reset when the supplied tpmLocator |
| 137 | * mismatches the one in PIB |
| 138 | */ |
| 139 | KeyChain(const std::string& pibLocator, |
| 140 | const std::string& tpmLocator, |
| 141 | bool allowReset = false); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 142 | |
| 143 | virtual |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 144 | ~KeyChain(); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 145 | |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 146 | /** |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 147 | * @brief Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a |
| 148 | * self-signed certificate of the KSK. |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 149 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 150 | * @param identityName The name of the identity. |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 151 | * @param params The key parameter if a key needs to be generated for the identity. |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 152 | * @return The name of the default certificate of the identity. |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 153 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 154 | Name |
| 155 | createIdentity(const Name& identityName, const KeyParams& params = DEFAULT_KEY_PARAMS); |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 156 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 157 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 158 | * @brief Generate a pair of RSA keys for the specified identity. |
| 159 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 160 | * @param identityName The name of the identity. |
| 161 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 162 | * @param keySize The size of the key. |
| 163 | * @return The generated key name. |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 164 | * @see generateEcdsaKeyPair |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 165 | */ |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 166 | Name |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 167 | generateRsaKeyPair(const Name& identityName, bool isKsk = false, uint32_t keySize = 2048); |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 168 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 169 | /** |
| 170 | * @brief Generate a pair of ECDSA keys for the specified identity. |
| 171 | * |
| 172 | * @param identityName The name of the identity. |
| 173 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 174 | * @param keySize The size of the key. |
| 175 | * @return The generated key name. |
| 176 | * @see generateRsaKeyPair |
| 177 | */ |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 178 | Name |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 179 | generateEcdsaKeyPair(const Name& identityName, bool isKsk = false, uint32_t keySize = 256); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 180 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 181 | /** |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 182 | * @brief Generate a pair of RSA keys for the specified identity and set it as default key for |
| 183 | * the identity. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 184 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 185 | * @param identityName The name of the identity. |
| 186 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 187 | * @param keySize The size of the key. |
| 188 | * @return The generated key name. |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 189 | * @see generateRsaKeyPair, generateEcdsaKeyPair, generateEcdsaKeyPairAsDefault |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 190 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 191 | Name |
José Quevedo | 699d2ea | 2016-01-29 00:13:00 +0000 | [diff] [blame] | 192 | generateRsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, uint32_t keySize = 2048); |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 193 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 194 | /** |
| 195 | * @brief Generate a pair of ECDSA keys for the specified identity and set it as default key for |
| 196 | * the identity. |
| 197 | * |
| 198 | * @param identityName The name of the identity. |
| 199 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 200 | * @param keySize The size of the key. |
| 201 | * @return The generated key name. |
| 202 | * @see generateRsaKeyPair, generateEcdsaKeyPair, generateRsaKeyPairAsDefault |
| 203 | */ |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 204 | Name |
José Quevedo | 699d2ea | 2016-01-29 00:13:00 +0000 | [diff] [blame] | 205 | generateEcdsaKeyPairAsDefault(const Name& identityName, bool isKsk = false, uint32_t keySize = 256); |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 206 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 207 | /** |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 208 | * @brief prepare an unsigned identity certificate |
| 209 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 210 | * @param keyName Key name, e.g., `/<identity_name>/ksk-123456`. |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 211 | * @param signingIdentity The signing identity. |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 212 | * @param notBefore Refer to v1::IdentityCertificate. |
| 213 | * @param notAfter Refer to v1::IdentityCertificate. |
| 214 | * @param subjectDescription Refer to v1::IdentityCertificate. |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 215 | * @param certPrefix Prefix before `KEY` component. By default, KeyChain will infer the |
| 216 | * certificate name according to the relation between the signingIdentity and |
| 217 | * the subject identity. If signingIdentity is a prefix of the subject identity, |
| 218 | * `KEY` will be inserted after the signingIdentity, otherwise `KEY` is inserted |
| 219 | * after subject identity (i.e., before `ksk-....`). |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 220 | * @return v1::IdentityCertificate. |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 221 | */ |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 222 | shared_ptr<v1::IdentityCertificate> |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 223 | prepareUnsignedIdentityCertificate(const Name& keyName, |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 224 | const Name& signingIdentity, |
| 225 | const time::system_clock::TimePoint& notBefore, |
| 226 | const time::system_clock::TimePoint& notAfter, |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 227 | const std::vector<security::v1::CertificateSubjectDescription>& subjectDescription, |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 228 | const Name& certPrefix = DEFAULT_PREFIX); |
| 229 | |
| 230 | /** |
| 231 | * @brief prepare an unsigned identity certificate |
| 232 | * |
| 233 | * @param keyName Key name, e.g., `/<identity_name>/ksk-123456`. |
| 234 | * @param publicKey Public key to sign. |
| 235 | * @param signingIdentity The signing identity. |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 236 | * @param notBefore Refer to v1::IdentityCertificate. |
| 237 | * @param notAfter Refer to v1::IdentityCertificate. |
| 238 | * @param subjectDescription Refer to v1::IdentityCertificate. |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 239 | * @param certPrefix Prefix before `KEY` component. By default, KeyChain will infer the |
| 240 | * certificate name according to the relation between the signingIdentity and |
| 241 | * the subject identity. If signingIdentity is a prefix of the subject identity, |
| 242 | * `KEY` will be inserted after the signingIdentity, otherwise `KEY` is inserted |
| 243 | * after subject identity (i.e., before `ksk-....`). |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 244 | * @return v1::IdentityCertificate. |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 245 | */ |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 246 | shared_ptr<v1::IdentityCertificate> |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 247 | prepareUnsignedIdentityCertificate(const Name& keyName, |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 248 | const v1::PublicKey& publicKey, |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 249 | const Name& signingIdentity, |
| 250 | const time::system_clock::TimePoint& notBefore, |
| 251 | const time::system_clock::TimePoint& notAfter, |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 252 | const std::vector<security::v1::CertificateSubjectDescription>& subjectDescription, |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 253 | const Name& certPrefix = DEFAULT_PREFIX); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 254 | |
| 255 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 256 | * @brief Sign data according to the supplied signing information |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 257 | * |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 258 | * This method uses the supplied signing information @p params to create the SignatureInfo block: |
| 259 | * - it selects a private key and its certificate to sign the packet |
| 260 | * - sets the KeyLocator field with the certificate name, and |
| 261 | * - adds other requested information to the SignatureInfo block). |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 262 | * |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 263 | * After that, the method assigns the created SignatureInfo to the data packets, generate a |
| 264 | * signature and sets as part of the SignatureValue block. |
| 265 | * |
| 266 | * @param data The data to sign |
| 267 | * @param params The signing parameters. |
| 268 | * @throws Error if signing fails. |
| 269 | * @see SigningInfo |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 270 | */ |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 271 | void |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 272 | sign(Data& data, const SigningInfo& params = DEFAULT_SIGNING_INFO); |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 273 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 274 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 275 | * @brief Sign interest according to the supplied signing information |
| 276 | * |
| 277 | * This method uses the supplied signing information @p params to create the SignatureInfo block: |
| 278 | * - it selects a private key and its certificate to sign the packet |
| 279 | * - sets the KeyLocator field with the certificate name, and |
| 280 | * - adds other requested information to the SignatureInfo block). |
| 281 | * |
| 282 | * After that, the method appends the created SignatureInfo to the interest name, generate a |
| 283 | * signature and appends it as part of the SignatureValue block to the interest name. |
| 284 | * |
| 285 | * @param interest The interest to sign |
| 286 | * @param params The signing parameters. |
| 287 | * @throws Error if signing fails. |
| 288 | * @see SigningInfo |
| 289 | */ |
| 290 | void |
| 291 | sign(Interest& interest, const SigningInfo& params = DEFAULT_SIGNING_INFO); |
| 292 | |
| 293 | /** |
| 294 | * @brief Sign buffer according to the supplied signing information |
| 295 | * |
| 296 | * @param buffer The buffer to sign |
| 297 | * @param bufferLength The buffer size |
| 298 | * @param params The signing parameters. |
| 299 | * @return a SignatureValue TLV block |
| 300 | * @throws Error if signing fails. |
| 301 | * @see SigningInfo |
| 302 | */ |
| 303 | Block |
| 304 | sign(const uint8_t* buffer, size_t bufferLength, const SigningInfo& params); |
| 305 | |
| 306 | /** |
| 307 | * @deprecated use sign sign(T&, const SigningInfo&) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 308 | * @brief Sign packet with a particular certificate. |
| 309 | * |
| 310 | * @param packet The packet to be signed. |
| 311 | * @param certificateName The certificate name of the key to use for signing. |
| 312 | * @throws SecPublicInfo::Error if certificate does not exist. |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 313 | */ |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 314 | template<typename T> |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 315 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 316 | sign(T& packet, const Name& certificateName); |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 317 | |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 318 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 319 | * @deprecated Use sign(const uint8_t*, size_t, const SigningInfo&) instead |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 320 | * @brief Sign the byte array using a particular certificate. |
| 321 | * |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 322 | * @param buffer The byte array to be signed. |
| 323 | * @param bufferLength the length of buffer. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 324 | * @param certificateName The certificate name of the signing key. |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 325 | * @return The Signature. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 326 | * @throws SecPublicInfo::Error if certificate does not exist. |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 327 | */ |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 328 | Signature |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 329 | sign(const uint8_t* buffer, size_t bufferLength, const Name& certificateName); |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 330 | |
| 331 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 332 | * @deprecated use sign sign(T&, const SigningInfo&) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 333 | * @brief Sign packet using the default certificate of a particular identity. |
| 334 | * |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 335 | * If there is no default certificate of that identity, this method will create a self-signed |
| 336 | * certificate. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 337 | * |
| 338 | * @param packet The packet to be signed. |
| 339 | * @param identityName The signing identity name. |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 340 | */ |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 341 | template<typename T> |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 342 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 343 | signByIdentity(T& packet, const Name& identityName); |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 344 | |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 345 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 346 | * @deprecated use sign(const uint8_t*, size_t, const SigningInfo&) instead |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 347 | * @brief Sign the byte array using the default certificate of a particular identity. |
| 348 | * |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 349 | * @param buffer The byte array to be signed. |
| 350 | * @param bufferLength the length of buffer. |
| 351 | * @param identityName The identity name. |
| 352 | * @return The Signature. |
| 353 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 354 | Signature |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 355 | signByIdentity(const uint8_t* buffer, size_t bufferLength, const Name& identityName); |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 356 | |
| 357 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 358 | * @deprecated use sign(Data&, SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)) |
Yingdi Yu | 6ab6781 | 2014-11-27 15:00:34 -0800 | [diff] [blame] | 359 | * @brief Set Sha256 weak signature for @p data |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 360 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 361 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 362 | signWithSha256(Data& data); |
Yingdi Yu | 2115716 | 2014-02-28 13:02:34 -0800 | [diff] [blame] | 363 | |
| 364 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 365 | * @deprecated use sign(Interest&, SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)) |
Yingdi Yu | 6ab6781 | 2014-11-27 15:00:34 -0800 | [diff] [blame] | 366 | * @brief Set Sha256 weak signature for @p interest |
| 367 | */ |
| 368 | void |
| 369 | signWithSha256(Interest& interest); |
| 370 | |
| 371 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 372 | * @brief Generate a self-signed certificate for a public key. |
| 373 | * |
Alexander Afanasyev | 770827c | 2014-05-13 17:42:55 -0700 | [diff] [blame] | 374 | * @param keyName The name of the public key |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 375 | * @return The generated certificate, shared_ptr<v1::IdentityCertificate>() if selfSign fails |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 376 | */ |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 377 | shared_ptr<v1::IdentityCertificate> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 378 | selfSign(const Name& keyName); |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 379 | |
| 380 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 381 | * @brief Self-sign the supplied identity certificate. |
| 382 | * |
| 383 | * @param cert The supplied cert. |
| 384 | * @throws SecTpm::Error if the private key does not exist. |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 385 | */ |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 386 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 387 | selfSign(v1::IdentityCertificate& cert); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 388 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 389 | /** |
| 390 | * @brief delete a certificate. |
| 391 | * |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 392 | * @param certificateName The certificate to be deleted. |
Yingdi Yu | 6147ef4 | 2014-12-08 17:48:32 -0800 | [diff] [blame] | 393 | * @throws KeyChain::Error if certificate cannot be deleted. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 394 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 395 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 396 | deleteCertificate(const Name& certificateName); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 397 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 398 | /** |
| 399 | * @brief delete a key. |
| 400 | * |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 401 | * @param keyName The key to be deleted. |
Yingdi Yu | 6147ef4 | 2014-12-08 17:48:32 -0800 | [diff] [blame] | 402 | * @throws KeyChain::Error if key cannot be deleted. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 403 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 404 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 405 | deleteKey(const Name& keyName); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 406 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 407 | /** |
| 408 | * @brief delete an identity. |
| 409 | * |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 410 | * @param identity The identity to be deleted. |
Yingdi Yu | 6147ef4 | 2014-12-08 17:48:32 -0800 | [diff] [blame] | 411 | * @throws KeyChain::Error if identity cannot be deleted. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 412 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 413 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 414 | deleteIdentity(const Name& identity); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 415 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 416 | /** |
| 417 | * @brief export an identity. |
| 418 | * |
| 419 | * @param identity The identity to export. |
| 420 | * @param passwordStr The password to secure the private key. |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame] | 421 | * @return The encoded export data. |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 422 | * @throws SecPublicInfo::Error if anything goes wrong in exporting. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 423 | */ |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame] | 424 | shared_ptr<SecuredBag> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 425 | exportIdentity(const Name& identity, const std::string& passwordStr); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 426 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 427 | /** |
| 428 | * @brief import an identity. |
| 429 | * |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame] | 430 | * @param securedBag The encoded import data. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 431 | * @param passwordStr The password to secure the private key. |
| 432 | */ |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 433 | void |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 434 | importIdentity(const SecuredBag& securedBag, const std::string& passwordStr); |
| 435 | |
| 436 | SecPublicInfo& |
| 437 | getPib() |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 438 | { |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 439 | return *m_pib; |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 442 | const SecPublicInfo& |
| 443 | getPib() const |
| 444 | { |
| 445 | return *m_pib; |
| 446 | } |
| 447 | |
| 448 | SecTpm& |
| 449 | getTpm() |
| 450 | { |
| 451 | return *m_tpm; |
| 452 | } |
| 453 | |
| 454 | const SecTpm& |
| 455 | getTpm() const |
| 456 | { |
| 457 | return *m_tpm; |
| 458 | } |
| 459 | |
| 460 | /******************************* |
| 461 | * Wrapper of SecPublicInfo * |
| 462 | *******************************/ |
| 463 | bool |
| 464 | doesIdentityExist(const Name& identityName) const |
| 465 | { |
| 466 | return m_pib->doesIdentityExist(identityName); |
| 467 | } |
| 468 | |
| 469 | void |
| 470 | addIdentity(const Name& identityName) |
| 471 | { |
| 472 | return m_pib->addIdentity(identityName); |
| 473 | } |
| 474 | |
| 475 | bool |
| 476 | doesPublicKeyExist(const Name& keyName) const |
| 477 | { |
| 478 | return m_pib->doesPublicKeyExist(keyName); |
| 479 | } |
| 480 | |
| 481 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 482 | addPublicKey(const Name& keyName, KeyType keyType, const v1::PublicKey& publicKeyDer) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 483 | { |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 484 | return m_pib->addKey(keyName, publicKeyDer); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 487 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 488 | addKey(const Name& keyName, const v1::PublicKey& publicKeyDer) |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 489 | { |
| 490 | return m_pib->addKey(keyName, publicKeyDer); |
| 491 | } |
| 492 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 493 | shared_ptr<v1::PublicKey> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 494 | getPublicKey(const Name& keyName) const |
| 495 | { |
| 496 | return m_pib->getPublicKey(keyName); |
| 497 | } |
| 498 | |
| 499 | bool |
| 500 | doesCertificateExist(const Name& certificateName) const |
| 501 | { |
| 502 | return m_pib->doesCertificateExist(certificateName); |
| 503 | } |
| 504 | |
| 505 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 506 | addCertificate(const v1::IdentityCertificate& certificate) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 507 | { |
| 508 | return m_pib->addCertificate(certificate); |
| 509 | } |
| 510 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 511 | shared_ptr<v1::IdentityCertificate> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 512 | getCertificate(const Name& certificateName) const |
| 513 | { |
| 514 | return m_pib->getCertificate(certificateName); |
| 515 | } |
| 516 | |
| 517 | Name |
| 518 | getDefaultIdentity() const |
| 519 | { |
| 520 | return m_pib->getDefaultIdentity(); |
| 521 | } |
| 522 | |
| 523 | Name |
| 524 | getDefaultKeyNameForIdentity(const Name& identityName) const |
| 525 | { |
| 526 | return m_pib->getDefaultKeyNameForIdentity(identityName); |
| 527 | } |
| 528 | |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 529 | /** |
| 530 | * @brief Get default key parameters for the specified identity |
| 531 | * |
| 532 | * If identity has a previously generated key, the returned parameters |
| 533 | * will include the same type of the key. If there are no existing |
| 534 | * keys, DEFAULT_KEY_PARAMS is used. |
| 535 | */ |
| 536 | const KeyParams& |
| 537 | getDefaultKeyParamsForIdentity(const Name& identityName) const; |
| 538 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 539 | Name |
| 540 | getDefaultCertificateNameForKey(const Name& keyName) const |
| 541 | { |
| 542 | return m_pib->getDefaultCertificateNameForKey(keyName); |
| 543 | } |
| 544 | |
| 545 | void |
| 546 | getAllIdentities(std::vector<Name>& nameList, bool isDefault) const |
| 547 | { |
| 548 | return m_pib->getAllIdentities(nameList, isDefault); |
| 549 | } |
| 550 | |
| 551 | void |
| 552 | getAllKeyNames(std::vector<Name>& nameList, bool isDefault) const |
| 553 | { |
| 554 | return m_pib->getAllKeyNames(nameList, isDefault); |
| 555 | } |
| 556 | |
| 557 | void |
| 558 | getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, bool isDefault) const |
| 559 | { |
| 560 | return m_pib->getAllKeyNamesOfIdentity(identity, nameList, isDefault); |
| 561 | } |
| 562 | |
| 563 | void |
| 564 | getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) const |
| 565 | { |
| 566 | return m_pib->getAllCertificateNames(nameList, isDefault); |
| 567 | } |
| 568 | |
| 569 | void |
| 570 | getAllCertificateNamesOfKey(const Name& keyName, |
| 571 | std::vector<Name>& nameList, |
| 572 | bool isDefault) const |
| 573 | { |
| 574 | return m_pib->getAllCertificateNamesOfKey(keyName, nameList, isDefault); |
| 575 | } |
| 576 | |
| 577 | void |
| 578 | deleteCertificateInfo(const Name& certificateName) |
| 579 | { |
| 580 | return m_pib->deleteCertificateInfo(certificateName); |
| 581 | } |
| 582 | |
| 583 | void |
| 584 | deletePublicKeyInfo(const Name& keyName) |
| 585 | { |
| 586 | return m_pib->deletePublicKeyInfo(keyName); |
| 587 | } |
| 588 | |
| 589 | void |
| 590 | deleteIdentityInfo(const Name& identity) |
| 591 | { |
| 592 | return m_pib->deleteIdentityInfo(identity); |
| 593 | } |
| 594 | |
| 595 | void |
| 596 | setDefaultIdentity(const Name& identityName) |
| 597 | { |
| 598 | return m_pib->setDefaultIdentity(identityName); |
| 599 | } |
| 600 | |
| 601 | void |
| 602 | setDefaultKeyNameForIdentity(const Name& keyName) |
| 603 | { |
| 604 | return m_pib->setDefaultKeyNameForIdentity(keyName); |
| 605 | } |
| 606 | |
| 607 | void |
| 608 | setDefaultCertificateNameForKey(const Name& certificateName) |
| 609 | { |
| 610 | return m_pib->setDefaultCertificateNameForKey(certificateName); |
| 611 | } |
| 612 | |
| 613 | Name |
| 614 | getNewKeyName(const Name& identityName, bool useKsk) |
| 615 | { |
| 616 | return m_pib->getNewKeyName(identityName, useKsk); |
| 617 | } |
| 618 | |
| 619 | Name |
| 620 | getDefaultCertificateNameForIdentity(const Name& identityName) const |
| 621 | { |
| 622 | return m_pib->getDefaultCertificateNameForIdentity(identityName); |
| 623 | } |
| 624 | |
| 625 | Name |
| 626 | getDefaultCertificateName() const |
| 627 | { |
| 628 | return m_pib->getDefaultCertificateName(); |
| 629 | } |
| 630 | |
| 631 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 632 | addCertificateAsKeyDefault(const v1::IdentityCertificate& certificate) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 633 | { |
| 634 | return m_pib->addCertificateAsKeyDefault(certificate); |
| 635 | } |
| 636 | |
| 637 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 638 | addCertificateAsIdentityDefault(const v1::IdentityCertificate& certificate) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 639 | { |
| 640 | return m_pib->addCertificateAsIdentityDefault(certificate); |
| 641 | } |
| 642 | |
| 643 | void |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 644 | addCertificateAsSystemDefault(const v1::IdentityCertificate& certificate) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 645 | { |
| 646 | return m_pib->addCertificateAsSystemDefault(certificate); |
| 647 | } |
| 648 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 649 | shared_ptr<v1::IdentityCertificate> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 650 | getDefaultCertificate() const |
| 651 | { |
Alexander Afanasyev | aab7966 | 2014-07-07 17:35:34 -0700 | [diff] [blame] | 652 | if (!static_cast<bool>(m_pib->getDefaultCertificate())) |
| 653 | const_cast<KeyChain*>(this)->setDefaultCertificateInternal(); |
| 654 | |
| 655 | return m_pib->getDefaultCertificate(); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void |
| 659 | refreshDefaultCertificate() |
| 660 | { |
| 661 | return m_pib->refreshDefaultCertificate(); |
| 662 | } |
| 663 | |
| 664 | /******************************* |
| 665 | * Wrapper of SecTpm * |
| 666 | *******************************/ |
| 667 | |
| 668 | void |
| 669 | setTpmPassword(const uint8_t* password, size_t passwordLength) |
| 670 | { |
| 671 | return m_tpm->setTpmPassword(password, passwordLength); |
| 672 | } |
| 673 | |
| 674 | void |
| 675 | resetTpmPassword() |
| 676 | { |
| 677 | return m_tpm->resetTpmPassword(); |
| 678 | } |
| 679 | |
| 680 | void |
| 681 | setInTerminal(bool inTerminal) |
| 682 | { |
| 683 | return m_tpm->setInTerminal(inTerminal); |
| 684 | } |
| 685 | |
| 686 | bool |
| 687 | getInTerminal() const |
| 688 | { |
| 689 | return m_tpm->getInTerminal(); |
| 690 | } |
| 691 | |
| 692 | bool |
| 693 | isLocked() const |
| 694 | { |
| 695 | return m_tpm->isLocked(); |
| 696 | } |
| 697 | |
| 698 | bool |
| 699 | unlockTpm(const char* password, size_t passwordLength, bool usePassword) |
| 700 | { |
| 701 | return m_tpm->unlockTpm(password, passwordLength, usePassword); |
| 702 | } |
| 703 | |
| 704 | void |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 705 | generateKeyPairInTpm(const Name& keyName, const KeyParams& params) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 706 | { |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 707 | return m_tpm->generateKeyPairInTpm(keyName, params); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void |
| 711 | deleteKeyPairInTpm(const Name& keyName) |
| 712 | { |
| 713 | return m_tpm->deleteKeyPairInTpm(keyName); |
| 714 | } |
| 715 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 716 | shared_ptr<v1::PublicKey> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 717 | getPublicKeyFromTpm(const Name& keyName) const |
| 718 | { |
| 719 | return m_tpm->getPublicKeyFromTpm(keyName); |
| 720 | } |
| 721 | |
| 722 | Block |
| 723 | signInTpm(const uint8_t* data, size_t dataLength, |
| 724 | const Name& keyName, |
| 725 | DigestAlgorithm digestAlgorithm) |
| 726 | { |
| 727 | return m_tpm->signInTpm(data, dataLength, keyName, digestAlgorithm); |
| 728 | } |
| 729 | |
| 730 | ConstBufferPtr |
| 731 | decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) |
| 732 | { |
| 733 | return m_tpm->decryptInTpm(data, dataLength, keyName, isSymmetric); |
| 734 | } |
| 735 | |
| 736 | ConstBufferPtr |
| 737 | encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, bool isSymmetric) |
| 738 | { |
| 739 | return m_tpm->encryptInTpm(data, dataLength, keyName, isSymmetric); |
| 740 | } |
| 741 | |
| 742 | void |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 743 | generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 744 | { |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 745 | return m_tpm->generateSymmetricKeyInTpm(keyName, params); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | bool |
| 749 | doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) const |
| 750 | { |
| 751 | return m_tpm->doesKeyExistInTpm(keyName, keyClass); |
| 752 | } |
| 753 | |
| 754 | bool |
| 755 | generateRandomBlock(uint8_t* res, size_t size) const |
| 756 | { |
| 757 | return m_tpm->generateRandomBlock(res, size); |
| 758 | } |
| 759 | |
| 760 | void |
| 761 | addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, AclType acl) |
| 762 | { |
| 763 | return m_tpm->addAppToAcl(keyName, keyClass, appPath, acl); |
| 764 | } |
| 765 | |
| 766 | ConstBufferPtr |
| 767 | exportPrivateKeyPkcs5FromTpm(const Name& keyName, const std::string& password) |
| 768 | { |
| 769 | return m_tpm->exportPrivateKeyPkcs5FromTpm(keyName, password); |
| 770 | } |
| 771 | |
| 772 | bool |
| 773 | importPrivateKeyPkcs5IntoTpm(const Name& keyName, |
| 774 | const uint8_t* buf, size_t size, |
| 775 | const std::string& password) |
| 776 | { |
| 777 | return m_tpm->importPrivateKeyPkcs5IntoTpm(keyName, buf, size, password); |
| 778 | } |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 779 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 780 | private: |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 781 | void |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 782 | initialize(const std::string& pibLocatorUri, |
| 783 | const std::string& tpmLocatorUri, |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 784 | bool needReset); |
| 785 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 786 | /** |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 787 | * @brief Prepare a SignatureInfo TLV according to signing information and return the signing key name |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 788 | * |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 789 | * @param params The signing parameters. |
| 790 | * @return The signing key name and prepared SignatureInfo. |
| 791 | * @throw Error when the requested signing method cannot be satisfied. |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 792 | */ |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 793 | std::tuple<Name, SignatureInfo> |
| 794 | prepareSignatureInfo(const SigningInfo& params); |
| 795 | |
| 796 | /** |
| 797 | * @brief Internal abstraction of packet signing. |
| 798 | * |
| 799 | * @param packet The packet to sign |
| 800 | * @param params The signing parameters. |
| 801 | * @throw Error when the signing fails. |
| 802 | */ |
| 803 | template<typename T> |
| 804 | void |
| 805 | signImpl(T& packet, const SigningInfo& params); |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 806 | |
| 807 | /** |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 808 | * @brief Set default certificate if it is not initialized |
| 809 | */ |
| 810 | void |
| 811 | setDefaultCertificateInternal(); |
| 812 | |
| 813 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 814 | * @brief Generate a key pair for the specified identity. |
| 815 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 816 | * @param identityName The name of the specified identity. |
| 817 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 818 | * @param params The parameter of the key. |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 819 | * @return The name of the generated key. |
| 820 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 821 | Name |
Yingdi Yu | 4b8c6a2 | 2014-04-15 23:00:54 -0700 | [diff] [blame] | 822 | generateKeyPair(const Name& identityName, bool isKsk = false, |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 823 | const KeyParams& params = DEFAULT_KEY_PARAMS); |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 824 | |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 825 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 826 | * @brief Sign the data using a particular key. |
| 827 | * |
| 828 | * @param data Reference to the data packet. |
| 829 | * @param signature Signature to be added. |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 830 | * @param keyName The name of the signing key. |
| 831 | * @param digestAlgorithm the digest algorithm. |
| 832 | * @throws Tpm::Error |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 833 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 834 | void |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 835 | signPacketWrapper(Data& data, const Signature& signature, |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 836 | const Name& keyName, DigestAlgorithm digestAlgorithm); |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 837 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 838 | /** |
| 839 | * @brief Sign the interest using a particular key. |
| 840 | * |
| 841 | * @param interest Reference to the interest packet. |
| 842 | * @param signature Signature to be added. |
| 843 | * @param keyName The name of the signing key. |
| 844 | * @param digestAlgorithm the digest algorithm. |
| 845 | * @throws Tpm::Error |
Alexander Afanasyev | b78bc4d | 2014-04-09 21:20:52 -0700 | [diff] [blame] | 846 | */ |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 847 | void |
Yingdi Yu | c8f883c | 2014-06-20 23:25:22 -0700 | [diff] [blame] | 848 | signPacketWrapper(Interest& interest, const Signature& signature, |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 849 | const Name& keyName, DigestAlgorithm digestAlgorithm); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 850 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 851 | /** |
| 852 | * @brief Generate a SignatureValue block for a buffer @p buf with size @p size using |
| 853 | * a key with name @p keyName and digest algorithm @p digestAlgorithm. |
| 854 | */ |
| 855 | Block |
| 856 | pureSign(const uint8_t* buf, size_t size, const Name& keyName, DigestAlgorithm digestAlgorithm) const; |
| 857 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 858 | static void |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 859 | registerPibImpl(const std::string& canonicalName, |
| 860 | std::initializer_list<std::string> aliases, PibCreateFunc createFunc); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 861 | |
| 862 | static void |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 863 | registerTpmImpl(const std::string& canonicalName, |
| 864 | std::initializer_list<std::string> aliases, TpmCreateFunc createFunc); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 865 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 866 | public: |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 867 | static tlv::SignatureTypeValue |
| 868 | getSignatureType(KeyType keyType, DigestAlgorithm digestAlgorithm); |
| 869 | |
| 870 | public: |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 871 | static const Name DEFAULT_PREFIX; |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 872 | static const SigningInfo DEFAULT_SIGNING_INFO; |
| 873 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 874 | // RsaKeyParams is set to be default for backward compatibility. |
| 875 | static const RsaKeyParams DEFAULT_KEY_PARAMS; |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 876 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 877 | typedef std::map<std::string, Block> SignParams; |
| 878 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 879 | private: |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 880 | std::unique_ptr<SecPublicInfo> m_pib; |
| 881 | std::unique_ptr<SecTpm> m_tpm; |
Yingdi Yu | 0f5fb69 | 2014-06-10 12:07:28 -0700 | [diff] [blame] | 882 | time::milliseconds m_lastTimestamp; |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 883 | }; |
| 884 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 885 | template<typename T> |
| 886 | void |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 887 | KeyChain::signImpl(T& packet, const SigningInfo& params) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 888 | { |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 889 | Name keyName; |
| 890 | SignatureInfo sigInfo; |
| 891 | std::tie(keyName, sigInfo) = prepareSignatureInfo(params); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 892 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 893 | signPacketWrapper(packet, Signature(sigInfo), |
| 894 | keyName, params.getDigestAlgorithm()); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | template<typename T> |
| 898 | void |
| 899 | KeyChain::sign(T& packet, const Name& certificateName) |
| 900 | { |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 901 | signImpl(packet, SigningInfo(SigningInfo::SIGNER_TYPE_CERT, certificateName)); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | template<typename T> |
| 905 | void |
| 906 | KeyChain::signByIdentity(T& packet, const Name& identityName) |
| 907 | { |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 908 | signImpl(packet, SigningInfo(SigningInfo::SIGNER_TYPE_ID, identityName)); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 911 | template<class PibType> |
| 912 | inline void |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 913 | KeyChain::registerPib(std::initializer_list<std::string> aliases) |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 914 | { |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 915 | registerPibImpl(*aliases.begin(), aliases, [] (const std::string& locator) { |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 916 | return make_unique<PibType>(locator); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 917 | }); |
| 918 | } |
| 919 | |
| 920 | template<class TpmType> |
| 921 | inline void |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 922 | KeyChain::registerTpm(std::initializer_list<std::string> aliases) |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 923 | { |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 924 | registerTpmImpl(*aliases.begin(), aliases, [] (const std::string& locator) { |
Davide Pesavento | 409cc20 | 2015-09-19 14:13:16 +0200 | [diff] [blame] | 925 | return make_unique<TpmType>(locator); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 926 | }); |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * \brief Register SecPib class in ndn-cxx KeyChain |
| 931 | * |
| 932 | * This macro should be placed once in the implementation file of the |
| 933 | * SecPib type within the namespace where the type is declared. |
| 934 | */ |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 935 | #define NDN_CXX_KEYCHAIN_REGISTER_PIB(PibType, ...) \ |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 936 | static class NdnCxxAuto ## PibType ## PibRegistrationClass \ |
| 937 | { \ |
| 938 | public: \ |
| 939 | NdnCxxAuto ## PibType ## PibRegistrationClass() \ |
| 940 | { \ |
| 941 | ::ndn::KeyChain::registerPib<PibType>({__VA_ARGS__}); \ |
| 942 | } \ |
| 943 | } ndnCxxAuto ## PibType ## PibRegistrationVariable |
| 944 | |
| 945 | /** |
| 946 | * \brief Register SecTpm class in ndn-cxx KeyChain |
| 947 | * |
| 948 | * This macro should be placed once in the implementation file of the |
| 949 | * SecTpm type within the namespace where the type is declared. |
| 950 | */ |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 951 | #define NDN_CXX_KEYCHAIN_REGISTER_TPM(TpmType, ...) \ |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 952 | static class NdnCxxAuto ## TpmType ## TpmRegistrationClass \ |
| 953 | { \ |
| 954 | public: \ |
| 955 | NdnCxxAuto ## TpmType ## TpmRegistrationClass() \ |
| 956 | { \ |
| 957 | ::ndn::KeyChain::registerTpm<TpmType>({__VA_ARGS__}); \ |
| 958 | } \ |
| 959 | } ndnCxxAuto ## TpmType ## TpmRegistrationVariable |
| 960 | |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 961 | } // namespace security |
| 962 | |
| 963 | using security::KeyChain; |
| 964 | |
Yingdi Yu | 6ab6781 | 2014-11-27 15:00:34 -0800 | [diff] [blame] | 965 | } // namespace ndn |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 966 | |
Alexander Afanasyev | 766cea7 | 2014-04-24 19:16:42 -0700 | [diff] [blame] | 967 | #endif // NDN_SECURITY_KEY_CHAIN_HPP |