Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 1e164cc | 2017-01-03 11:04:35 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 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 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 22 | #ifndef NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 23 | #define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |
| 24 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 25 | #include "security/v1/key-chain.hpp" |
Zhiyi Zhang | 1e164cc | 2017-01-03 11:04:35 -0800 | [diff] [blame] | 26 | #include "security/signing-helpers.hpp" |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
| 29 | #include "boost-test.hpp" |
| 30 | |
| 31 | namespace ndn { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 32 | namespace tests { |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * @brief IdentityManagementFixture is a test suite level fixture. |
| 36 | * Test cases in the suite can use this fixture to create identities. |
| 37 | * Identities added via addIdentity method are automatically deleted |
| 38 | * during test teardown. |
| 39 | */ |
| 40 | class IdentityManagementFixture |
| 41 | { |
| 42 | public: |
| 43 | IdentityManagementFixture(); |
| 44 | |
| 45 | ~IdentityManagementFixture(); |
| 46 | |
| 47 | /// @brief add identity, return true if succeed. |
| 48 | bool |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 49 | addIdentity(const Name& identity, const KeyParams& params = security::v1::KeyChain::DEFAULT_KEY_PARAMS); |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 50 | |
Zhiyi Zhang | 0a939b4 | 2016-11-16 14:27:20 -0800 | [diff] [blame] | 51 | /** |
| 52 | * @brief save identity certificate to a file |
| 53 | * @param identity identity name |
| 54 | * @param filename file name, should be writable |
| 55 | * @param wantAdd if true, add new identity when necessary |
| 56 | * @return whether successful |
| 57 | */ |
| 58 | bool |
| 59 | saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false); |
| 60 | |
Zhiyi Zhang | 1e164cc | 2017-01-03 11:04:35 -0800 | [diff] [blame] | 61 | /** \brief issue a certificate for \p identity signed by \p issuer |
| 62 | * |
| 63 | * If identity does not exist, it is created. |
| 64 | * A new key is generated as the default key for identity. |
| 65 | * A default certificate for the key is signed by the issuer using its default certificate. |
| 66 | * |
| 67 | * \return whether success |
| 68 | */ |
| 69 | bool |
| 70 | addSubCertificate(const Name& identity, const Name& issuer, |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 71 | const KeyParams& params = security::v1::KeyChain::DEFAULT_KEY_PARAMS); |
Zhiyi Zhang | 1e164cc | 2017-01-03 11:04:35 -0800 | [diff] [blame] | 72 | |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 73 | protected: |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame^] | 74 | security::v1::KeyChain m_keyChain; |
Zhiyi Zhang | 0a939b4 | 2016-11-16 14:27:20 -0800 | [diff] [blame] | 75 | |
| 76 | private: |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 77 | std::vector<Name> m_identities; |
Zhiyi Zhang | 0a939b4 | 2016-11-16 14:27:20 -0800 | [diff] [blame] | 78 | std::vector<std::string> m_certFiles; |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 81 | } // namespace tests |
Yingdi Yu | d9715e3 | 2014-06-27 08:48:47 -0700 | [diff] [blame] | 82 | } // namespace ndn |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 83 | |
| 84 | #endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP |