29 , m_byKeyName(m_container.get<0>())
30 , m_byLastRefreshed(m_container.get<1>())
32 if (inner ==
nullptr) {
33 NDN_THROW(std::invalid_argument(
"Inner policy is missing"));
42 const shared_ptr<ValidationState>& state,
50 const shared_ptr<ValidationState>& state,
53 if (!state->getOutcome()) {
67 ValidationPolicySignedInterest::checkIncomingInterest(
const shared_ptr<ValidationState>& state,
71 if (!state->getOutcome()) {
75 if (!state->getOutcome()) {
78 auto timestamp = sigInfo.getTime();
79 auto seqNum = sigInfo.getSeqNum();
80 auto nonce = sigInfo.getNonce();
82 auto record = m_byKeyName.find(keyName);
85 if (!timestamp.has_value()) {
93 "Timestamp is outside the grace period for key " + keyName.
toUri()});
97 if (record != m_byKeyName.end() && record->timestamp.has_value() && timestamp <= record->timestamp) {
99 "Timestamp is reordered for key " + keyName.
toUri()});
105 if (!seqNum.has_value()) {
107 "Sequence number is required by policy but is not present"});
111 if (record != m_byKeyName.end() && record->seqNum.has_value() && seqNum <= record->seqNum) {
113 "Sequence number is reordered for key " + keyName.
toUri()});
119 if (!nonce.has_value()) {
124 if (record != m_byKeyName.end() && record->observedNonces.get<NonceSet>().count(*nonce) > 0) {
126 "Nonce matches previously-seen nonce for key " + keyName.
toUri()});
132 auto interestState = std::dynamic_pointer_cast<InterestValidationState>(state);
133 BOOST_ASSERT(interestState !=
nullptr);
134 interestState->afterSuccess.connect([=] (
const Interest&) {
135 insertRecord(keyName, timestamp, seqNum, nonce);
142 ValidationPolicySignedInterest::insertRecord(
const Name& keyName,
143 std::optional<time::system_clock::time_point> timestamp,
144 std::optional<uint64_t> seqNum,
145 std::optional<SigNonce> nonce)
148 auto [it, isOk] = m_byKeyName.emplace(keyName, timestamp, seqNum);
151 isOk = m_byKeyName.modify(it, [&] (LastInterestRecord& record) {
153 if (timestamp.has_value()) {
154 record.timestamp = timestamp;
156 if (seqNum.has_value()) {
157 record.seqNum = seqNum;
165 isOk = m_byKeyName.modify(it, [
this, &nonce] (LastInterestRecord& record) {
166 auto& sigNonceList = record.observedNonces.get<NonceList>();
167 sigNonceList.push_back(*nonce);
171 BOOST_ASSERT(sigNonceList.size() ==
static_cast<size_t>(m_options.
maxNonceRecordCount) + 1);
172 sigNonceList.pop_front();
180 m_byLastRefreshed.size() >
static_cast<size_t>(m_options.
maxRecordCount)) {
181 BOOST_ASSERT(m_byLastRefreshed.size() ==
static_cast<size_t>(m_options.
maxRecordCount) + 1);
182 m_byLastRefreshed.erase(m_byLastRefreshed.begin());
Represents a Data packet.
Represents an Interest packet.
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.
@ POLICY_ERROR
The packet violates the validation rules enforced by the policy.
bool shouldValidateSeqNums
Whether to validate sequence numbers in signed Interests by ensuring they are present and are strictl...
ssize_t maxNonceRecordCount
Number of previous nonces to track for each public key.
time::nanoseconds timestampGracePeriod
Tolerance of timestamp differences from the current time.
ssize_t maxRecordCount
Max number of distinct public keys to track.
bool shouldValidateNonces
Whether to validate nonces by ensuring that they are present and do not overlap with one of the last ...
bool shouldValidateTimestamps
Whether to validate timestamps in signed Interests by ensuring they are not reordered for a given pub...
ValidationPolicySignedInterest(unique_ptr< ValidationPolicy > inner, const Options &options={})
Constructor.
void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Check data against the policy.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
ValidationPolicy & getInnerPolicy()
Return the inner policy.
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
Contains the ndn-cxx security framework.
@ V03
Sign Interest using Packet Specification v0.3 semantics.
SignatureInfo getSignatureInfo(const Interest &interest, ValidationState &state)
Extract SignatureInfo from a signed Interest.
Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
Extract the KeyLocator name from a SignatureInfo element.
constexpr duration< Rep, Period > abs(duration< Rep, Period > d)
Returns the absolute value of the duration d.