blob: acd75d02756eb4e14fb0f776934f58ecfce13e80 [file] [log] [blame]
Muktadir Chowdhuryf04f9892017-08-20 20:42:56 -05001/* -*- 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 is part of NLSR (Named-data Link State Routing).
12 * See AUTHORS.md for complete list of NLSR authors and contributors.
13 *
14 * NLSR 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,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NLSR_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
27#define NLSR_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
28
29#include "boost-test.hpp"
30#include "test-home-fixture.hpp"
31
32#include <vector>
33
34#include <ndn-cxx/security/v2/key-chain.hpp>
35#include <ndn-cxx/security/signing-helpers.hpp>
36
37namespace nlsr {
38namespace tests {
39
40class IdentityManagementBaseFixture : public TestHomeFixture<DefaultPibDir>
41{
42public:
43 ~IdentityManagementBaseFixture();
44
45 bool
46 saveCertToFile(const ndn::Data& obj, const std::string& filename);
47
48protected:
49 std::set<ndn::Name> m_identities;
50 std::set<std::string> m_certFiles;
51};
52
53/**
54 * @brief A test suite level fixture to help with identity management
55 *
56 * Test cases in the suite can use this fixture to create identities. Identities,
57 * certificates, and saved certificates are automatically removed during test teardown.
58 */
59class IdentityManagementFixture : public IdentityManagementBaseFixture
60{
61public:
62 IdentityManagementFixture();
63
64 /**
65 * @brief Add identity @p identityName
66 * @return name of the created self-signed certificate
67 */
68 ndn::security::Identity
69 addIdentity(const ndn::Name& identityName, const ndn::KeyParams& params = ndn::KeyChain::getDefaultKeyParams());
70
71 /**
72 * @brief Save identity certificate to a file
73 * @param identity identity
74 * @param filename file name, should be writable
75 * @return whether successful
76 */
77 bool
78 saveCertificate(const ndn::security::Identity& identity, const std::string& filename);
79
80 /**
81 * @brief Issue a certificate for \p subidentityName signed by \p issuer
82 *
83 * If identity does not exist, it is created.
84 * A new key is generated as the default key for identity.
85 * A default certificate for the key is signed by the issuer using its default certificate.
86 *
87 * @return the sub identity
88 */
89 ndn::security::Identity
90 addSubCertificate(const ndn::Name& identityName, const ndn::security::Identity& issuer,
91 const ndn::KeyParams& params = ndn::KeyChain::getDefaultKeyParams());
92
93 /**
94 * @brief Add a self-signed certificate to @p key with issuer ID @p issuer
95 */
96 ndn::security::v2::Certificate
97 addCertificate(const ndn::security::Key& key, const std::string& issuer);
98
99protected:
100 ndn::KeyChain m_keyChain;
101};
102
103} // namespace tests
104} // namespace nlsr
105
106#endif // NLSR_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP