Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2021 Regents of the University of California. |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 4 | * |
| 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 | |
| 26 | namespace ndn { |
| 27 | namespace security { |
| 28 | inline namespace v2 { |
| 29 | namespace tests { |
| 30 | |
| 31 | const time::milliseconds ValidatorFixtureBase::s_mockPeriod{250}; |
| 32 | const int ValidatorFixtureBase::s_mockTimes = 200; |
| 33 | |
| 34 | ValidatorFixtureBase::ValidatorFixtureBase() |
| 35 | { |
| 36 | processInterest = [this] (const Interest& interest) { |
| 37 | auto cert = cache.find(interest); |
| 38 | if (cert != nullptr) { |
| 39 | face.receive(*cert); |
| 40 | } |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | void |
| 45 | ValidatorFixtureBase::mockNetworkOperations() |
| 46 | { |
| 47 | util::signal::ScopedConnection conn = face.onSendInterest.connect([this] (const Interest& interest) { |
| 48 | if (processInterest) { |
Davide Pesavento | 2e481fc | 2021-07-02 18:20:03 -0400 | [diff] [blame^] | 49 | m_io.post([=] { processInterest(interest); }); |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 50 | } |
| 51 | }); |
| 52 | advanceClocks(s_mockPeriod, s_mockTimes); |
| 53 | } |
| 54 | |
| 55 | Identity |
| 56 | ValidatorFixtureBase::addSubCertificate(const Name& subIdentityName, const Identity& issuer) |
| 57 | { |
| 58 | auto subId = m_keyChain.createIdentity(subIdentityName); |
| 59 | auto cert = subId.getDefaultKey().getDefaultCertificate(); |
| 60 | cert.setName(cert.getKeyName() |
| 61 | .append("parent") |
| 62 | .appendVersion()); |
| 63 | |
| 64 | SignatureInfo info; |
| 65 | auto now = time::system_clock::now(); |
| 66 | info.setValidityPeriod(ValidityPeriod(now, now + 90_days)); |
| 67 | |
| 68 | AdditionalDescription description; |
| 69 | description.set("type", "sub-certificate"); |
| 70 | info.addCustomTlv(description.wireEncode()); |
| 71 | |
| 72 | m_keyChain.sign(cert, signingByIdentity(issuer).setSignatureInfo(info)); |
| 73 | m_keyChain.setDefaultCertificate(subId.getDefaultKey(), cert); |
| 74 | |
| 75 | return subId; |
| 76 | } |
| 77 | |
| 78 | Name |
| 79 | InterestV02Pkt::makeName(Name name, KeyChain& keyChain) |
| 80 | { |
| 81 | Interest interest(name); |
| 82 | interest.setCanBePrefix(false); |
| 83 | SigningInfo params; |
| 84 | params.setSignedInterestFormat(SignedInterestFormat::V02); |
| 85 | keyChain.sign(interest, params); |
| 86 | return interest.getName(); |
| 87 | } |
| 88 | |
| 89 | Name |
| 90 | InterestV03Pkt::makeName(Name name, KeyChain& keyChain) |
| 91 | { |
| 92 | Interest interest(name); |
| 93 | interest.setCanBePrefix(false); |
| 94 | SigningInfo params; |
| 95 | params.setSignedInterestFormat(SignedInterestFormat::V03); |
| 96 | keyChain.sign(interest, params); |
| 97 | return interest.getName(); |
| 98 | } |
| 99 | |
| 100 | } // namespace tests |
| 101 | } // inline namespace v2 |
| 102 | } // namespace security |
| 103 | } // namespace ndn |