Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 2bea5c4 | 2017-08-14 20:10:32 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [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 | |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 22 | #include "ndn-cxx/security/validation-policy-command-interest.hpp" |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 23 | |
Davide Pesavento | 77c5ce8 | 2021-05-07 16:12:02 -0400 | [diff] [blame] | 24 | #include "ndn-cxx/security/interest-signer.hpp" |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 25 | #include "ndn-cxx/security/validation-policy-accept-all.hpp" |
| 26 | #include "ndn-cxx/security/validation-policy-simple-hierarchy.hpp" |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 27 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 28 | #include "tests/test-common.hpp" |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 29 | #include "tests/unit/security/validator-fixture.hpp" |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 30 | |
Davide Pesavento | 49e1e87 | 2023-11-11 00:45:23 -0500 | [diff] [blame^] | 31 | #include <boost/mp11/list.hpp> |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 32 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 33 | namespace ndn::tests { |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 34 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 35 | using namespace ndn::security; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 36 | |
| 37 | BOOST_AUTO_TEST_SUITE(Security) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 38 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 39 | struct CommandInterestDefaultOptions |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 40 | { |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 41 | static ValidationPolicyCommandInterest::Options |
| 42 | getOptions() |
| 43 | { |
| 44 | return {}; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | template<class T, class InnerPolicy> |
| 49 | class CommandInterestPolicyWrapper : public ValidationPolicyCommandInterest |
| 50 | { |
| 51 | public: |
| 52 | CommandInterestPolicyWrapper() |
| 53 | : ValidationPolicyCommandInterest(make_unique<InnerPolicy>(), T::getOptions()) |
| 54 | { |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | template<class T, class InnerPolicy = ValidationPolicySimpleHierarchy> |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 59 | class ValidationPolicyCommandInterestFixture |
| 60 | : public HierarchicalValidatorFixture<CommandInterestPolicyWrapper<T, InnerPolicy>> |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 61 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 62 | protected: |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 63 | Interest |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 64 | makeCommandInterest(const Identity& id, SignedInterestFormat format = SignedInterestFormat::V02) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 65 | { |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 66 | Name name = id.getName(); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 67 | name.append("CMD"); |
| 68 | switch (format) { |
| 69 | case SignedInterestFormat::V02: |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 70 | return m_signer.makeCommandInterest(name, signingByIdentity(id)); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 71 | case SignedInterestFormat::V03: { |
| 72 | Interest interest(name); |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 73 | m_signer.makeSignedInterest(interest, signingByIdentity(id)); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 74 | return interest; |
| 75 | } |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 76 | } |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 77 | NDN_CXX_UNREACHABLE; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 80 | protected: |
Davide Pesavento | 77c5ce8 | 2021-05-07 16:12:02 -0400 | [diff] [blame] | 81 | InterestSigner m_signer{this->m_keyChain}; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
Eric Newberry | 1caa634 | 2020-08-23 19:29:08 -0700 | [diff] [blame] | 84 | BOOST_FIXTURE_TEST_SUITE(TestValidationPolicyCommandInterest, |
| 85 | ValidationPolicyCommandInterestFixture<CommandInterestDefaultOptions>) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 86 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 87 | template<int secs> |
| 88 | struct GracePeriodSeconds |
| 89 | { |
| 90 | static ValidationPolicyCommandInterest::Options |
| 91 | getOptions() |
| 92 | { |
| 93 | ValidationPolicyCommandInterest::Options options; |
| 94 | options.gracePeriod = time::seconds(secs); |
| 95 | return options; |
| 96 | } |
| 97 | }; |
| 98 | |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 99 | BOOST_AUTO_TEST_SUITE(Accepts) |
| 100 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 101 | BOOST_AUTO_TEST_CASE(BasicV02) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 102 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 103 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V02); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 104 | VALIDATE_SUCCESS(i1, "Should succeed (within grace period)"); |
Alexander Afanasyev | 31fd467 | 2018-06-17 13:25:52 -0400 | [diff] [blame] | 105 | VALIDATE_FAILURE(i1, "Should fail (replay attack)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 106 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 107 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 108 | advanceClocks(5_ms); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 109 | auto i2 = makeCommandInterest(identity, SignedInterestFormat::V02); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 110 | VALIDATE_SUCCESS(i2, "Should succeed (timestamp larger than previous)"); |
Alexander Afanasyev | 31fd467 | 2018-06-17 13:25:52 -0400 | [diff] [blame] | 111 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 112 | auto i3 = m_signer.makeCommandInterest(Name(identity.getName()).append("CMD"), signingWithSha256()); |
Alexander Afanasyev | 31fd467 | 2018-06-17 13:25:52 -0400 | [diff] [blame] | 113 | VALIDATE_FAILURE(i3, "Should fail (Sha256 signature violates policy)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 114 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 117 | BOOST_AUTO_TEST_CASE(BasicV03) |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 118 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 119 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V03); |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 120 | VALIDATE_SUCCESS(i1, "Should succeed (within grace period)"); |
| 121 | VALIDATE_FAILURE(i1, "Should fail (replay attack)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 122 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 123 | |
| 124 | advanceClocks(5_ms); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 125 | auto i2 = makeCommandInterest(identity, SignedInterestFormat::V03); |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 126 | VALIDATE_SUCCESS(i2, "Should succeed (timestamp larger than previous)"); |
| 127 | |
| 128 | Interest i3(Name(identity.getName()).append("CMD")); |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 129 | m_signer.makeSignedInterest(i3, signingWithSha256()); |
| 130 | VALIDATE_FAILURE(i3, "Should fail (Sha256 signature violates policy)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 131 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Eric Newberry | 17d7c47 | 2020-06-18 21:29:22 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 134 | BOOST_AUTO_TEST_CASE(DataPassthrough) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 135 | { |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 136 | Data d1("/Security/ValidatorFixture/Sub1"); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 137 | m_keyChain.sign(d1); |
| 138 | VALIDATE_SUCCESS(d1, "Should succeed (fallback on inner validation policy for data)"); |
| 139 | } |
| 140 | |
Eric Newberry | 1caa634 | 2020-08-23 19:29:08 -0700 | [diff] [blame] | 141 | using ValidationPolicyAcceptAllCommands = ValidationPolicyCommandInterestFixture<CommandInterestDefaultOptions, |
Alexander Afanasyev | 31fd467 | 2018-06-17 13:25:52 -0400 | [diff] [blame] | 142 | ValidationPolicyAcceptAll>; |
| 143 | |
| 144 | BOOST_FIXTURE_TEST_CASE(SignedWithSha256, ValidationPolicyAcceptAllCommands) // Bug 4635 |
| 145 | { |
| 146 | auto i1 = m_signer.makeCommandInterest("/hello/world/CMD", signingWithSha256()); |
| 147 | VALIDATE_SUCCESS(i1, "Should succeed (within grace period)"); |
| 148 | VALIDATE_FAILURE(i1, "Should fail (replay attack)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 149 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 31fd467 | 2018-06-17 13:25:52 -0400 | [diff] [blame] | 150 | |
| 151 | advanceClocks(5_ms); |
| 152 | auto i2 = m_signer.makeCommandInterest("/hello/world/CMD", signingWithSha256()); |
| 153 | VALIDATE_SUCCESS(i2, "Should succeed (timestamp larger than previous)"); |
| 154 | } |
| 155 | |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 156 | BOOST_AUTO_TEST_SUITE_END() // Accepts |
| 157 | |
| 158 | BOOST_AUTO_TEST_SUITE(Rejects) |
| 159 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 160 | BOOST_AUTO_TEST_CASE(NotSigned) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 161 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 162 | auto i1 = Interest("/short"); |
| 163 | BOOST_TEST_REQUIRE(i1.getName().size() < signed_interest::MIN_SIZE); |
| 164 | VALIDATE_FAILURE(i1, "Should fail (not signed / name too short)"); |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 165 | BOOST_TEST(lastError.getCode() == ValidationError::MALFORMED_SIGNATURE); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_CASE(BadSigInfo) |
| 169 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 170 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V02); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 171 | setNameComponent(i1, command_interest::POS_SIG_INFO, "not-SignatureInfo"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 172 | BOOST_TEST_REQUIRE(i1.getName().size() >= command_interest::MIN_SIZE); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 173 | VALIDATE_FAILURE(i1, "Should fail (signature info is missing)"); |
Davide Pesavento | 637ea3b | 2022-09-10 00:11:34 -0400 | [diff] [blame] | 174 | BOOST_TEST(lastError.getCode() == ValidationError::MALFORMED_SIGNATURE); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 175 | } |
| 176 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 177 | BOOST_AUTO_TEST_CASE(BadTimestampV02) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 178 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 179 | // i1 is a valid signed interest (in v0.2 format) but is not a valid command interest |
| 180 | auto i1 = Interest("/short"); |
| 181 | m_keyChain.sign(i1, signingByIdentity(identity).setSignedInterestFormat(SignedInterestFormat::V02)); |
| 182 | BOOST_TEST_REQUIRE((i1.getName().size() >= signed_interest::MIN_SIZE && |
| 183 | i1.getName().size() < command_interest::MIN_SIZE)); |
| 184 | VALIDATE_FAILURE(i1, "Should fail (timestamp is missing)"); |
| 185 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
| 186 | |
| 187 | auto i2 = makeCommandInterest(identity, SignedInterestFormat::V02); |
| 188 | setNameComponent(i2, command_interest::POS_TIMESTAMP, "not-timestamp"); |
| 189 | BOOST_TEST_REQUIRE(i2.getName().size() >= command_interest::MIN_SIZE); |
| 190 | VALIDATE_FAILURE(i2, "Should fail (timestamp is malformed)"); |
| 191 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
| 192 | } |
| 193 | |
| 194 | BOOST_AUTO_TEST_CASE(BadTimestampV03) |
| 195 | { |
| 196 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V03); |
| 197 | auto si = i1.getSignatureInfo().value(); |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 198 | si.setTime(std::nullopt); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 199 | i1.setSignatureInfo(si); |
| 200 | VALIDATE_FAILURE(i1, "Should fail (timestamp is missing)"); |
| 201 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
| 202 | } |
| 203 | |
| 204 | BOOST_AUTO_TEST_CASE(MissingKeyLocatorV02) |
| 205 | { |
| 206 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V02); |
Junxiao Shi | 605671d | 2017-08-26 13:41:06 +0000 | [diff] [blame] | 207 | SignatureInfo sigInfo(tlv::SignatureSha256WithRsa); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 208 | setNameComponent(i1, command_interest::POS_SIG_INFO, |
| 209 | sigInfo.wireEncode().begin(), sigInfo.wireEncode().end()); |
| 210 | VALIDATE_FAILURE(i1, "Should fail (missing KeyLocator)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 211 | BOOST_TEST(lastError.getCode() == ValidationError::INVALID_KEY_LOCATOR); |
| 212 | } |
| 213 | |
| 214 | BOOST_AUTO_TEST_CASE(MissingKeyLocatorV03) |
| 215 | { |
| 216 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V03); |
| 217 | auto si = i1.getSignatureInfo().value(); |
Davide Pesavento | f6b4589 | 2023-03-13 15:00:51 -0400 | [diff] [blame] | 218 | si.setKeyLocator(std::nullopt); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 219 | i1.setSignatureInfo(si); |
| 220 | VALIDATE_FAILURE(i1, "Should fail (missing KeyLocator)"); |
| 221 | BOOST_TEST(lastError.getCode() == ValidationError::INVALID_KEY_LOCATOR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | BOOST_AUTO_TEST_CASE(BadKeyLocatorType) |
| 225 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 226 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V02); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 227 | KeyLocator kl; |
Davide Pesavento | fbea4fc | 2022-02-08 07:26:04 -0500 | [diff] [blame] | 228 | kl.setKeyDigest(makeBinaryBlock(tlv::KeyDigest, {0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD})); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 229 | SignatureInfo sigInfo(tlv::SignatureSha256WithRsa, kl); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 230 | setNameComponent(i1, command_interest::POS_SIG_INFO, |
| 231 | sigInfo.wireEncode().begin(), sigInfo.wireEncode().end()); |
| 232 | VALIDATE_FAILURE(i1, "Should fail (bad KeyLocator type)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 233 | BOOST_TEST(lastError.getCode() == ValidationError::INVALID_KEY_LOCATOR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | BOOST_AUTO_TEST_CASE(BadCertName) |
| 237 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 238 | auto i1 = makeCommandInterest(identity, SignedInterestFormat::V02); |
| 239 | SignatureInfo sigInfo(tlv::SignatureSha256WithEcdsa, KeyLocator("/bad/cert/name")); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 240 | setNameComponent(i1, command_interest::POS_SIG_INFO, |
| 241 | sigInfo.wireEncode().begin(), sigInfo.wireEncode().end()); |
| 242 | VALIDATE_FAILURE(i1, "Should fail (bad certificate name)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 243 | BOOST_TEST(lastError.getCode() == ValidationError::INVALID_KEY_LOCATOR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | BOOST_AUTO_TEST_CASE(InnerPolicyReject) |
| 247 | { |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 248 | auto i1 = makeCommandInterest(otherIdentity, SignedInterestFormat::V02); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 249 | VALIDATE_FAILURE(i1, "Should fail (inner policy should reject)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 250 | BOOST_TEST(lastError.getCode() == ValidationError::LOOP_DETECTED); |
| 251 | |
| 252 | auto i2 = makeCommandInterest(otherIdentity, SignedInterestFormat::V03); |
| 253 | VALIDATE_FAILURE(i2, "Should fail (inner policy should reject)"); |
| 254 | BOOST_TEST(lastError.getCode() == ValidationError::LOOP_DETECTED); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 257 | BOOST_FIXTURE_TEST_CASE(TimestampOutOfGracePositive, |
| 258 | ValidationPolicyCommandInterestFixture<GracePeriodSeconds<15>>) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 259 | { |
| 260 | auto i1 = makeCommandInterest(identity); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 261 | advanceClocks(16_s); // verifying at +16s |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 262 | VALIDATE_FAILURE(i1, "Should fail (timestamp outside the grace period)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 263 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 264 | rewindClockAfterValidation(); |
| 265 | |
| 266 | auto i2 = makeCommandInterest(identity); // signed at +16s |
| 267 | VALIDATE_SUCCESS(i2, "Should succeed"); |
| 268 | } |
| 269 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 270 | BOOST_FIXTURE_TEST_CASE(TimestampOutOfGraceNegative, |
| 271 | ValidationPolicyCommandInterestFixture<GracePeriodSeconds<15>>) |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 272 | { |
| 273 | auto i1 = makeCommandInterest(identity); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 274 | advanceClocks(1_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 275 | auto i2 = makeCommandInterest(identity); // signed at +1s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 276 | advanceClocks(1_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 277 | auto i3 = makeCommandInterest(identity); // signed at +2s |
| 278 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 279 | m_systemClock->advance(-18_s); // verifying at -16s |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 280 | VALIDATE_FAILURE(i1, "Should fail (timestamp outside the grace period)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 281 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 282 | rewindClockAfterValidation(); |
| 283 | |
| 284 | // CommandInterestValidator should not remember i1's timestamp |
| 285 | VALIDATE_FAILURE(i2, "Should fail (timestamp outside the grace period)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 286 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 287 | rewindClockAfterValidation(); |
| 288 | |
| 289 | // CommandInterestValidator should not remember i2's timestamp, and should treat i3 as initial |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 290 | advanceClocks(18_s); // verifying at +2s |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 291 | VALIDATE_SUCCESS(i3, "Should succeed"); |
| 292 | } |
| 293 | |
| 294 | BOOST_AUTO_TEST_CASE(TimestampReorderEqual) |
| 295 | { |
| 296 | auto i1 = makeCommandInterest(identity); // signed at 0s |
| 297 | VALIDATE_SUCCESS(i1, "Should succeed"); |
| 298 | |
| 299 | auto i2 = makeCommandInterest(identity); // signed at 0s |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 300 | setNameComponent(i2, command_interest::POS_TIMESTAMP, i1.getName()[command_interest::POS_TIMESTAMP]); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 301 | VALIDATE_FAILURE(i2, "Should fail (timestamp reordered)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 302 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 303 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 304 | advanceClocks(2_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 305 | auto i3 = makeCommandInterest(identity); // signed at +2s |
| 306 | VALIDATE_SUCCESS(i3, "Should succeed"); |
| 307 | } |
| 308 | |
| 309 | BOOST_AUTO_TEST_CASE(TimestampReorderNegative) |
| 310 | { |
| 311 | auto i2 = makeCommandInterest(identity); // signed at 0ms |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 312 | advanceClocks(200_ms); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 313 | auto i3 = makeCommandInterest(identity); // signed at +200ms |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 314 | advanceClocks(900_ms); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 315 | auto i1 = makeCommandInterest(identity); // signed at +1100ms |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 316 | advanceClocks(300_ms); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 317 | auto i4 = makeCommandInterest(identity); // signed at +1400ms |
| 318 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 319 | m_systemClock->advance(-300_ms); // verifying at +1100ms |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 320 | VALIDATE_SUCCESS(i1, "Should succeed"); |
| 321 | rewindClockAfterValidation(); |
| 322 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 323 | m_systemClock->advance(-1100_ms); // verifying at 0ms |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 324 | VALIDATE_FAILURE(i2, "Should fail (timestamp reordered)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 325 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 326 | rewindClockAfterValidation(); |
| 327 | |
| 328 | // CommandInterestValidator should not remember i2's timestamp |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 329 | advanceClocks(200_ms); // verifying at +200ms |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 330 | VALIDATE_FAILURE(i3, "Should fail (timestamp reordered)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 331 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 332 | rewindClockAfterValidation(); |
| 333 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 334 | advanceClocks(1200_ms); // verifying at 1400ms |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 335 | VALIDATE_SUCCESS(i4, "Should succeed"); |
| 336 | } |
| 337 | |
| 338 | BOOST_AUTO_TEST_SUITE_END() // Rejects |
| 339 | |
| 340 | BOOST_AUTO_TEST_SUITE(Options) |
| 341 | |
Davide Pesavento | 49e1e87 | 2023-11-11 00:45:23 -0500 | [diff] [blame^] | 342 | using NonPositiveGracePeriods = boost::mp11::mp_list<GracePeriodSeconds<0>, GracePeriodSeconds<-1>>; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 343 | |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 344 | BOOST_FIXTURE_TEST_CASE_TEMPLATE(GraceNonPositive, GracePeriod, NonPositiveGracePeriods, |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 345 | ValidationPolicyCommandInterestFixture<GracePeriod>) |
| 346 | { |
| 347 | auto i1 = this->makeCommandInterest(this->identity); // signed at 0ms |
| 348 | auto i2 = this->makeCommandInterest(this->subIdentity); // signed at 0ms |
| 349 | for (auto interest : {&i1, &i2}) { |
| 350 | setNameComponent(*interest, command_interest::POS_TIMESTAMP, |
| 351 | name::Component::fromNumber(time::toUnixTimestamp(time::system_clock::now()).count())); |
| 352 | } // ensure timestamps are exactly 0ms |
| 353 | |
| 354 | VALIDATE_SUCCESS(i1, "Should succeed when validating at 0ms"); |
| 355 | this->rewindClockAfterValidation(); |
| 356 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 357 | this->advanceClocks(1_ms); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 358 | VALIDATE_FAILURE(i2, "Should fail when validating at 1ms"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 359 | BOOST_TEST(this->lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | class LimitedRecordsOptions |
| 363 | { |
| 364 | public: |
| 365 | static ValidationPolicyCommandInterest::Options |
| 366 | getOptions() |
| 367 | { |
| 368 | ValidationPolicyCommandInterest::Options options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 369 | options.gracePeriod = 15_s; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 370 | options.maxRecords = 3; |
| 371 | return options; |
| 372 | } |
| 373 | }; |
| 374 | |
| 375 | BOOST_FIXTURE_TEST_CASE(LimitedRecords, ValidationPolicyCommandInterestFixture<LimitedRecordsOptions>) |
| 376 | { |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 377 | Identity id1 = this->addSubCertificate("/Security/ValidatorFixture/Sub1", identity); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 378 | this->cache.insert(id1.getDefaultKey().getDefaultCertificate()); |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 379 | Identity id2 = this->addSubCertificate("/Security/ValidatorFixture/Sub2", identity); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 380 | this->cache.insert(id2.getDefaultKey().getDefaultCertificate()); |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 381 | Identity id3 = this->addSubCertificate("/Security/ValidatorFixture/Sub3", identity); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 382 | this->cache.insert(id3.getDefaultKey().getDefaultCertificate()); |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 383 | Identity id4 = this->addSubCertificate("/Security/ValidatorFixture/Sub4", identity); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 384 | this->cache.insert(id4.getDefaultKey().getDefaultCertificate()); |
| 385 | |
| 386 | auto i1 = makeCommandInterest(id2); |
| 387 | auto i2 = makeCommandInterest(id3); |
| 388 | auto i3 = makeCommandInterest(id4); |
| 389 | auto i00 = makeCommandInterest(id1); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 390 | advanceClocks(1_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 391 | auto i01 = makeCommandInterest(id1); // signed at 1s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 392 | advanceClocks(1_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 393 | auto i02 = makeCommandInterest(id1); // signed at 2s |
| 394 | |
| 395 | VALIDATE_SUCCESS(i00, "Should succeed"); |
| 396 | rewindClockAfterValidation(); |
| 397 | |
| 398 | VALIDATE_SUCCESS(i02, "Should succeed"); |
| 399 | rewindClockAfterValidation(); |
| 400 | |
| 401 | VALIDATE_SUCCESS(i1, "Should succeed"); |
| 402 | rewindClockAfterValidation(); |
| 403 | |
| 404 | VALIDATE_SUCCESS(i2, "Should succeed"); |
| 405 | rewindClockAfterValidation(); |
| 406 | |
| 407 | VALIDATE_SUCCESS(i3, "Should succeed, forgets identity id1"); |
| 408 | rewindClockAfterValidation(); |
| 409 | |
| 410 | VALIDATE_SUCCESS(i01, "Should succeed despite timestamp is reordered, because record has been evicted"); |
| 411 | } |
| 412 | |
| 413 | class UnlimitedRecordsOptions |
| 414 | { |
| 415 | public: |
| 416 | static ValidationPolicyCommandInterest::Options |
| 417 | getOptions() |
| 418 | { |
| 419 | ValidationPolicyCommandInterest::Options options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 420 | options.gracePeriod = 15_s; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 421 | options.maxRecords = -1; |
| 422 | return options; |
| 423 | } |
| 424 | }; |
| 425 | |
| 426 | BOOST_FIXTURE_TEST_CASE(UnlimitedRecords, ValidationPolicyCommandInterestFixture<UnlimitedRecordsOptions>) |
| 427 | { |
| 428 | std::vector<Identity> identities; |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 429 | for (size_t i = 0; i < 20; ++i) { |
Alexander Afanasyev | 09236c2 | 2020-06-03 13:42:38 -0400 | [diff] [blame] | 430 | Identity id = this->addSubCertificate("/Security/ValidatorFixture/Sub" + to_string(i), identity); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 431 | this->cache.insert(id.getDefaultKey().getDefaultCertificate()); |
| 432 | identities.push_back(id); |
| 433 | } |
| 434 | |
| 435 | auto i1 = makeCommandInterest(identities.at(0)); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 436 | advanceClocks(1_s); |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 437 | for (size_t i = 0; i < 20; ++i) { |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 438 | auto i2 = makeCommandInterest(identities.at(i)); // signed at +1s |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 439 | VALIDATE_SUCCESS(i2, "Should succeed"); |
| 440 | rewindClockAfterValidation(); |
| 441 | } |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 442 | |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 443 | VALIDATE_FAILURE(i1, "Should fail (timestamp reorder)"); |
Davide Pesavento | 2acce25 | 2022-09-08 22:03:03 -0400 | [diff] [blame] | 444 | BOOST_TEST(lastError.getCode() == ValidationError::POLICY_ERROR); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | class ZeroRecordsOptions |
| 448 | { |
| 449 | public: |
| 450 | static ValidationPolicyCommandInterest::Options |
| 451 | getOptions() |
| 452 | { |
| 453 | ValidationPolicyCommandInterest::Options options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 454 | options.gracePeriod = 15_s; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 455 | options.maxRecords = 0; |
| 456 | return options; |
| 457 | } |
| 458 | }; |
| 459 | |
| 460 | BOOST_FIXTURE_TEST_CASE(ZeroRecords, ValidationPolicyCommandInterestFixture<ZeroRecordsOptions>) |
| 461 | { |
| 462 | auto i1 = makeCommandInterest(identity); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 463 | advanceClocks(1_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 464 | auto i2 = makeCommandInterest(identity); // signed at +1s |
| 465 | VALIDATE_SUCCESS(i2, "Should succeed"); |
| 466 | rewindClockAfterValidation(); |
| 467 | |
| 468 | VALIDATE_SUCCESS(i1, "Should succeed despite timestamp is reordered, because record isn't kept"); |
| 469 | } |
| 470 | |
| 471 | class LimitedRecordLifetimeOptions |
| 472 | { |
| 473 | public: |
| 474 | static ValidationPolicyCommandInterest::Options |
| 475 | getOptions() |
| 476 | { |
| 477 | ValidationPolicyCommandInterest::Options options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 478 | options.gracePeriod = 400_s; |
| 479 | options.recordLifetime = 300_s; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 480 | return options; |
| 481 | } |
| 482 | }; |
| 483 | |
| 484 | BOOST_FIXTURE_TEST_CASE(LimitedRecordLifetime, ValidationPolicyCommandInterestFixture<LimitedRecordLifetimeOptions>) |
| 485 | { |
| 486 | auto i1 = makeCommandInterest(identity); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 487 | advanceClocks(240_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 488 | auto i2 = makeCommandInterest(identity); // signed at +240s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 489 | advanceClocks(120_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 490 | auto i3 = makeCommandInterest(identity); // signed at +360s |
| 491 | |
Davide Pesavento | 4c1ad4c | 2020-11-16 21:12:02 -0500 | [diff] [blame] | 492 | m_systemClock->advance(-360_s); // rewind system clock to 0s |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 493 | VALIDATE_SUCCESS(i1, "Should succeed"); |
| 494 | rewindClockAfterValidation(); |
| 495 | |
| 496 | VALIDATE_SUCCESS(i3, "Should succeed"); |
| 497 | rewindClockAfterValidation(); |
| 498 | |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 499 | advanceClocks(30_s, 301_s); // advance steady clock by 301s, and system clock to +301s |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 500 | VALIDATE_SUCCESS(i2, "Should succeed despite timestamp is reordered, because record has been expired"); |
| 501 | } |
| 502 | |
| 503 | class ZeroRecordLifetimeOptions |
| 504 | { |
| 505 | public: |
| 506 | static ValidationPolicyCommandInterest::Options |
| 507 | getOptions() |
| 508 | { |
| 509 | ValidationPolicyCommandInterest::Options options; |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 510 | options.gracePeriod = 15_s; |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 511 | options.recordLifetime = time::seconds::zero(); |
| 512 | return options; |
| 513 | } |
| 514 | }; |
| 515 | |
| 516 | BOOST_FIXTURE_TEST_CASE(ZeroRecordLifetime, ValidationPolicyCommandInterestFixture<ZeroRecordLifetimeOptions>) |
| 517 | { |
| 518 | auto i1 = makeCommandInterest(identity); // signed at 0s |
Davide Pesavento | 0f83080 | 2018-01-16 23:58:58 -0500 | [diff] [blame] | 519 | advanceClocks(1_s); |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 520 | auto i2 = makeCommandInterest(identity); // signed at +1s |
| 521 | VALIDATE_SUCCESS(i2, "Should succeed"); |
| 522 | rewindClockAfterValidation(); |
| 523 | |
| 524 | VALIDATE_SUCCESS(i1, "Should succeed despite timestamp is reordered, because record has been expired"); |
| 525 | } |
| 526 | |
| 527 | BOOST_AUTO_TEST_SUITE_END() // Options |
| 528 | |
| 529 | BOOST_AUTO_TEST_SUITE_END() // TestValidationPolicyCommandInterest |
Alexander Afanasyev | 9333887 | 2017-01-30 22:37:00 -0800 | [diff] [blame] | 530 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 531 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 532 | } // namespace ndn::tests |