blob: 53b68f5fe66d44760fd7b8021dedbe5ebf503ba2 [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/*
Zhiyi Zhang1e164cc2017-01-03 11:04:35 -08003 * Copyright (c) 2013-2017 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
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080025#include "security/v2/key-chain.hpp"
Zhiyi Zhang1e164cc2017-01-03 11:04:35 -080026#include "security/signing-helpers.hpp"
Yingdi Yud9715e32014-06-27 08:48:47 -070027
28#include "boost-test.hpp"
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080029#include "test-home-fixture.hpp"
Yingdi Yud9715e32014-06-27 08:48:47 -070030
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -080031#include <vector>
32
Yingdi Yud9715e32014-06-27 08:48:47 -070033namespace ndn {
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070034namespace tests {
Yingdi Yud9715e32014-06-27 08:48:47 -070035
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080036class IdentityManagementBaseFixture : public TestHomeFixture<DefaultPibDir>
Yingdi Yud9715e32014-06-27 08:48:47 -070037{
38public:
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080039 ~IdentityManagementBaseFixture();
Yingdi Yud9715e32014-06-27 08:48:47 -070040
Yingdi Yud9715e32014-06-27 08:48:47 -070041 bool
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080042 saveCertToFile(const Data& obj, const std::string& filename);
43
44protected:
45 std::set<Name> m_identities;
46 std::set<std::string> m_certFiles;
47};
48
49/**
50 * @brief A test suite level fixture to help with identity management
51 *
52 * Test cases in the suite can use this fixture to create identities. Identities,
53 * certificates, and saved certificates are automatically removed during test teardown.
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080054 */
Alexander Afanasyevadc71842017-01-26 22:17:58 -050055class IdentityManagementFixture : public IdentityManagementBaseFixture
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080056{
57public:
Alexander Afanasyevadc71842017-01-26 22:17:58 -050058 IdentityManagementFixture();
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080059
60 /**
61 * @brief Add identity @p identityName
62 * @return name of the created self-signed certificate
63 */
64 security::Identity
65 addIdentity(const Name& identityName, const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams());
66
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