12 #include "../util/crypto.hpp"
20 Validator::Validator()
22 , m_face(*static_cast<
Face*>(0))
38 vector<shared_ptr<ValidationRequest> > nextSteps;
39 checkPolicy(interest, nSteps, onValidated, onValidationFailed, nextSteps);
41 if (!nextSteps.empty())
45 onValidationFailed(interest.shared_from_this(),
46 "Require more information to validate the interest!");
50 vector<shared_ptr<ValidationRequest> >::const_iterator it = nextSteps.begin();
51 OnFailure onFailure = bind(onValidationFailed, interest.shared_from_this(), _1);
52 for (; it != nextSteps.end(); it++)
54 bind(&Validator::onData,
this, _1, _2, *it),
55 bind(&Validator::onTimeout,
56 this, _1, (*it)->m_nRetrials,
74 vector<shared_ptr<ValidationRequest> > nextSteps;
75 checkPolicy(data, nSteps, onValidated, onValidationFailed, nextSteps);
77 if (!nextSteps.empty())
81 onValidationFailed(data.shared_from_this(),
82 "Require more information to validate the data!");
85 vector<shared_ptr<ValidationRequest> >::const_iterator it = nextSteps.begin();
86 OnFailure onFailure = bind(onValidationFailed, data.shared_from_this(), _1);
87 for (; it != nextSteps.end(); it++)
89 bind(&Validator::onData,
this, _1, _2, *it),
90 bind(&Validator::onTimeout,
91 this, _1, (*it)->m_nRetrials,
104 Validator::onData(
const Interest& interest,
106 const shared_ptr<ValidationRequest>& nextStep)
108 validate(data, nextStep->m_onValidated, nextStep->m_onDataValidated, nextStep->m_nSteps);
112 Validator::onTimeout(
const Interest& interest,
114 const OnFailure& onFailure,
115 const shared_ptr<ValidationRequest>& nextStep)
120 bind(&Validator::onData,
this, _1, _2, nextStep),
121 bind(&Validator::onTimeout,
this, _1,
122 nRetrials - 1, onFailure, nextStep));
124 onFailure(
"Cannot fetch cert: " + interest.getName().toUri());
157 if (interestName.
size() < 2)
164 Signature sig(interestName[-2].blockFromValue(),
165 interestName[-1].blockFromValue());
227 using namespace CryptoPP;
229 RSA::PublicKey publicKey;
232 queue.Put(reinterpret_cast<const byte*>(key.
get().
buf()), key.
get().size());
233 publicKey.Load(queue);
235 RSASS<PKCS1v15, SHA256>::Verifier verifier(publicKey);
236 return verifier.VerifyMessage(buf, size,
240 catch (CryptoPP::Exception& e)
254 if (static_cast<bool>(buffer) &&
259 const uint8_t* p1 = buffer->buf();
260 const uint8_t* p2 = sigValue.
value();
267 catch (CryptoPP::Exception& e)
Representing of SHA256-with-RSA signature in a data packet.
const Name & getName() const
Representing of SHA256 signature in a data packet.
static const size_t SHA256_DIGEST_SIZE
number of octets in a SHA256 digest
Class representing wire element of the NDN packet.
An Interest holds a Name and other fields for an interest.
const Block & getValue() const
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
function< void(const shared_ptr< const Data > &)> OnDataValidated
Callback to report a successful Data validation.
void validate(const Data &data, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed)
Validate Data and call either onValidated or onValidationFailed.
virtual void checkPolicy(const Data &data, int nSteps, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed, std::vector< shared_ptr< ValidationRequest > > &nextSteps)=0
Check the Data against policy and return the next validation step if necessary.
uint8_t * buf()
Get pointer to the first byte of the buffer (alternative version)
function< void(const shared_ptr< const Data > &, const std::string &)> OnDataValidationFailed
Callback to report a failed Data validation.
Abstraction to communicate with local or remote NDN forwarder.
size_t size() const
Get the number of components.
A Name holds an array of Name::Component and represents an NDN name.
const PendingInterestId * expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout())
Express Interest.
size_t value_size() const
size_t wireEncode(EncodingImpl< T > &block) const
Fast encoding or block size estimation.
const Signature & getSignature() const
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
const Buffer & get() const
static bool verifySignature(const Data &data, const PublicKey &publicKey)
Verify the data using the publicKey.
const uint8_t * value() const
ConstBufferPtr sha256(const uint8_t *data, size_t dataLength)
Compute the sha-256 digest of data.
Class representing a general-use automatically managed/resized buffer.
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
Error that can be thrown from Block.
A Signature is storage for the signature-related information (info and value) in a Data packet...