Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013-2019 Regents of the University of California. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 4 | * |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 6 | * |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [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. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 10 | * |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 14 | * |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 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/>. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 18 | * |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 22 | #ifndef NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 23 | #define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 24 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 25 | #include "test-home-fixture.hpp" |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 26 | #include "unit-test-time-fixture.hpp" |
| 27 | #include "boost-test.hpp" |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 28 | #include <ndn-cxx/security/v2/key-chain.hpp> |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 29 | #include <ndn-cxx/security/signing-helpers.hpp> |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 30 | #include <vector> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 31 | |
| 32 | namespace ndn { |
| 33 | namespace ndncert { |
| 34 | namespace tests { |
| 35 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 36 | class IdentityManagementBaseFixture : public TestHomeFixture<DefaultPibDir> |
| 37 | { |
| 38 | public: |
| 39 | ~IdentityManagementBaseFixture(); |
| 40 | |
| 41 | bool |
| 42 | saveCertToFile(const Data& obj, const std::string& filename); |
| 43 | |
| 44 | protected: |
| 45 | std::set<Name> m_identities; |
| 46 | std::set<std::string> m_certFiles; |
| 47 | }; |
| 48 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 49 | /** |
| 50 | * @brief A test suite level fixture to help with identity management |
| 51 | * |
| 52 | * Test cases in the suite can use this fixture to create identities. Identities, |
| 53 | * certificates, and saved certificates are automatically removed during test teardown. |
| 54 | */ |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 55 | class IdentityManagementFixture : public IdentityManagementBaseFixture |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 56 | { |
| 57 | public: |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 58 | IdentityManagementFixture(); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * @brief Add identity @p identityName |
| 62 | * @return name of the created self-signed certificate |
| 63 | */ |
| 64 | security::Identity |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 65 | addIdentity(const Name& identityName, |
| 66 | const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams()); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * @brief Save identity certificate to a file |
| 70 | * @param identity identity |
| 71 | * @param filename file name, should be writable |
| 72 | * @return whether successful |
| 73 | */ |
| 74 | bool |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 75 | saveCertificate(const security::Identity& identity, const std::string& filename); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * @brief Issue a certificate for \p subIdentityName signed by \p issuer |
| 79 | * |
| 80 | * If identity does not exist, it is created. |
| 81 | * A new key is generated as the default key for identity. |
| 82 | * A default certificate for the key is signed by the issuer using its default certificate. |
| 83 | * |
| 84 | * @return the sub identity |
| 85 | */ |
| 86 | security::Identity |
| 87 | addSubCertificate(const Name& subIdentityName, const security::Identity& issuer, |
| 88 | const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams()); |
| 89 | |
| 90 | /** |
| 91 | * @brief Add a self-signed certificate to @p key with issuer ID @p issuer |
| 92 | */ |
| 93 | security::v2::Certificate |
| 94 | addCertificate(const security::Key& key, const std::string& issuer); |
| 95 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 96 | protected: |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 97 | KeyChain m_keyChain; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 100 | class IdentityManagementTimeFixture : public UnitTestTimeFixture |
| 101 | , public IdentityManagementFixture |
Zhiyi Zhang | 3b76f2c | 2017-03-01 10:20:15 -0800 | [diff] [blame] | 102 | { |
| 103 | }; |
| 104 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 105 | } // namespace tests |
| 106 | } // namespace ndncert |
| 107 | } // namespace ndn |
| 108 | |
Zhiyi Zhang | 42d992d | 2019-07-07 16:46:50 -0700 | [diff] [blame] | 109 | #endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |