blob: d76e3facd6854a75a45d8e2128f825ca17795836 [file] [log] [blame]
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev5181d892020-06-06 18:05:47 -04003 * Copyright (c) 2014-2020, Regents of the University of California
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -04004 *
5 * NAC library is free software: you can redistribute it and/or modify it under the
6 * terms of the GNU Lesser General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later version.
8 *
9 * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12 *
13 * You should have received copies of the GNU General Public License and GNU Lesser
14 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * See AUTHORS.md for complete list of NAC library authors and contributors.
18 */
19
20#ifndef NAC_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
21#define NAC_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
22
Alexander Afanasyev5181d892020-06-06 18:05:47 -040023#include "common.hpp"
24
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040025#include "boost-test.hpp"
26
Alexander Afanasyev5181d892020-06-06 18:05:47 -040027#include <ndn-cxx/security/key-chain.hpp>
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040028#include <ndn-cxx/security/signing-helpers.hpp>
29
30#include <vector>
31
32namespace ndn {
33namespace nac {
34namespace tests {
35
36/**
37 * @brief A test suite level fixture to help with identity management
38 *
39 * Test cases in the suite can use this fixture to create identities. Identities,
40 * certificates, and saved certificates are automatically removed during test teardown.
41 */
42class IdentityManagementFixture
43{
44public:
45 IdentityManagementFixture();
46
47 ~IdentityManagementFixture();
48
49 /**
50 * @brief Add identity @p identityName
51 * @return name of the created self-signed certificate
52 */
Alexander Afanasyev5181d892020-06-06 18:05:47 -040053 Identity
54 addIdentity(const Name& identityName, const KeyParams& params = KeyChain::getDefaultKeyParams());
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040055
56 /**
57 * @brief Save identity certificate to a file
58 * @param identity identity
59 * @param filename file name, should be writable
60 * @return whether successful
61 */
62 bool
Alexander Afanasyev5181d892020-06-06 18:05:47 -040063 saveIdentityCertificate(const Identity& identity, const std::string& filename);
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040064
65 /**
66 * @brief Issue a certificate for \p subIdentityName signed by \p issuer
67 *
68 * If identity does not exist, it is created.
69 * A new key is generated as the default key for identity.
70 * A default certificate for the key is signed by the issuer using its default certificate.
71 *
72 * @return the sub identity
73 */
74 security::Identity
Alexander Afanasyev5181d892020-06-06 18:05:47 -040075 addSubCertificate(const Name& subIdentityName, const Identity& issuer,
76 const KeyParams& params = KeyChain::getDefaultKeyParams());
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040077
78 /**
79 * @brief Add a self-signed certificate to @p key with issuer ID @p issuer
80 */
Alexander Afanasyev5181d892020-06-06 18:05:47 -040081 Certificate
82 addCertificate(const Key& key, const std::string& issuer);
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040083
84 bool
85 saveCertToFile(const Data& obj, const std::string& filename);
86
87protected:
Alexander Afanasyev5181d892020-06-06 18:05:47 -040088 KeyChain m_keyChain;
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040089 std::set<Name> m_identities;
90 std::set<std::string> m_certFiles;
91};
92
93} // namespace tests
94} // namespace nac
95} // namespace ndn
96
97#endif // NAC_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP