Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #include "dummy-keychain.hpp" |
| 23 | |
| 24 | #include "util/io.hpp" |
| 25 | #include <boost/iostreams/device/array.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace security { |
| 29 | |
| 30 | static const uint8_t DUMMY_CERT[] = |
| 31 | "Bv0C8Ac4CAVkdW1teQgDa2V5CANLRVkIEWtzay0xNDE4NjAwMzkxMDUwCAdJRC1D" |
| 32 | "RVJUCAn9AAABSkssIl4UAxgBAhX9AXMwggFvMCIYDzIwMTQxMjE0MjMzOTUxWhgP" |
| 33 | "MjAzNDEyMDkyMzM5NTFaMCUwIwYDVQQpExwvZHVtbXkva2V5L2tzay0xNDE4NjAw" |
| 34 | "MzkxMDUwMIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAxUfhv54Jdgeq" |
| 35 | "0wmQ/ru9ew/ByCKcQawaZT9Xm9o/sMahwQ9IbNx2Dz4Jkelaxra7+DI0QP3pYctv" |
| 36 | "Ykn/jwq5y3cO0LJQB+kf/7FtSKG9qBEv8aqq5hDVteBUKiyUXqDmQzbe+mTcJ9Yd" |
| 37 | "D7siF1dhrjnM3KL1xpcXu3QaV5m/I6cKVwYrJxp3JKr6k5pHhxJlPIyUu7oU3kFW" |
| 38 | "7bHq2uq4ec9gBXCKwA64IVYVQm1GVDk+V0wr7pw9qD6QNa7eMzrCME6vfM0deSiU" |
| 39 | "a4TovUJDQFDsM287kYm3tZu7iuJzmOC63tl4YZdyqyOgnqSrUGE1soNHfLokI13H" |
| 40 | "hSwxok7nuQIBERY0GwEBHC8HLQgFZHVtbXkIA2tleQgDS0VZCBFrc2stMTQxODYw" |
| 41 | "MDM5MTA1MAgHSUQtQ0VSVBf9AQBLLJoQt9HE93NI3Mv1JCb3ezBCWMwTDnZA+XQV" |
| 42 | "UgVSvISJfU/lo2sne0SfGp4KsUhj206CDpuh3q0Th5gKSJeysy/bv66V2m2G8aDn" |
| 43 | "OkJ7Ut+2o/QnFpIMJz+oZf2f9Z0Pchocmkv8y4Fj02t8HCuFO1ekEvOcocZvWbKy" |
| 44 | "HX+P0OdefPzSC535/rsNHXTzgPsoV+yb13vrm4wPeqPPBs+scQYneIFKkRkGE5PU" |
| 45 | "pkncAMBN6iWgmSA2RcjcbmT6utCjJTqWviX1XPQtHoF/hBGC0D/TtQDgwVGGibXB" |
| 46 | "zb+klRHvCC/uUIfjU2HrE705kaw8btPhTP5/PMe8YKkk+hjh"; |
| 47 | |
| 48 | static const uint8_t DUMMY_SIGNATURE[] = |
| 49 | {0x17, 0xfd, 0x01, 0x00, 0x93, 0x15, 0x09, 0x49, 0x79, 0x9e, 0xb7, 0x9c, 0xd3, 0xc1, 0xbf, 0x61, |
| 50 | 0x89, 0xd5, 0xd9, 0xca, 0xf2, 0xb0, 0x14, 0xae, 0x72, 0x7c, 0x1f, 0x8f, 0xf5, 0xb1, 0x70, 0xd6, |
| 51 | 0x9b, 0x8f, 0xf8, 0xd7, 0x2d, 0xbc, 0x92, 0x6f, 0x7d, 0x77, 0x96, 0x46, 0xea, 0xd4, 0x7d, 0x90, |
| 52 | 0xbc, 0x7a, 0xeb, 0xe2, 0x03, 0x93, 0xb1, 0xd2, 0x62, 0xec, 0x9d, 0xff, 0x9c, 0x9c, 0x2a, 0x14, |
| 53 | 0x7d, 0x23, 0xca, 0x29, 0x3d, 0x15, 0x1a, 0x40, 0x42, 0x2c, 0x59, 0x33, 0x8a, 0xf7, 0xc0, 0x6b, |
| 54 | 0xc4, 0x9c, 0xf3, 0xc4, 0x99, 0xa4, 0x1a, 0x60, 0xf5, 0x28, 0x7d, 0x4c, 0xef, 0x43, 0x7d, 0xbd, |
| 55 | 0x7d, 0x00, 0x51, 0xee, 0x41, 0xf5, 0x25, 0x80, 0xce, 0xe6, 0x64, 0x4f, 0x75, 0x54, 0xf3, 0xb2, |
| 56 | 0x99, 0x9a, 0x0f, 0x93, 0x9a, 0x28, 0x1d, 0xfe, 0x12, 0x8a, 0xe0, 0xc1, 0x02, 0xeb, 0xa4, 0x35, |
| 57 | 0x52, 0x88, 0xac, 0x44, 0x1a, 0x44, 0x82, 0x97, 0x4f, 0x5f, 0xa8, 0xd8, 0x9f, 0x67, 0x38, 0xa8, |
| 58 | 0x64, 0xb6, 0x62, 0x99, 0xbd, 0x96, 0x3c, 0xf5, 0x86, 0x09, 0x5c, 0x97, 0x6b, 0x8f, 0xae, 0xe0, |
| 59 | 0x60, 0xe7, 0x23, 0x98, 0x6a, 0xee, 0xc1, 0xb0, 0x14, 0xbe, 0x46, 0x2c, 0xfb, 0xa7, 0x27, 0x73, |
| 60 | 0xe4, 0xf3, 0x26, 0x33, 0xba, 0x99, 0xd4, 0x01, 0x38, 0xa8, 0xf2, 0x9e, 0x87, 0xe0, 0x71, 0x0b, |
| 61 | 0x25, 0x44, 0x07, 0x35, 0x88, 0xab, 0x67, 0x27, 0x56, 0x0e, 0xb5, 0xb5, 0xe8, 0x27, 0xb4, 0x49, |
| 62 | 0xdc, 0xb8, 0x48, 0x31, 0xff, 0x99, 0x48, 0xab, 0x11, 0xb4, 0xa0, 0xdf, 0x8a, 0x6d, 0xff, 0x43, |
| 63 | 0x69, 0x32, 0xa7, 0xbc, 0x63, 0x9d, 0x0f, 0xe0, 0x95, 0x34, 0x36, 0x25, 0x4b, 0x3e, 0x36, 0xbd, |
| 64 | 0x81, 0x91, 0x0b, 0x91, 0x9f, 0x3a, 0x04, 0xa2, 0x44, 0x28, 0x19, 0xa1, 0x38, 0x21, 0x4f, 0x25, |
| 65 | 0x59, 0x8a, 0x48, 0xc2}; |
| 66 | |
| 67 | const std::string DummyPublicInfo::SCHEME = "pib-dummy"; |
| 68 | const std::string DummyTpm::SCHEME = "tpm-dummy"; |
| 69 | |
| 70 | NDN_CXX_KEYCHAIN_REGISTER_PIB(DummyPublicInfo, "pib-dummy", "dummy"); |
| 71 | NDN_CXX_KEYCHAIN_REGISTER_TPM(DummyTpm, "tpm-dummy", "dummy"); |
| 72 | |
| 73 | DummyPublicInfo::DummyPublicInfo(const std::string& locator) |
| 74 | : SecPublicInfo(locator) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | bool |
| 79 | DummyPublicInfo::doesIdentityExist(const Name& identityName) |
| 80 | { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | DummyPublicInfo::addIdentity(const Name& identityName) |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | bool |
| 90 | DummyPublicInfo::revokeIdentity() |
| 91 | { |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | bool |
| 96 | DummyPublicInfo::doesPublicKeyExist(const Name& keyName) |
| 97 | { |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | DummyPublicInfo::addKey(const Name& keyName, const PublicKey& publicKey) |
| 103 | { |
| 104 | } |
| 105 | |
| 106 | shared_ptr<PublicKey> |
| 107 | DummyPublicInfo::getPublicKey(const Name& keyName) |
| 108 | { |
| 109 | static shared_ptr<PublicKey> publicKey = nullptr; |
| 110 | if (publicKey == nullptr) { |
| 111 | typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream; |
| 112 | arrayStream |
| 113 | is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT)); |
| 114 | auto cert = io::load<IdentityCertificate>(is, io::NO_ENCODING); |
| 115 | publicKey = make_shared<PublicKey>(cert->getPublicKeyInfo()); |
| 116 | } |
| 117 | |
| 118 | return publicKey; |
| 119 | } |
| 120 | |
| 121 | KeyType |
| 122 | DummyPublicInfo::getPublicKeyType(const Name& keyName) |
| 123 | { |
| 124 | return KEY_TYPE_RSA; |
| 125 | } |
| 126 | |
| 127 | bool |
| 128 | DummyPublicInfo::doesCertificateExist(const Name& certificateName) |
| 129 | { |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | DummyPublicInfo::addCertificate(const IdentityCertificate& certificate) |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | shared_ptr<IdentityCertificate> |
| 139 | DummyPublicInfo::getCertificate(const Name& certificateName) |
| 140 | { |
| 141 | static shared_ptr<IdentityCertificate> cert = nullptr; |
| 142 | if (cert == nullptr) { |
| 143 | typedef boost::iostreams::stream<boost::iostreams::array_source> arrayStream; |
| 144 | arrayStream |
| 145 | is(reinterpret_cast<const char*>(DUMMY_CERT), sizeof(DUMMY_CERT)); |
| 146 | cert = io::load<IdentityCertificate>(is, io::BASE_64); |
| 147 | } |
| 148 | |
| 149 | return cert; |
| 150 | } |
| 151 | |
| 152 | Name |
| 153 | DummyPublicInfo::getDefaultIdentity() |
| 154 | { |
| 155 | return "/dummy/key"; |
| 156 | } |
| 157 | |
| 158 | Name |
| 159 | DummyPublicInfo::getDefaultKeyNameForIdentity(const Name& identityName) |
| 160 | { |
| 161 | return "/dummy/key/ksk-1418600391050"; |
| 162 | } |
| 163 | |
| 164 | Name |
| 165 | DummyPublicInfo::getDefaultCertificateNameForKey(const Name& keyName) |
| 166 | { |
| 167 | return "/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E"; |
| 168 | } |
| 169 | |
| 170 | void |
| 171 | DummyPublicInfo::getAllIdentities(std::vector<Name>& nameList, bool isDefault) |
| 172 | { |
| 173 | if (isDefault) { |
| 174 | nameList.push_back("/dummy"); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | DummyPublicInfo::getAllKeyNames(std::vector<Name>& nameList, bool isDefault) |
| 180 | { |
| 181 | if (isDefault) { |
| 182 | nameList.push_back("/dummy/key/ksk-1418600391050"); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void |
| 187 | DummyPublicInfo::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name>& nameList, |
| 188 | bool isDefault) |
| 189 | { |
| 190 | if (isDefault) { |
| 191 | nameList.push_back("/dummy/key/ksk-1418600391050"); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void |
| 196 | DummyPublicInfo::getAllCertificateNames(std::vector<Name>& nameList, bool isDefault) |
| 197 | { |
| 198 | if (isDefault) { |
| 199 | nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E"); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | void |
| 204 | DummyPublicInfo::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name>& nameList, |
| 205 | bool isDefault) |
| 206 | { |
| 207 | if (isDefault) { |
| 208 | nameList.push_back("/dummy/key/KEY/ksk-1418600391050/ID-CERT/%FD%00%00%01JK%2C%22%5E"); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | void |
| 213 | DummyPublicInfo::deleteCertificateInfo(const Name& certificateName) |
| 214 | { |
| 215 | } |
| 216 | |
| 217 | void |
| 218 | DummyPublicInfo::deletePublicKeyInfo(const Name& keyName) |
| 219 | { |
| 220 | } |
| 221 | |
| 222 | void |
| 223 | DummyPublicInfo::deleteIdentityInfo(const Name& identity) |
| 224 | { |
| 225 | } |
| 226 | |
| 227 | void |
| 228 | DummyPublicInfo::setDefaultIdentityInternal(const Name& identityName) |
| 229 | { |
| 230 | } |
| 231 | |
| 232 | void |
| 233 | DummyPublicInfo::setDefaultKeyNameForIdentityInternal(const Name& keyName) |
| 234 | { |
| 235 | } |
| 236 | |
| 237 | void |
| 238 | DummyPublicInfo::setDefaultCertificateNameForKeyInternal(const Name& certificateName) |
| 239 | { |
| 240 | } |
| 241 | |
| 242 | void |
| 243 | DummyPublicInfo::setTpmLocator(const std::string& tpmLocator) |
| 244 | { |
| 245 | m_tpmLocator = tpmLocator; |
| 246 | } |
| 247 | |
| 248 | std::string |
| 249 | DummyPublicInfo::getTpmLocator() |
| 250 | { |
| 251 | return m_tpmLocator; |
| 252 | } |
| 253 | |
| 254 | std::string |
| 255 | DummyPublicInfo::getScheme() |
| 256 | { |
| 257 | return DummyPublicInfo::SCHEME; |
| 258 | } |
| 259 | |
| 260 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 261 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 262 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 263 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 264 | |
| 265 | DummyTpm::DummyTpm(const std::string& locator) |
| 266 | : SecTpm(locator) |
| 267 | { |
| 268 | } |
| 269 | |
| 270 | void |
| 271 | DummyTpm::setTpmPassword(const uint8_t* password, size_t passwordLength) |
| 272 | { |
| 273 | } |
| 274 | |
| 275 | void |
| 276 | DummyTpm::resetTpmPassword() |
| 277 | { |
| 278 | } |
| 279 | |
| 280 | void |
| 281 | DummyTpm::setInTerminal(bool inTerminal) |
| 282 | { |
| 283 | } |
| 284 | |
| 285 | bool |
| 286 | DummyTpm::getInTerminal() const |
| 287 | { |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | bool |
| 292 | DummyTpm::isLocked() |
| 293 | { |
| 294 | return false; |
| 295 | } |
| 296 | |
| 297 | bool |
| 298 | DummyTpm::unlockTpm(const char* password, size_t passwordLength, bool usePassword) |
| 299 | { |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | void |
| 304 | DummyTpm::generateKeyPairInTpm(const Name& keyName, const KeyParams& params) |
| 305 | { |
| 306 | } |
| 307 | |
| 308 | void |
| 309 | DummyTpm::deleteKeyPairInTpm(const Name& keyName) |
| 310 | { |
| 311 | } |
| 312 | |
| 313 | shared_ptr<PublicKey> |
| 314 | DummyTpm::getPublicKeyFromTpm(const Name& keyName) |
| 315 | { |
| 316 | return nullptr; |
| 317 | } |
| 318 | |
| 319 | Block |
| 320 | DummyTpm::signInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, |
| 321 | DigestAlgorithm digestAlgorithm) |
| 322 | { |
| 323 | return Block(DUMMY_SIGNATURE, sizeof(DUMMY_SIGNATURE)); |
| 324 | } |
| 325 | |
| 326 | ConstBufferPtr |
| 327 | DummyTpm::decryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, |
| 328 | bool isSymmetric) |
| 329 | { |
| 330 | throw Error("Not supported"); |
| 331 | } |
| 332 | |
| 333 | ConstBufferPtr |
| 334 | DummyTpm::encryptInTpm(const uint8_t* data, size_t dataLength, const Name& keyName, |
| 335 | bool isSymmetric) |
| 336 | { |
| 337 | throw Error("Not supported"); |
| 338 | } |
| 339 | |
| 340 | void |
| 341 | DummyTpm::generateSymmetricKeyInTpm(const Name& keyName, const KeyParams& params) |
| 342 | { |
| 343 | } |
| 344 | |
| 345 | bool |
| 346 | DummyTpm::doesKeyExistInTpm(const Name& keyName, KeyClass keyClass) |
| 347 | { |
| 348 | return true; |
| 349 | } |
| 350 | |
| 351 | bool |
| 352 | DummyTpm::generateRandomBlock(uint8_t* res, size_t size) |
| 353 | { |
| 354 | return false; |
| 355 | } |
| 356 | |
| 357 | void |
| 358 | DummyTpm::addAppToAcl(const Name& keyName, KeyClass keyClass, const std::string& appPath, |
| 359 | AclType acl) |
| 360 | { |
| 361 | } |
| 362 | |
| 363 | ConstBufferPtr |
| 364 | DummyTpm::exportPrivateKeyPkcs8FromTpm(const Name& keyName) |
| 365 | { |
| 366 | throw Error("Not supported"); |
| 367 | } |
| 368 | |
| 369 | bool |
| 370 | DummyTpm::importPrivateKeyPkcs8IntoTpm(const Name& keyName, const uint8_t* buffer, |
| 371 | size_t bufferSize) |
| 372 | { |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | bool |
| 377 | DummyTpm::importPublicKeyPkcs1IntoTpm(const Name& keyName, const uint8_t* buffer, size_t bufferSize) |
| 378 | { |
| 379 | return false; |
| 380 | } |
| 381 | |
| 382 | std::string |
| 383 | DummyTpm::getScheme() |
| 384 | { |
| 385 | return DummyTpm::SCHEME; |
| 386 | } |
| 387 | |
| 388 | } // namespace security |
| 389 | } // namespace ndn |