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. |
Jeff Thompson | ba16b8f | 2013-12-16 13:11:47 -0800 | [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 | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 9 | #ifndef NDN_SECURITY_KEY_CHAIN_HPP |
| 10 | #define NDN_SECURITY_KEY_CHAIN_HPP |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 11 | |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 12 | #include "identity-certificate.hpp" |
| 13 | #include "public-key.hpp" |
| 14 | #include "signature-sha256-with-rsa.hpp" |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 15 | #include "secured-bag.hpp" |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 16 | #include "../interest.hpp" |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 17 | #include "../util/random.hpp" |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 18 | |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 19 | //PublicInfo |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 20 | #include "sec-public-info-sqlite3.hpp" |
| 21 | #include "sec-public-info-memory.hpp" |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 22 | //TPM |
| 23 | #include "sec-tpm-file.hpp" |
Yingdi Yu | 4f32463 | 2014-01-15 18:10:03 -0800 | [diff] [blame] | 24 | #include "sec-tpm-memory.hpp" |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 25 | |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 26 | #ifdef NDN_CPP_HAVE_OSX_SECURITY |
| 27 | #include "sec-tpm-osx.hpp" |
| 28 | #endif |
| 29 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 30 | |
| 31 | namespace ndn { |
| 32 | |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 33 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 34 | * @brief KeyChain is one of the main classes of the security library. |
Jeff Thompson | ffa36f9 | 2013-09-20 08:42:41 -0700 | [diff] [blame] | 35 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 36 | * The KeyChain class provides a set of interfaces of identity management and private key related operations. |
Jeff Thompson | ffa36f9 | 2013-09-20 08:42:41 -0700 | [diff] [blame] | 37 | */ |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 38 | template<class Info, class Tpm> |
| 39 | class KeyChainImpl : public Info, public Tpm |
| 40 | { |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 41 | typedef SecPublicInfo::Error InfoError; |
| 42 | typedef SecTpm::Error TpmError; |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 43 | public: |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 44 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 45 | * @brief Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed certificate of the KSK. |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 46 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 47 | * @param identityName The name of the identity. |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 48 | * @return The name of the default certificate of the identity. |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 49 | */ |
| 50 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 51 | createIdentity(const Name& identityName) |
| 52 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 53 | Info::addIdentity(identityName); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 54 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 55 | Name keyName; |
| 56 | try |
| 57 | { |
| 58 | keyName = Info::getDefaultKeyNameForIdentity(identityName); |
| 59 | } |
| 60 | catch(InfoError& e) |
| 61 | { |
| 62 | keyName = generateRSAKeyPairAsDefault(identityName, true); |
| 63 | } |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 64 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 65 | Name certName; |
| 66 | try |
| 67 | { |
| 68 | certName = Info::getDefaultCertificateNameForKey(keyName); |
| 69 | } |
| 70 | catch(InfoError& e) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 71 | { |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 72 | shared_ptr<IdentityCertificate> selfCert = selfSign(keyName); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 73 | Info::addCertificateAsIdentityDefault(*selfCert); |
| 74 | certName = selfCert->getName(); |
| 75 | } |
| 76 | |
| 77 | return certName; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 78 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 79 | |
| 80 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 81 | * @brief Generate a pair of RSA keys for the specified identity. |
| 82 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 83 | * @param identityName The name of the identity. |
| 84 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 85 | * @param keySize The size of the key. |
| 86 | * @return The generated key name. |
| 87 | */ |
| 88 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 89 | generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048) |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 90 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 91 | return generateKeyPair(identityName, isKsk, KEY_TYPE_RSA, keySize); |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 92 | } |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 93 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 94 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 95 | * @brief Generate a pair of RSA keys for the specified identity and set it as default key for the identity. |
| 96 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 97 | * @param identityName The name of the identity. |
| 98 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 99 | * @param keySize The size of the key. |
| 100 | * @return The generated key name. |
| 101 | */ |
| 102 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 103 | generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048) |
| 104 | { |
| 105 | Name keyName = generateKeyPair(identityName, isKsk, KEY_TYPE_RSA, keySize); |
| 106 | |
| 107 | Info::setDefaultKeyNameForIdentity(keyName); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 108 | |
| 109 | return keyName; |
| 110 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 111 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 112 | /** |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 113 | * @brief prepare an unsigned identity certificate |
| 114 | * |
| 115 | * @param keyName Key name, e.g., /<identity_name>/ksk-123456. |
| 116 | * @param signingIdentity The signing identity. |
| 117 | * @param notBefore Refer to IdentityCertificate. |
| 118 | * @param notAfter Refer to IdentityCertificate. |
| 119 | * @param subjectDescription Refer to IdentityCertificate. |
| 120 | * @return IdentityCertificate. |
| 121 | */ |
| 122 | shared_ptr<IdentityCertificate> |
| 123 | prepareUnsignedIdentityCertificate(const Name& keyName, |
| 124 | const Name& signingIdentity, |
| 125 | const MillisecondsSince1970& notBefore, |
| 126 | const MillisecondsSince1970& notAfter, |
| 127 | const std::vector<CertificateSubjectDescription>& subjectDescription) |
| 128 | |
| 129 | { |
| 130 | if(keyName.size() < 1) |
| 131 | return shared_ptr<IdentityCertificate>(); |
| 132 | |
| 133 | std::string keyIdPrefix = keyName.get(-1).toEscapedString().substr(0, 4); |
| 134 | if(keyIdPrefix != "ksk-" && keyIdPrefix != "dsk-") |
| 135 | return shared_ptr<IdentityCertificate>(); |
| 136 | |
| 137 | shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(); |
| 138 | Name certName; |
| 139 | |
| 140 | if(signingIdentity.isPrefixOf(keyName)) |
| 141 | { |
| 142 | certName.append(signingIdentity).append("KEY").append(keyName.getSubName(signingIdentity.size())).append("ID-CERT").appendVersion(); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | certName.append(keyName.getPrefix(-1)).append("KEY").append(keyName.get(-1)).append("ID-CERT").appendVersion(); |
| 147 | } |
| 148 | |
| 149 | certificate->setName(certName); |
| 150 | certificate->setNotBefore(notBefore); |
| 151 | certificate->setNotAfter(notAfter); |
| 152 | |
| 153 | shared_ptr<PublicKey> publicKey; |
| 154 | try |
| 155 | { |
| 156 | publicKey = Info::getPublicKey(keyName); |
| 157 | } |
| 158 | catch(InfoError& e) |
| 159 | { |
| 160 | return shared_ptr<IdentityCertificate>(); |
| 161 | } |
| 162 | certificate->setPublicKeyInfo(*publicKey); |
| 163 | |
| 164 | if(subjectDescription.empty()) |
| 165 | { |
| 166 | CertificateSubjectDescription subDescryptName("2.5.4.41", keyName.getPrefix(-1).toUri()); |
| 167 | certificate->addSubjectDescription(subDescryptName); |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | std::vector<CertificateSubjectDescription>::const_iterator sdIt = subjectDescription.begin(); |
| 172 | std::vector<CertificateSubjectDescription>::const_iterator sdEnd = subjectDescription.end(); |
| 173 | for(; sdIt != sdEnd; sdIt++) |
| 174 | certificate->addSubjectDescription(*sdIt); |
| 175 | } |
| 176 | |
| 177 | certificate->encode(); |
| 178 | |
| 179 | return certificate; |
| 180 | } |
| 181 | |
| 182 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 183 | * @brief Sign packet with default identity |
| 184 | * |
| 185 | * on return signatureInfo and signatureValue in the packet are set. |
| 186 | * |
| 187 | * @param packet The packet to be signed |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 188 | */ |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 189 | template<typename T> |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 190 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 191 | sign(T& packet) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 192 | { |
| 193 | if (!Info::defaultCertificate()) |
| 194 | { |
| 195 | Info::refreshDefaultCertificate(); |
| 196 | |
| 197 | if(!Info::defaultCertificate()) |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 198 | { |
| 199 | Name defaultIdentity; |
| 200 | try |
| 201 | { |
| 202 | defaultIdentity = Info::getDefaultIdentity(); |
| 203 | } |
| 204 | catch(InfoError& e) |
| 205 | { |
| 206 | uint32_t random = random::generateWord32(); |
| 207 | defaultIdentity.append("tmp-identity").append(reinterpret_cast<uint8_t*>(&random), 4); |
| 208 | } |
| 209 | createIdentity(defaultIdentity); |
| 210 | Info::refreshDefaultCertificate(); |
| 211 | } |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 214 | sign(packet, *Info::defaultCertificate()); |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 215 | } |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 216 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 217 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 218 | * @brief Sign packet with a particular certificate. |
| 219 | * |
| 220 | * @param packet The packet to be signed. |
| 221 | * @param certificateName The certificate name of the key to use for signing. |
| 222 | * @throws SecPublicInfo::Error if certificate does not exist. |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 223 | */ |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 224 | template<typename T> |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 225 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 226 | sign(T& packet, const Name& certificateName) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 227 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 228 | if (!Info::doesCertificateExist(certificateName)) |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 229 | throw InfoError("Requested certificate [" + certificateName.toUri() + "] doesn't exist"); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 230 | |
| 231 | SignatureSha256WithRsa signature; |
| 232 | signature.setKeyLocator(certificateName.getPrefix(-1)); // implicit conversion should take care |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 233 | |
| 234 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 235 | signPacketWrapper(packet, signature, |
| 236 | IdentityCertificate::certificateNameToPublicKeyName(certificateName), |
| 237 | DIGEST_ALGORITHM_SHA256); |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 238 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 239 | |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 240 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 241 | * @brief Sign the byte array using a particular certificate. |
| 242 | * |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 243 | * @param buffer The byte array to be signed. |
| 244 | * @param bufferLength the length of buffer. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 245 | * @param certificateName The certificate name of the signing key. |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 246 | * @return The Signature. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 247 | * @throws SecPublicInfo::Error if certificate does not exist. |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 248 | */ |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 249 | Signature |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 250 | sign(const uint8_t* buffer, size_t bufferLength, const Name& certificateName) |
| 251 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 252 | if (!Info::doesCertificateExist(certificateName)) |
Yingdi Yu | 4270f20 | 2014-01-28 14:19:16 -0800 | [diff] [blame] | 253 | throw InfoError("Requested certificate [" + certificateName.toUri() + "] doesn't exist"); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 254 | |
| 255 | SignatureSha256WithRsa signature; |
| 256 | signature.setKeyLocator(certificateName.getPrefix(-1)); // implicit conversion should take care |
| 257 | |
| 258 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 259 | signature.setValue(Tpm::signInTpm(buffer, bufferLength, |
| 260 | IdentityCertificate::certificateNameToPublicKeyName(certificateName), |
| 261 | DIGEST_ALGORITHM_SHA256)); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 262 | return signature; |
| 263 | } |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 264 | |
| 265 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 266 | * @brief Sign packet using the default certificate of a particular identity. |
| 267 | * |
| 268 | * If there is no default certificate of that identity, this method will create a self-signed certificate. |
| 269 | * |
| 270 | * @param packet The packet to be signed. |
| 271 | * @param identityName The signing identity name. |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 272 | */ |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 273 | template<typename T> |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 274 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 275 | signByIdentity(T& packet, const Name& identityName) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 276 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 277 | Name signingCertificateName; |
| 278 | try |
| 279 | { |
| 280 | signingCertificateName = Info::getDefaultCertificateNameForIdentity(identityName); |
| 281 | } |
| 282 | catch(InfoError& e) |
| 283 | { |
| 284 | signingCertificateName = createIdentity(identityName); |
| 285 | // Ideally, no exception will be thrown out, unless something goes wrong in the TPM, which is a fatal error. |
| 286 | } |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 287 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 288 | // We either get or create the signing certificate, sign packet! (no exception unless fatal error in TPM) |
| 289 | sign(packet, signingCertificateName); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 290 | } |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 291 | |
| 292 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 293 | * @brief Sign the byte array using the default certificate of a particular identity. |
| 294 | * |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 295 | * @param buffer The byte array to be signed. |
| 296 | * @param bufferLength the length of buffer. |
| 297 | * @param identityName The identity name. |
| 298 | * @return The Signature. |
| 299 | */ |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 300 | Signature |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 301 | signByIdentity(const uint8_t* buffer, size_t bufferLength, const Name& identityName) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 302 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 303 | Name signingCertificateName; |
| 304 | try |
| 305 | { |
| 306 | signingCertificateName = Info::getDefaultCertificateNameForIdentity(identityName); |
| 307 | } |
| 308 | catch(InfoError& e) |
| 309 | { |
| 310 | signingCertificateName = createIdentity(identityName); |
| 311 | // Ideally, no exception will be thrown out, unless something goes wrong in the TPM, which is a fatal error. |
| 312 | } |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 313 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 314 | // We either get or create the signing certificate, sign data! (no exception unless fatal error in TPM) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 315 | return sign(buffer, bufferLength, signingCertificateName); |
| 316 | } |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 317 | |
| 318 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 319 | * @brief Generate a self-signed certificate for a public key. |
| 320 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 321 | * @param keyName The name of the public key. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 322 | * @return The generated certificate, NULL if selfSign fails. |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 323 | */ |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 324 | shared_ptr<IdentityCertificate> |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 325 | selfSign(const Name& keyName) |
| 326 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 327 | shared_ptr<PublicKey> pubKey; |
| 328 | try |
| 329 | { |
| 330 | pubKey = Info::getPublicKey(keyName); // may throw an exception. |
| 331 | } |
| 332 | catch(InfoError& e) |
| 333 | { |
| 334 | return shared_ptr<IdentityCertificate>(); |
| 335 | } |
Yingdi Yu | 7ea6950 | 2014-01-15 17:21:29 -0800 | [diff] [blame] | 336 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 337 | shared_ptr<IdentityCertificate> certificate = make_shared<IdentityCertificate>(); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 338 | |
| 339 | Name certificateName = keyName.getPrefix(-1); |
| 340 | certificateName.append("KEY").append(keyName.get(-1)).append("ID-CERT").appendVersion(); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 341 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 342 | certificate->setName(certificateName); |
| 343 | certificate->setNotBefore(getNow()); |
| 344 | certificate->setNotAfter(getNow() + 630720000 /* 20 years*/); |
| 345 | certificate->setPublicKeyInfo(*pubKey); |
| 346 | certificate->addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri())); |
| 347 | certificate->encode(); |
| 348 | |
| 349 | selfSign(*certificate); |
| 350 | return certificate; |
| 351 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 352 | |
| 353 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 354 | * @brief Self-sign the supplied identity certificate. |
| 355 | * |
| 356 | * @param cert The supplied cert. |
| 357 | * @throws SecTpm::Error if the private key does not exist. |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 358 | */ |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 359 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 360 | selfSign (IdentityCertificate& cert) |
| 361 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 362 | Name keyName = IdentityCertificate::certificateNameToPublicKeyName(cert.getName()); |
| 363 | if(!Tpm::doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE)) |
| 364 | throw TpmError("private key does not exist!"); |
| 365 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 366 | SignatureSha256WithRsa signature; |
| 367 | signature.setKeyLocator(cert.getName().getPrefix(-1)); // implicit conversion should take care |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 368 | |
| 369 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 370 | signPacketWrapper(cert, signature, keyName, DIGEST_ALGORITHM_SHA256); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 373 | /** |
| 374 | * @brief delete a certificate. |
| 375 | * |
| 376 | * If the certificate to be deleted is current default system default, |
| 377 | * the method will not delete the certificate and return immediately. |
| 378 | * |
| 379 | * @param certificateName The certificate to be deleted. |
| 380 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 381 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 382 | deleteCertificate (const Name& certificateName) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 383 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 384 | try |
| 385 | { |
| 386 | if(Info::getDefaultCertificateName() == certificateName) |
| 387 | return; |
| 388 | } |
| 389 | catch(InfoError& e) |
| 390 | { |
| 391 | // Not a real error, just try to delete the certificate |
| 392 | } |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 393 | |
| 394 | Info::deleteCertificateInfo(certificateName); |
| 395 | } |
| 396 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 397 | /** |
| 398 | * @brief delete a key. |
| 399 | * |
| 400 | * If the key to be deleted is current default system default, |
| 401 | * the method will not delete the key and return immediately. |
| 402 | * |
| 403 | * @param keyName The key to be deleted. |
| 404 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 405 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 406 | deleteKey (const Name& keyName) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 407 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 408 | try |
| 409 | { |
| 410 | if(Info::getDefaultKeyNameForIdentity(Info::getDefaultIdentity()) == keyName) |
| 411 | return; |
| 412 | } |
| 413 | catch(InfoError& e) |
| 414 | { |
| 415 | // Not a real error, just try to delete the key |
| 416 | } |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 417 | |
| 418 | Info::deletePublicKeyInfo(keyName); |
| 419 | Tpm::deleteKeyPairInTpm(keyName); |
| 420 | } |
| 421 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 422 | /** |
| 423 | * @brief delete an identity. |
| 424 | * |
| 425 | * If the identity to be deleted is current default system default, |
| 426 | * the method will not delete the identity and return immediately. |
| 427 | * |
| 428 | * @param identity The identity to be deleted. |
| 429 | */ |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 430 | void |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 431 | deleteIdentity (const Name& identity) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 432 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 433 | try |
| 434 | { |
| 435 | if(Info::getDefaultIdentity() == identity) |
| 436 | return; |
| 437 | } |
| 438 | catch(InfoError& e) |
| 439 | { |
| 440 | // Not a real error, just try to delete the identity |
| 441 | } |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 442 | |
| 443 | std::vector<Name> nameList; |
| 444 | Info::getAllKeyNamesOfIdentity(identity, nameList, true); |
| 445 | Info::getAllKeyNamesOfIdentity(identity, nameList, false); |
| 446 | |
| 447 | Info::deleteIdentityInfo(identity); |
| 448 | |
| 449 | std::vector<Name>::const_iterator it = nameList.begin(); |
| 450 | for(; it != nameList.end(); it++) |
| 451 | Tpm::deleteKeyPairInTpm(*it); |
| 452 | } |
| 453 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 454 | /** |
| 455 | * @brief export an identity. |
| 456 | * |
| 457 | * @param identity The identity to export. |
| 458 | * @param passwordStr The password to secure the private key. |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 459 | * @return The encoded export data. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 460 | * @throws InfoError if anything goes wrong in exporting. |
| 461 | */ |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 462 | shared_ptr<SecuredBag> |
Yingdi Yu | be4150e | 2014-02-18 13:02:46 -0800 | [diff] [blame] | 463 | exportIdentity(const Name& identity, const std::string& passwordStr) |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 464 | { |
| 465 | if (!Info::doesIdentityExist(identity)) |
| 466 | throw InfoError("Identity does not exist!"); |
| 467 | |
| 468 | Name keyName = Info::getDefaultKeyNameForIdentity(identity); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 469 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 470 | ConstBufferPtr pkcs8; |
| 471 | try |
| 472 | { |
| 473 | pkcs8 = Tpm::exportPrivateKeyPkcs8FromTpm(keyName, passwordStr); |
| 474 | } |
| 475 | catch(TpmError& e) |
| 476 | { |
| 477 | throw InfoError("Fail to export PKCS8 of private key"); |
| 478 | } |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 479 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 480 | shared_ptr<IdentityCertificate> cert; |
| 481 | try |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 482 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 483 | cert = Info::getCertificate(Info::getDefaultCertificateNameForKey(keyName)); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 484 | } |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 485 | catch(InfoError& e) |
| 486 | { |
| 487 | cert = selfSign(keyName); |
| 488 | Info::addCertificateAsIdentityDefault(*cert); |
| 489 | } |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 490 | |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 491 | shared_ptr<SecuredBag> secureBag = make_shared<SecuredBag>(boost::cref(*cert), boost::cref(pkcs8)); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 492 | |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 493 | return secureBag; |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 494 | } |
| 495 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 496 | /** |
| 497 | * @brief import an identity. |
| 498 | * |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 499 | * @param securedBag The encoded import data. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 500 | * @param passwordStr The password to secure the private key. |
| 501 | */ |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 502 | void |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 503 | importIdentity(const SecuredBag& securedBag, const std::string& passwordStr) |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 504 | { |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 505 | Name keyName = IdentityCertificate::certificateNameToPublicKeyName(securedBag.getCertificate().getName()); |
| 506 | Name identity = keyName.getPrefix(-1); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 507 | |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 508 | // Add identity |
| 509 | Info::addIdentity(identity); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 510 | |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 511 | // Add key |
| 512 | Tpm::importPrivateKeyPkcs8IntoTpm(keyName, securedBag.getKey()->buf(), securedBag.getKey()->size(), passwordStr); |
| 513 | shared_ptr<PublicKey> pubKey = Tpm::getPublicKeyFromTpm(keyName.toUri()); |
| 514 | Info::addPublicKey(keyName, KEY_TYPE_RSA, *pubKey); // HACK! We should set key type according to the pkcs8 info. |
| 515 | Info::setDefaultKeyNameForIdentity(keyName); |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 516 | |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame^] | 517 | // Add cert |
| 518 | Info::addCertificateAsIdentityDefault(securedBag.getCertificate()); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 521 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 522 | private: |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 523 | /** |
| 524 | * @brief sign a packet using a pariticular certificate. |
| 525 | * |
| 526 | * @param packet The packet to be signed. |
| 527 | * @param certificate The signing certificate. |
| 528 | */ |
| 529 | template<typename T> |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 530 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 531 | sign(T& packet, const IdentityCertificate& certificate) |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 532 | { |
| 533 | SignatureSha256WithRsa signature; |
| 534 | signature.setKeyLocator(certificate.getName().getPrefix(-1)); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 535 | |
| 536 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 537 | signPacketWrapper(packet, signature, certificate.getPublicKeyName(), DIGEST_ALGORITHM_SHA256); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 538 | } |
| 539 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 540 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 541 | * @brief Generate a key pair for the specified identity. |
| 542 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 543 | * @param identityName The name of the specified identity. |
| 544 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 545 | * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA. |
| 546 | * @param keySize The size of the key pair. |
| 547 | * @return The name of the generated key. |
| 548 | */ |
| 549 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 550 | generateKeyPair(const Name& identityName, bool isKsk = false, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) |
| 551 | { |
| 552 | Name keyName = Info::getNewKeyName(identityName, isKsk); |
| 553 | |
| 554 | Tpm::generateKeyPairInTpm(keyName.toUri(), keyType, keySize); |
| 555 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 556 | shared_ptr<PublicKey> pubKey = Tpm::getPublicKeyFromTpm(keyName.toUri()); |
Yingdi Yu | ef26ee3 | 2014-01-15 16:41:14 -0800 | [diff] [blame] | 557 | Info::addPublicKey(keyName, keyType, *pubKey); |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 558 | |
| 559 | return keyName; |
| 560 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 561 | |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 562 | /** |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 563 | * @brief Sign the data using a particular key. |
| 564 | * |
| 565 | * @param data Reference to the data packet. |
| 566 | * @param signature Signature to be added. |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 567 | * @param keyName The name of the signing key. |
| 568 | * @param digestAlgorithm the digest algorithm. |
| 569 | * @throws Tpm::Error |
| 570 | */ |
| 571 | void |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 572 | signPacketWrapper(Data& data, const SignatureSha256WithRsa& signature, const Name& keyName, DigestAlgorithm digestAlgorithm) |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 573 | { |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 574 | data.setSignature(signature); |
Yingdi Yu | 8726f65 | 2014-01-23 10:35:12 -0800 | [diff] [blame] | 575 | data.setSignatureValue |
| 576 | (Tpm::signInTpm(data.wireEncode().value(), |
| 577 | data.wireEncode().value_size() - data.getSignature().getValue().size(), |
| 578 | keyName, digestAlgorithm)); |
| 579 | } |
| 580 | |
Yingdi Yu | 2e57a58 | 2014-02-20 23:34:43 -0800 | [diff] [blame] | 581 | /** |
| 582 | * @brief Sign the interest using a particular key. |
| 583 | * |
| 584 | * @param interest Reference to the interest packet. |
| 585 | * @param signature Signature to be added. |
| 586 | * @param keyName The name of the signing key. |
| 587 | * @param digestAlgorithm the digest algorithm. |
| 588 | * @throws Tpm::Error |
| 589 | */ |
| 590 | void |
| 591 | signPacketWrapper(Interest& interest, const SignatureSha256WithRsa& signature, const Name& keyName, DigestAlgorithm digestAlgorithm) |
| 592 | { |
| 593 | Name signedName = Name(interest.getName()).append(signature.getInfo()); |
| 594 | |
| 595 | Block sigValue = Tpm::signInTpm(signedName.wireEncode().value(), |
| 596 | signedName.wireEncode().value_size(), |
| 597 | keyName, |
| 598 | DIGEST_ALGORITHM_SHA256); |
| 599 | sigValue.encode(); |
| 600 | signedName.append(sigValue); |
| 601 | interest.setName(signedName); |
| 602 | } |
| 603 | |
| 604 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 605 | }; |
| 606 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 607 | } // namespace ndn |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 608 | |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 609 | |
| 610 | |
Alexander Afanasyev | 3e08d5d | 2014-02-12 19:24:28 -0800 | [diff] [blame] | 611 | #if defined(NDN_CPP_HAVE_OSX_SECURITY) and defined(NDN_CPP_WITH_OSX_KEYCHAIN) |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 612 | |
| 613 | namespace ndn |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 614 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 615 | typedef KeyChainImpl<SecPublicInfoSqlite3, SecTpmOsx> KeyChain; |
| 616 | }; |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 617 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 618 | #else |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 619 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 620 | namespace ndn |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 621 | { |
Yingdi Yu | 0402092 | 2014-01-22 12:46:53 -0800 | [diff] [blame] | 622 | typedef KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> KeyChain; |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 623 | }; |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 624 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 625 | #endif //NDN_CPP_HAVE_OSX_SECURITY |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 626 | |
Yingdi Yu | fc40d87 | 2014-02-18 12:56:04 -0800 | [diff] [blame] | 627 | #endif //NDN_SECURITY_KEY_CHAIN_HPP |