blob: ba42ca30826fcd1d2ad563c9a85b3166b6fa5515 [file] [log] [blame]
Yingdi Yud9715e32014-06-27 08:48:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -08002/*
Davide Pesavento7e780642018-11-24 15:51:34 -05003 * Copyright (c) 2013-2018 Regents of the University of California.
Yingdi Yud9715e32014-06-27 08:48:47 -07004 *
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 Yu41546342014-11-30 23:37:53 -080022#ifndef NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
23#define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
24
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "ndn-cxx/security/v2/key-chain.hpp"
26#include "ndn-cxx/security/signing-helpers.hpp"
Yingdi Yud9715e32014-06-27 08:48:47 -070027
Davide Pesavento7e780642018-11-24 15:51:34 -050028#include "tests/test-home-fixture.hpp"
Yingdi Yud9715e32014-06-27 08:48:47 -070029
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -080030#include <vector>
31
Yingdi Yud9715e32014-06-27 08:48:47 -070032namespace ndn {
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070033namespace tests {
Yingdi Yud9715e32014-06-27 08:48:47 -070034
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080035class IdentityManagementBaseFixture : public TestHomeFixture<DefaultPibDir>
Yingdi Yud9715e32014-06-27 08:48:47 -070036{
37public:
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080038 ~IdentityManagementBaseFixture();
Yingdi Yud9715e32014-06-27 08:48:47 -070039
Yingdi Yud9715e32014-06-27 08:48:47 -070040 bool
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080041 saveCertToFile(const Data& obj, const std::string& filename);
42
43protected:
44 std::set<Name> m_identities;
45 std::set<std::string> m_certFiles;
46};
47
48/**
49 * @brief A test suite level fixture to help with identity management
50 *
51 * Test cases in the suite can use this fixture to create identities. Identities,
52 * certificates, and saved certificates are automatically removed during test teardown.
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080053 */
Alexander Afanasyevadc71842017-01-26 22:17:58 -050054class IdentityManagementFixture : public IdentityManagementBaseFixture
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080055{
56public:
Alexander Afanasyevadc71842017-01-26 22:17:58 -050057 IdentityManagementFixture();
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080058
59 /**
60 * @brief Add identity @p identityName
61 * @return name of the created self-signed certificate
62 */
63 security::Identity
Davide Pesavento7e780642018-11-24 15:51:34 -050064 addIdentity(const Name& identityName,
65 const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams());
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080066
67 /**
68 * @brief Save identity certificate to a file
69 * @param identity identity
70 * @param filename file name, should be writable
71 * @return whether successful
72 */
73 bool
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -080074 saveCertificate(const security::Identity& identity, const std::string& filename);
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080075
76 /**
77 * @brief Issue a certificate for \p subIdentityName signed by \p issuer
78 *
79 * If identity does not exist, it is created.
80 * A new key is generated as the default key for identity.
81 * A default certificate for the key is signed by the issuer using its default certificate.
82 *
83 * @return the sub identity
84 */
85 security::Identity
86 addSubCertificate(const Name& subIdentityName, const security::Identity& issuer,
87 const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams());
88
Qiuhan Ding4caa0cc2015-10-23 20:31:27 -070089 /**
90 * @brief Add a self-signed certificate to @p key with issuer ID @p issuer
91 */
92 security::v2::Certificate
93 addCertificate(const security::Key& key, const std::string& issuer);
94
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080095protected:
Alexander Afanasyevadc71842017-01-26 22:17:58 -050096 KeyChain m_keyChain;
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080097};
98
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070099} // namespace tests
Yingdi Yud9715e32014-06-27 08:48:47 -0700100} // namespace ndn
Yingdi Yu41546342014-11-30 23:37:53 -0800101
102#endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP