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 | |
| 9 | #ifndef NDN_KEY_CHAIN_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 10 | #define NDN_KEY_CHAIN_HPP |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 11 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 12 | #include "certificate/identity-certificate.hpp" |
| 13 | #include "certificate/public-key.hpp" |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 14 | #include "signature/signature-sha256-with-rsa.hpp" |
| 15 | |
| 16 | #include "identity/sec-public-info-sqlite3.hpp" |
| 17 | #include "identity/sec-public-info-memory.hpp" |
| 18 | #include "identity/sec-tpm-osx.hpp" |
| 19 | #include "identity/sec-tpm-memory.hpp" |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 20 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 21 | |
| 22 | namespace ndn { |
| 23 | |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 24 | /** |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 25 | * KeyChain is one of the main classes of the security library. |
Jeff Thompson | ffa36f9 | 2013-09-20 08:42:41 -0700 | [diff] [blame] | 26 | * |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 27 | * 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] | 28 | */ |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 29 | template<class Info, class Tpm> |
| 30 | class KeyChainImpl : public Info, public Tpm |
| 31 | { |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 32 | public: |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 33 | // struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Create an identity by creating a pair of Key-Signing-Key (KSK) for this identity and a self-signed certificate of the KSK. |
| 37 | * @param identityName The name of the identity. |
| 38 | * @return The key name of the auto-generated KSK of the identity. |
| 39 | */ |
| 40 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 41 | createIdentity(const Name& identityName) |
| 42 | { |
| 43 | if (!Info::doesIdentityExist(identityName)) { |
| 44 | Info::addIdentity(identityName); |
| 45 | |
| 46 | Name keyName = generateRSAKeyPairAsDefault(identityName, true); |
| 47 | |
| 48 | ptr_lib::shared_ptr<IdentityCertificate> selfCert = selfSign(keyName); |
| 49 | |
| 50 | Info::addCertificateAsDefault(*selfCert); |
| 51 | |
| 52 | return keyName; |
| 53 | } |
| 54 | else |
| 55 | return Name(); |
| 56 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 59 | * Generate a pair of RSA keys for the specified identity. |
| 60 | * @param identityName The name of the identity. |
| 61 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 62 | * @param keySize The size of the key. |
| 63 | * @return The generated key name. |
| 64 | */ |
| 65 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 66 | generateRSAKeyPair(const Name& identityName, bool isKsk = false, int keySize = 2048) |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 67 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 68 | return generateKeyPair(identityName, isKsk, KEY_TYPE_RSA, keySize); |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 69 | } |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 70 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 71 | /** |
| 72 | * Generate a pair of RSA keys for the specified identity and set it as default key for the identity. |
| 73 | * @param identityName The name of the identity. |
| 74 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 75 | * @param keySize The size of the key. |
| 76 | * @return The generated key name. |
| 77 | */ |
| 78 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 79 | generateRSAKeyPairAsDefault(const Name& identityName, bool isKsk = false, int keySize = 2048) |
| 80 | { |
| 81 | Name keyName = generateKeyPair(identityName, isKsk, KEY_TYPE_RSA, keySize); |
| 82 | |
| 83 | Info::setDefaultKeyNameForIdentity(keyName); |
| 84 | |
| 85 | Info::refreshDefaultCertificate(); |
| 86 | |
| 87 | return keyName; |
| 88 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 89 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 90 | /** |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 91 | * Create an identity certificate for a public key managed by this IdentityManager. |
| 92 | * @param certificatePrefix The name of public key to be signed. |
| 93 | * @param signerCertificateName The name of signing certificate. |
| 94 | * @param notBefore The notBefore value in the validity field of the generated certificate. |
| 95 | * @param notAfter The notAfter vallue in validity field of the generated certificate. |
| 96 | * @return The name of generated identity certificate. |
| 97 | */ |
| 98 | ptr_lib::shared_ptr<IdentityCertificate> |
| 99 | createIdentityCertificate |
| 100 | (const Name& certificatePrefix, |
| 101 | const Name& signerCertificateName, |
| 102 | const MillisecondsSince1970& notBefore, |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 103 | const MillisecondsSince1970& notAfter) |
| 104 | { |
| 105 | Name keyName = getKeyNameFromCertificatePrefix(certificatePrefix); |
| 106 | |
| 107 | ptr_lib::shared_ptr<PublicKey> pubKey = Info::getPublicKey(keyName); |
| 108 | if (!pubKey) |
| 109 | throw std::runtime_error("Requested public key [" + keyName.toUri() + "] doesn't exist"); |
| 110 | |
| 111 | ptr_lib::shared_ptr<IdentityCertificate> certificate = |
| 112 | createIdentityCertificate(certificatePrefix, |
| 113 | *pubKey, |
| 114 | signerCertificateName, |
| 115 | notBefore, notAfter); |
| 116 | |
| 117 | Info::addCertificate(*certificate); |
| 118 | |
| 119 | return certificate; |
| 120 | } |
| 121 | |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 122 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 123 | /** |
| 124 | * Create an identity certificate for a public key supplied by the caller. |
| 125 | * @param certificatePrefix The name of public key to be signed. |
| 126 | * @param publickey The public key to be signed. |
| 127 | * @param signerCertificateName The name of signing certificate. |
| 128 | * @param notBefore The notBefore value in the validity field of the generated certificate. |
| 129 | * @param notAfter The notAfter vallue in validity field of the generated certificate. |
| 130 | * @return The generated identity certificate. |
| 131 | */ |
| 132 | ptr_lib::shared_ptr<IdentityCertificate> |
| 133 | createIdentityCertificate |
| 134 | (const Name& certificatePrefix, |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 135 | const PublicKey& publicKey, |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 136 | const Name& signerCertificateName, |
| 137 | const MillisecondsSince1970& notBefore, |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 138 | const MillisecondsSince1970& notAfter) |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 139 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 140 | ptr_lib::shared_ptr<IdentityCertificate> certificate (new IdentityCertificate()); |
| 141 | Name keyName = getKeyNameFromCertificatePrefix(certificatePrefix); |
| 142 | |
| 143 | Name certificateName = certificatePrefix; |
| 144 | certificateName.append("ID-CERT").appendVersion(); |
| 145 | |
| 146 | certificate->setName(certificateName); |
| 147 | certificate->setNotBefore(notBefore); |
| 148 | certificate->setNotAfter(notAfter); |
| 149 | certificate->setPublicKeyInfo(publicKey); |
| 150 | certificate->addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri())); |
| 151 | certificate->encode(); |
| 152 | |
| 153 | sign(*certificate, signerCertificateName); |
| 154 | |
| 155 | return certificate; |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 158 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 159 | sign(Data &data) |
| 160 | { |
| 161 | if (!Info::defaultCertificate()) |
| 162 | { |
| 163 | Info::refreshDefaultCertificate(); |
| 164 | |
| 165 | if(!Info::defaultCertificate()) |
| 166 | throw std::runtime_error("Default IdentityCertificate cannot be determined"); |
| 167 | } |
| 168 | |
| 169 | sign(data, *Info::defaultCertificate()); |
| 170 | } |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 171 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 172 | /** |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 173 | * Wire encode the Data object, sign it and set its signature. |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 174 | * @param data The Data object to be signed. This updates its signature and key locator field and wireEncoding. |
Jeff Thompson | 9296f0c | 2013-09-23 18:10:27 -0700 | [diff] [blame] | 175 | * @param certificateName The certificate name of the key to use for signing. If omitted, infer the signing identity from the data packet name. |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 176 | */ |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 177 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 178 | sign(Data& data, const Name& certificateName) |
| 179 | { |
| 180 | ptr_lib::shared_ptr<IdentityCertificate> cert = Info::getCertificate(certificateName); |
| 181 | if (!cert) |
| 182 | throw std::runtime_error("Requested certificate [" + certificateName.toUri() + "] doesn't exist"); |
| 183 | |
| 184 | SignatureSha256WithRsa signature; |
| 185 | signature.setKeyLocator(certificateName.getPrefix(-1)); // implicit conversion should take care |
| 186 | data.setSignature(signature); |
| 187 | |
| 188 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
| 189 | Tpm::sign(data, cert->getPublicKeyName(), DIGEST_ALGORITHM_SHA256); |
| 190 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 191 | |
| 192 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 193 | sign(Data& data, const IdentityCertificate& certificate) |
| 194 | { |
| 195 | SignatureSha256WithRsa signature; |
| 196 | signature.setKeyLocator(certificate.getName().getPrefix(-1)); |
| 197 | data.setSignature(signature); |
| 198 | |
| 199 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
| 200 | Tpm::sign(data, certificate.getPublicKeyName(), DIGEST_ALGORITHM_SHA256); |
| 201 | } |
Jeff Thompson | 79a2d5d | 2013-09-27 14:32:23 -0700 | [diff] [blame] | 202 | |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 203 | /** |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 204 | * Sign the byte array using a certificate name and return a Signature object. |
| 205 | * @param buffer The byte array to be signed. |
| 206 | * @param bufferLength the length of buffer. |
| 207 | * @param certificateName The certificate name used to get the signing key and which will be put into KeyLocator. |
| 208 | * @return The Signature. |
| 209 | */ |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 210 | Signature |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 211 | sign(const uint8_t* buffer, size_t bufferLength, const Name& certificateName) |
| 212 | { |
| 213 | ptr_lib::shared_ptr<IdentityCertificate> cert = Info::getCertificate(certificateName); |
| 214 | if (!cert) |
| 215 | throw std::runtime_error("Requested certificate [" + certificateName.toUri() + "] doesn't exist"); |
| 216 | |
| 217 | SignatureSha256WithRsa signature; |
| 218 | signature.setKeyLocator(certificateName.getPrefix(-1)); // implicit conversion should take care |
| 219 | |
| 220 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
| 221 | signature.setValue(Tpm::sign(buffer, bufferLength, cert->getPublicKeyName(), DIGEST_ALGORITHM_SHA256)); |
| 222 | return signature; |
| 223 | } |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 224 | |
| 225 | /** |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 226 | * Wire encode the Data object, sign it and set its signature. |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 227 | * @param data The Data object to be signed. This updates its signature and key locator field and wireEncoding. |
| 228 | * @param identityName The identity name for the key to use for signing. If omitted, infer the signing identity from the data packet name. |
Jeff Thompson | 29ce310 | 2013-09-27 11:47:48 -0700 | [diff] [blame] | 229 | */ |
| 230 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 231 | signByIdentity(Data& data, const Name& identityName = Name()) |
| 232 | { |
| 233 | Name signingCertificateName = Info::getDefaultCertificateNameForIdentity(identityName); |
| 234 | |
| 235 | if (signingCertificateName.getComponentCount() == 0) |
| 236 | throw std::runtime_error("No qualified certificate name found!"); |
| 237 | |
| 238 | sign(data, signingCertificateName); |
| 239 | } |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 240 | |
| 241 | /** |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 242 | * Sign the byte array using an identity name and return a Signature object. |
| 243 | * @param buffer The byte array to be signed. |
| 244 | * @param bufferLength the length of buffer. |
| 245 | * @param identityName The identity name. |
| 246 | * @return The Signature. |
| 247 | */ |
Alexander Afanasyev | 64a3d81 | 2014-01-05 23:35:05 -0800 | [diff] [blame] | 248 | Signature |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 249 | signByIdentity(const uint8_t* buffer, size_t bufferLength, const Name& identityName = Name()) |
| 250 | { |
| 251 | Name signingCertificateName = Info::getDefaultCertificateNameForIdentity(identityName); |
| 252 | |
| 253 | if (signingCertificateName.size() == 0) |
| 254 | throw std::runtime_error("No qualified certificate name found!"); |
| 255 | |
| 256 | return sign(buffer, bufferLength, signingCertificateName); |
| 257 | } |
Jeff Thompson | c01e178 | 2013-10-21 14:08:42 -0700 | [diff] [blame] | 258 | |
| 259 | /** |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 260 | * Generate a self-signed certificate for a public key. |
| 261 | * @param keyName The name of the public key. |
| 262 | * @return The generated certificate. |
| 263 | */ |
| 264 | ptr_lib::shared_ptr<IdentityCertificate> |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 265 | selfSign(const Name& keyName) |
| 266 | { |
| 267 | ptr_lib::shared_ptr<IdentityCertificate> certificate = ptr_lib::make_shared<IdentityCertificate>(); |
| 268 | |
| 269 | Name certificateName = keyName.getPrefix(-1); |
| 270 | certificateName.append("KEY").append(keyName.get(-1)).append("ID-CERT").appendVersion(); |
| 271 | |
| 272 | ptr_lib::shared_ptr<PublicKey> pubKey = Info::getPublicKey(keyName); |
| 273 | if (!pubKey) |
| 274 | throw std::runtime_error("Requested public key [" + keyName.toUri() + "] doesn't exist"); |
| 275 | |
| 276 | certificate->setName(certificateName); |
| 277 | certificate->setNotBefore(getNow()); |
| 278 | certificate->setNotAfter(getNow() + 630720000 /* 20 years*/); |
| 279 | certificate->setPublicKeyInfo(*pubKey); |
| 280 | certificate->addSubjectDescription(CertificateSubjectDescription("2.5.4.41", keyName.toUri())); |
| 281 | certificate->encode(); |
| 282 | |
| 283 | selfSign(*certificate); |
| 284 | return certificate; |
| 285 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 286 | |
| 287 | /** |
| 288 | * @brief Self-sign the supplied identity certificate |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 289 | */ |
Jeff Thompson | 2ce8f49 | 2013-09-17 18:01:25 -0700 | [diff] [blame] | 290 | void |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 291 | selfSign (IdentityCertificate& cert) |
| 292 | { |
| 293 | SignatureSha256WithRsa signature; |
| 294 | signature.setKeyLocator(cert.getName().getPrefix(-1)); // implicit conversion should take care |
| 295 | cert.setSignature(signature); |
| 296 | |
| 297 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
| 298 | Tpm::sign(cert, cert.getPublicKeyName(), DIGEST_ALGORITHM_SHA256); |
| 299 | } |
| 300 | |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 301 | |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 302 | private: |
| 303 | /** |
| 304 | * Generate a key pair for the specified identity. |
| 305 | * @param identityName The name of the specified identity. |
| 306 | * @param isKsk true for generating a Key-Signing-Key (KSK), false for a Data-Signing-Key (KSK). |
| 307 | * @param keyType The type of the key pair, e.g. KEY_TYPE_RSA. |
| 308 | * @param keySize The size of the key pair. |
| 309 | * @return The name of the generated key. |
| 310 | */ |
| 311 | Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 312 | generateKeyPair(const Name& identityName, bool isKsk = false, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) |
| 313 | { |
| 314 | Name keyName = Info::getNewKeyName(identityName, isKsk); |
| 315 | |
| 316 | Tpm::generateKeyPairInTpm(keyName.toUri(), keyType, keySize); |
| 317 | |
| 318 | ptr_lib::shared_ptr<PublicKey> pubKey = Tpm::getPublicKeyFromTpm(keyName.toUri()); |
| 319 | Tpm::addPublicKey(keyName, keyType, *pubKey); |
| 320 | |
| 321 | return keyName; |
| 322 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 323 | |
| 324 | static Name |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 325 | getKeyNameFromCertificatePrefix(const Name& certificatePrefix) |
| 326 | { |
| 327 | Name result; |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 328 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 329 | std::string keyString("KEY"); |
| 330 | int i = 0; |
| 331 | for(; i < certificatePrefix.size(); i++) { |
| 332 | if (certificatePrefix.get(i).toEscapedString() == keyString) |
| 333 | break; |
| 334 | } |
Alexander Afanasyev | bf1a67a | 2014-01-05 23:36:13 -0800 | [diff] [blame] | 335 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 336 | if (i >= certificatePrefix.size()) |
| 337 | throw std::runtime_error("Identity Certificate Prefix does not have a KEY component"); |
Alexander Afanasyev | bd5ba40 | 2014-01-05 22:41:09 -0800 | [diff] [blame] | 338 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 339 | result.append(certificatePrefix.getSubName(0, i)); |
| 340 | result.append(certificatePrefix.getSubName(i + 1, certificatePrefix.size()-i-1)); |
| 341 | |
| 342 | return result; |
| 343 | } |
| 344 | |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 345 | }; |
| 346 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 347 | } |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 348 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 349 | #ifdef NDN_CPP_HAVE_OSX_SECURITY |
| 350 | |
| 351 | namespace ndn |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 352 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 353 | typedef KeyChainImpl<SecPublicInfoSqlite3, SecTpmOsx> KeyChain; |
| 354 | }; |
Yingdi Yu | 2abd73f | 2014-01-08 23:34:11 -0800 | [diff] [blame] | 355 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 356 | #else |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 357 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 358 | namespace ndn |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 359 | { |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 360 | typedef KeyChainImpl<SecPublicInfoMemory, SecTpmMemory> KeyChain; |
| 361 | }; |
Alexander Afanasyev | e64788e | 2014-01-05 22:38:21 -0800 | [diff] [blame] | 362 | |
Yingdi Yu | 31b4af2 | 2014-01-14 14:13:00 -0800 | [diff] [blame] | 363 | #endif //NDN_CPP_HAVE_OSX_SECURITY |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 364 | |
| 365 | #endif |