31 , m_byKeyName(m_container.
get<0>())
32 , m_byLastRefreshed(m_container.
get<1>())
34 if (inner ==
nullptr) {
35 NDN_THROW(std::invalid_argument(
"Inner policy is missing"));
44 const shared_ptr<ValidationState>& state,
52 const shared_ptr<ValidationState>& state,
58 if (!state->getOutcome()) {
70 ValidationPolicySignedInterest::checkIncomingInterest(
const shared_ptr<ValidationState>& state,
80 auto record = m_byKeyName.find(keyName);
83 if (!timestamp.has_value()) {
85 "Timestamp is required by policy but is not present"});
92 "Timestamp is outside the grace period for key " + keyName.toUri()});
96 if (record != m_byKeyName.end() && record->timestamp.has_value() && timestamp <= record->timestamp) {
98 "Timestamp is reordered for key " + keyName.toUri()});
104 if (!seqNum.has_value()) {
106 "Sequence number is required by policy but is not present"});
110 if (record != m_byKeyName.end() && record->seqNum.has_value() && seqNum <= record->seqNum) {
112 "Sequence number is reordered for key " + keyName.toUri()});
118 if (!nonce.has_value()) {
123 if (record != m_byKeyName.end() && record->observedNonces.get<NonceSet>().count(*nonce) > 0) {
125 "Nonce matches previously-seen nonce for key " + keyName.toUri()});
132 BOOST_ASSERT(interestState !=
nullptr);
133 interestState->afterSuccess.connect([=] (
const Interest&) {
134 insertRecord(keyName, timestamp, seqNum, nonce);
141 ValidationPolicySignedInterest::insertRecord(
const Name& keyName,
142 optional<time::system_clock::TimePoint> timestamp,
143 optional<uint64_t> seqNum,
144 optional<SigNonce> nonce)
147 Container::nth_index<0>::type::iterator it;
149 std::tie(it, isOk) = m_byKeyName.emplace(keyName, timestamp, seqNum);
152 isOk = m_byKeyName.modify(it, [&] (LastInterestRecord& record) {
154 if (timestamp.has_value()) {
155 record.timestamp = timestamp;
157 if (seqNum.has_value()) {
158 record.seqNum = seqNum;
166 isOk = m_byKeyName.modify(it, [
this, &nonce] (LastInterestRecord& record) {
167 auto& sigNonceList = record.observedNonces.get<NonceList>();
168 sigNonceList.push_back(*nonce);
172 BOOST_ASSERT(sigNonceList.size() ==
static_cast<size_t>(m_options.
maxNonceRecordCount) + 1);
173 sigNonceList.pop_front();
181 m_byLastRefreshed.size() >
static_cast<size_t>(m_options.
maxRecordCount)) {
182 BOOST_ASSERT(m_byLastRefreshed.size() ==
static_cast<size_t>(m_options.
maxRecordCount) + 1);
183 m_byLastRefreshed.erase(m_byLastRefreshed.begin());
void setInnerPolicy(unique_ptr< ValidationPolicy > innerPolicy)
Set inner policy.
Sign Interest using Packet Specification v0.3 semantics.
bool shouldValidateSeqNums
Whether to validate sequence numbers in signed Interests by ensuring they are present and are strictl...
Copyright (c) 2011-2015 Regents of the University of California.
static time_point now() noexcept
R & get(variant< T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15 > &v, nonstd_lite_in_place_type_t(R)=nonstd_lite_in_place_type(R))
void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Check data against the policy.
Represents an Interest packet.
ValidationPolicy & getInnerPolicy()
Return the inner policy.
static time_point now() noexcept
time::nanoseconds timestampGracePeriod
Tolerance of timestamp differences from the current time.
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
optional< SignatureInfo > getSignatureInfo() const
Get the InterestSignatureInfo.
provides a tag type for simple types
ssize_t maxRecordCount
Max number of distinct public keys to track.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
bool shouldValidateNonces
Whether to validate nonces by ensuring that they are present and do not overlap with one of the last ...
static Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
Validation state for an interest packet.
ValidationPolicySignedInterest(unique_ptr< ValidationPolicy > inner, const Options &options={})
Constructor.
Represents an absolute name.
ssize_t maxNonceRecordCount
Number of previous nonces to track for each public key.
bool shouldValidateTimestamps
Whether to validate timestamps in signed Interests by ensuring they are not reordered for a given pub...
virtual void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check data against the policy.
Represents a Data packet.