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