Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
| 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file, originally written as part of NFD (Named Data Networking Forwarding Daemon), |
| 12 | * is a part of ndncert, a certificate management system based on NDN. |
| 13 | * |
| 14 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 15 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 16 | * version 3 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY |
| 19 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 20 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received copies of the GNU General Public License along with |
| 23 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 26 | */ |
| 27 | |
| 28 | #ifndef NDNCERT_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 29 | #define NDNCERT_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 30 | |
| 31 | #include "test-common.hpp" |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 32 | #include <ndn-cxx/security/v2/key-chain.hpp> |
| 33 | #include <ndn-cxx/security/v2/additional-description.hpp> |
| 34 | #include <ndn-cxx/security/signing-helpers.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 35 | |
| 36 | namespace ndn { |
| 37 | namespace ndncert { |
| 38 | namespace tests { |
| 39 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 40 | /** |
| 41 | * @brief A test suite level fixture to help with identity management |
| 42 | * |
| 43 | * Test cases in the suite can use this fixture to create identities. Identities, |
| 44 | * certificates, and saved certificates are automatically removed during test teardown. |
| 45 | */ |
| 46 | class IdentityManagementV2Fixture |
| 47 | { |
| 48 | public: |
| 49 | IdentityManagementV2Fixture(); |
| 50 | |
| 51 | /** |
| 52 | * @brief Add identity @p identityName |
| 53 | * @return name of the created self-signed certificate |
| 54 | */ |
| 55 | security::Identity |
| 56 | addIdentity(const Name& identityName, const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams()); |
| 57 | |
| 58 | /** |
| 59 | * @brief Save identity certificate to a file |
| 60 | * @param identity identity |
| 61 | * @param filename file name, should be writable |
| 62 | * @return whether successful |
| 63 | */ |
| 64 | bool |
| 65 | saveIdentityCertificate(const security::Identity& identity, const std::string& filename); |
| 66 | |
| 67 | /** |
| 68 | * @brief Issue a certificate for \p subIdentityName signed by \p issuer |
| 69 | * |
| 70 | * If identity does not exist, it is created. |
| 71 | * A new key is generated as the default key for identity. |
| 72 | * A default certificate for the key is signed by the issuer using its default certificate. |
| 73 | * |
| 74 | * @return the sub identity |
| 75 | */ |
| 76 | security::Identity |
| 77 | addSubCertificate(const Name& subIdentityName, const security::Identity& issuer, |
| 78 | const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams()); |
| 79 | |
| 80 | /** |
| 81 | * @brief Add a self-signed certificate to @p key with issuer ID @p issuer |
| 82 | */ |
| 83 | security::v2::Certificate |
| 84 | addCertificate(const security::Key& key, const std::string& issuer); |
| 85 | |
| 86 | bool |
| 87 | saveCertToFile(const Data& obj, const std::string& filename); |
| 88 | |
| 89 | protected: |
| 90 | std::set<Name> m_identities; |
| 91 | std::set<std::string> m_certFiles; |
| 92 | security::v2::KeyChain m_keyChain; |
| 93 | }; |
| 94 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 95 | /** \brief convenience base class for inheriting from both UnitTestTimeFixture |
Zhiyi Zhang | 3b76f2c | 2017-03-01 10:20:15 -0800 | [diff] [blame] | 96 | * and IdentityManagementV2Fixture |
| 97 | */ |
| 98 | class IdentityManagementV2TimeFixture : public UnitTestTimeFixture |
| 99 | , public IdentityManagementV2Fixture |
| 100 | { |
| 101 | }; |
| 102 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 103 | } // namespace tests |
| 104 | } // namespace ndncert |
| 105 | } // namespace ndn |
| 106 | |
| 107 | #endif // NDNCERT_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |