7 #ifndef NDN_UTIL_COMMAND_INTEREST_VALIDATOR_HPP
8 #define NDN_UTIL_COMMAND_INTEREST_VALIDATOR_HPP
10 #include "../security/validator.hpp"
11 #include "../security/identity-certificate.hpp"
12 #include "../security/sec-rule-specific.hpp"
32 : m_graceInterval(graceInterval < time::milliseconds::zero() ?
33 time::milliseconds(static_cast<int>(
GRACE_INTERVAL)) : graceInterval)
54 std::vector<shared_ptr<ValidationRequest> >& nextSteps)
56 onValidationFailed(data.shared_from_this(),
"No policy for data checking");
64 std::vector<shared_ptr<ValidationRequest> >& nextSteps);
66 time::milliseconds m_graceInterval;
67 std::map<Name, PublicKey> m_trustAnchorsForInterest;
68 std::list<SecRuleSpecific> m_trustScopeForInterest;
70 typedef std::map<Name, time::system_clock::TimePoint> LastTimestampMap;
71 LastTimestampMap m_lastTimestamp;
87 m_trustAnchorsForInterest[keyName] = publicKey;
88 shared_ptr<Regex> interestRegex = make_shared<Regex>(regex);
90 m_trustScopeForInterest.push_back(
SecRuleSpecific(interestRegex, signerRegex));
98 std::vector<shared_ptr<ValidationRequest> >& nextSteps)
104 return onValidationFailed(interest.shared_from_this(),
105 "Interest is not signed: " + interest.
getName().
toUri());
113 return onValidationFailed(interest.shared_from_this(),
114 "Require SignatureSha256WithRsa");
121 return onValidationFailed(interest.shared_from_this(),
122 "Key Locator is not a name");
127 bool isInScope =
false;
128 for (std::list<SecRuleSpecific>::iterator scopeIt = m_trustScopeForInterest.begin();
129 scopeIt != m_trustScopeForInterest.end();
132 if (scopeIt->satisfy(interestName, keyName))
138 if (isInScope ==
false)
139 return onValidationFailed(interest.shared_from_this(),
140 "Signer cannot be authorized for the command: " +
146 interestName[-1].
size(),
147 sig, m_trustAnchorsForInterest[keyName]))
148 return onValidationFailed(interest.shared_from_this(),
149 "Signature cannot be validated: " +
158 LastTimestampMap::iterator timestampIt = m_lastTimestamp.find(keyName);
159 if (timestampIt == m_lastTimestamp.end())
161 if (!(currentTime - m_graceInterval <= interestTime &&
162 interestTime <= currentTime + m_graceInterval))
163 return onValidationFailed(interest.shared_from_this(),
164 "The command is not in grace interval: " +
169 if (interestTime <= timestampIt->second)
170 return onValidationFailed(interest.shared_from_this(),
171 "The command is outdated: " +
176 if (timestampIt == m_lastTimestamp.end())
178 m_lastTimestamp[keyName] = interestTime;
182 timestampIt->second = interestTime;
187 return onValidationFailed(interest.shared_from_this(),
188 "No valid signature");
192 return onValidationFailed(interest.shared_from_this(),
193 "Cannot locate the signing key");
197 return onValidationFailed(interest.shared_from_this(),
198 "Cannot decode signature related TLVs");
201 return onValidated(interest.shared_from_this());
206 #endif // NDN_UTIL_COMMAND_INTEREST_VALIDATOR_HPP
Representing of SHA256-with-RSA signature in a data packet.
const Name & getName() const
static shared_ptr< RegexTopMatcher > fromName(const Name &name, bool hasAnchor=false)
void addInterestRule(const std::string ®ex, const IdentityCertificate &certificate)
static Name certificateNameToPublicKeyName(const Name &certificateName)
Get the public key name from the full certificate name.
An Interest holds a Name and other fields for an interest.
PublicKey & getPublicKeyInfo()
const Name & getName() const
std::string toUri() const
Encode this name as a URI.
const Name & getName() const
function< void(const shared_ptr< const Data > &)> OnDataValidated
Callback to report a successful Data validation.
virtual ~CommandInterestValidator()
const KeyLocator & getKeyLocator() const
function< void(const shared_ptr< const Data > &, const std::string &)> OnDataValidationFailed
Callback to report a failed Data validation.
size_t size() const
Get the number of components.
A Name holds an array of Name::Component and represents an NDN name.
size_t wireEncode(EncodingImpl< T > &block) const
Fast encoding or block size estimation.
CommandInterestValidator(const time::milliseconds &graceInterval=time::milliseconds(static_cast< int >(GRACE_INTERVAL)))
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
system_clock::TimePoint fromUnixTimestamp(const milliseconds &duration)
Convert UNIX timestamp to system_clock::TimePoint.
static bool verifySignature(const Data &data, const PublicKey &publicKey)
Verify the data using the publicKey.
virtual void checkPolicy(const Data &data, int stepCount, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed, std::vector< shared_ptr< ValidationRequest > > &nextSteps)
Check the Data against policy and return the next validation step if necessary.
uint64_t toNumber() const
Interpret this name component as nonNegativeInteger.
Validator is one of the main classes of the security library.
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
const Component & get(ssize_t i) const
Get the component at the given index.
A Signature is storage for the signature-related information (info and value) in a Data packet...