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()});
131 auto interestState = dynamic_pointer_cast<InterestValidationState>(state);
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());
Represents a Data packet.
Represents an Interest packet.
optional< SignatureInfo > getSignatureInfo() const
Get the InterestSignatureInfo.
Represents an absolute name.
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
provides a tag type for simple types
ssize_t maxNonceRecordCount
Number of previous nonces to track for each public key.
bool shouldValidateSeqNums
Whether to validate sequence numbers in signed Interests by ensuring they are present and are strictl...
ssize_t maxRecordCount
Max number of distinct public keys to track.
time::nanoseconds timestampGracePeriod
Tolerance of timestamp differences from the current time.
bool shouldValidateTimestamps
Whether to validate timestamps in signed Interests by ensuring they are not reordered for a given pub...
bool shouldValidateNonces
Whether to validate nonces by ensuring that they are present and do not overlap with one of the last ...
void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Check data against the policy.
ValidationPolicySignedInterest(unique_ptr< ValidationPolicy > inner, const Options &options={})
Constructor.
ValidationPolicy & getInnerPolicy()
Return the inner policy.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
virtual void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check data against the policy.
void setInnerPolicy(unique_ptr< ValidationPolicy > innerPolicy)
Set inner policy.
static time_point now() noexcept
static time_point now() noexcept
Name getKeyLocatorName(const Data &data, ValidationState &state)
extract KeyLocator.Name from a Data packet
@ V03
Sign Interest using Packet Specification v0.3 semantics.
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)