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