blob: 0e780b4924df2b29df637cc37454c0214b0d462f [file] [log] [blame]
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento05ec0be2023-03-14 21:18:06 -04003 * Copyright (c) 2013-2023 Regents of the University of California.
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -05004 *
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
22#include "tests/unit/security/validator-fixture.hpp"
23
24#include "ndn-cxx/security/additional-description.hpp"
25
26namespace ndn {
27namespace security {
28inline namespace v2 {
29namespace tests {
30
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050031ValidatorFixtureBase::ValidatorFixtureBase()
32{
33 processInterest = [this] (const Interest& interest) {
34 auto cert = cache.find(interest);
35 if (cert != nullptr) {
Junxiao Shi7d728682022-04-01 01:21:13 +000036 BOOST_TEST_MESSAGE("ValidatorFixture processInterest " << interest << " reply " << cert->getName());
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050037 face.receive(*cert);
38 }
Junxiao Shi7d728682022-04-01 01:21:13 +000039 else {
40 BOOST_TEST_MESSAGE("ValidatorFixture processInterest " << interest << " no reply");
41 }
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050042 };
43}
44
45void
46ValidatorFixtureBase::mockNetworkOperations()
47{
48 util::signal::ScopedConnection conn = face.onSendInterest.connect([this] (const Interest& interest) {
49 if (processInterest) {
Davide Pesavento2e481fc2021-07-02 18:20:03 -040050 m_io.post([=] { processInterest(interest); });
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050051 }
52 });
53 advanceClocks(s_mockPeriod, s_mockTimes);
54}
55
Davide Pesavento2acce252022-09-08 22:03:03 -040056void
57ValidatorFixtureBase::rewindClockAfterValidation()
58{
59 m_systemClock->advance(s_mockPeriod * s_mockTimes * -1);
60}
61
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050062Identity
63ValidatorFixtureBase::addSubCertificate(const Name& subIdentityName, const Identity& issuer)
64{
65 auto subId = m_keyChain.createIdentity(subIdentityName);
66 auto cert = subId.getDefaultKey().getDefaultCertificate();
67 cert.setName(cert.getKeyName()
68 .append("parent")
69 .appendVersion());
70
71 SignatureInfo info;
72 auto now = time::system_clock::now();
73 info.setValidityPeriod(ValidityPeriod(now, now + 90_days));
74
75 AdditionalDescription description;
76 description.set("type", "sub-certificate");
77 info.addCustomTlv(description.wireEncode());
78
79 m_keyChain.sign(cert, signingByIdentity(issuer).setSignatureInfo(info));
80 m_keyChain.setDefaultCertificate(subId.getDefaultKey(), cert);
81
82 return subId;
83}
84
85Name
86InterestV02Pkt::makeName(Name name, KeyChain& keyChain)
87{
88 Interest interest(name);
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050089 SigningInfo params;
90 params.setSignedInterestFormat(SignedInterestFormat::V02);
91 keyChain.sign(interest, params);
92 return interest.getName();
93}
94
95Name
96InterestV03Pkt::makeName(Name name, KeyChain& keyChain)
97{
98 Interest interest(name);
Davide Pesavento4c1ad4c2020-11-16 21:12:02 -050099 SigningInfo params;
100 params.setSignedInterestFormat(SignedInterestFormat::V03);
101 keyChain.sign(interest, params);
102 return interest.getName();
103}
104
105} // namespace tests
106} // inline namespace v2
107} // namespace security
108} // namespace ndn