26 #include "../util/crypto.hpp" 33 static Oid
SECP256R1(
"1.2.840.10045.3.1.7");
54 std::vector<shared_ptr<ValidationRequest> > nextSteps;
55 checkPolicy(interest, nSteps, onValidated, onValidationFailed, nextSteps);
57 if (nextSteps.empty()) {
64 OnFailure onFailure = bind(onValidationFailed, interest.shared_from_this(), _1);
74 std::vector<shared_ptr<ValidationRequest> > nextSteps;
75 checkPolicy(data, nSteps, onValidated, onValidationFailed, nextSteps);
77 if (nextSteps.empty()) {
84 OnFailure onFailure = bind(onValidationFailed, data.shared_from_this(), _1);
91 const shared_ptr<ValidationRequest>& nextStep)
95 if (!static_cast<bool>(certificateData))
96 return nextStep->m_onDataValidationFailed(data.shared_from_this(),
100 nextStep->m_onDataValidated, nextStep->m_onDataValidationFailed,
156 RSA::PublicKey publicKey;
159 queue.Put(reinterpret_cast<const byte*>(key.
get().
buf()), key.
get().size());
160 publicKey.Load(queue);
162 RSASS<PKCS1v15, SHA256>::Verifier verifier(publicKey);
163 return verifier.VerifyMessage(buf, size,
171 ECDSA<ECP, SHA256>::PublicKey publicKey;
174 queue.Put(reinterpret_cast<const byte*>(key.
get().
buf()), key.
get().size());
175 publicKey.Load(queue);
177 ECDSA<ECP, SHA256>::Verifier verifier(publicKey);
180 StringSource src(key.
get().
buf(), key.
get().size(),
true);
181 BERSequenceDecoder subjectPublicKeyInfo(src);
183 BERSequenceDecoder algorithmInfo(subjectPublicKeyInfo);
186 algorithm.
decode(algorithmInfo);
189 curveId.
decode(algorithmInfo);
203 size_t usedSize = DSAConvertSignatureFormat(buffer,
sizeof(buffer), DSA_P1363,
207 return verifier.VerifyMessage(buf, size, buffer, usedSize);
212 size_t usedSize = DSAConvertSignatureFormat(buffer,
sizeof(buffer), DSA_P1363,
216 return verifier.VerifyMessage(buf, size, buffer, usedSize);
229 catch (
const CryptoPP::Exception& e) {
241 if (buffer !=
nullptr &&
244 const uint8_t* p1 = buffer->buf();
245 const uint8_t* p2 = sigValue.
value();
252 catch (
const CryptoPP::Exception& e) {
260 int remainingRetries,
262 const shared_ptr<ValidationRequest>& validationRequest)
264 if (remainingRetries > 0) {
272 remainingRetries - 1, onFailure, validationRequest),
274 remainingRetries - 1, onFailure, validationRequest));
277 onFailure(
"Cannot fetch cert: " + interest.
getName().
toUri());
283 int remainingRetries,
285 const shared_ptr<ValidationRequest>& validationRequest)
287 if (remainingRetries > 0) {
295 remainingRetries - 1, onFailure, validationRequest),
297 remainingRetries - 1, onFailure, validationRequest));
300 onFailure(
"Cannot fetch cert: " + interest.
getName().
toUri());
309 onFailure(
"Require more information to validate the packet!");
313 for (shared_ptr<ValidationRequest> step : nextSteps) {
317 step->m_nRetries, onFailure, step),
319 this, _1, step->m_nRetries,
void decode(CryptoPP::BufferedTransformation &in)
function< void(const shared_ptr< const Interest > &, const std::string &)> OnInterestValidationFailed
Callback to report a failed Interest validation.
void validate(const Data &data, const OnDataValidated &onValidated, const OnDataValidationFailed &onValidationFailed)
Validate Data and call either onValidated or onValidationFailed.
Copyright (c) 2011-2015 Regents of the University of California.
std::string toUri() const
Encode this name as a URI.
const Buffer & get() const
Copyright (c) 2013-2016 Regents of the University of California.
virtual shared_ptr< const Data > preCertificateValidation(const Data &data)
Hooks.
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.
void refreshNonce()
Refresh nonce.
size_t value_size() const
const Name & getName() const
Get name of the Data packet.
static const size_t SHA256_DIGEST_SIZE
number of octets in a SHA256 digest
Represent a SHA256 digest.
void setInfo(const Block &info)
Set SignatureInfo from a block.
virtual void afterCheckPolicy(const std::vector< shared_ptr< ValidationRequest >> &nextSteps, const OnFailure &onFailure)
trigger after checkPolicy is done.
Class representing a wire element of NDN-TLV packet format.
represents an Interest packet
const uint8_t * value() const
function< void(const shared_ptr< const Data > &, const std::string &)> OnDataValidationFailed
Callback to report a failed Data validation.
bool hasKeyLocator() const
Check if SignatureInfo block has a KeyLocator.
function< void(const shared_ptr< const Data > &)> OnDataValidated
Callback to report a successful Data validation.
represents a Network Nack
function< void(const shared_ptr< const Interest > &)> OnInterestValidated
Callback to report a successful Interest validation.
Validator(Face *face=nullptr)
Validator constructor.
void setValue(const Block &value)
Get SignatureValue from a block.
const Block & getValue() const
Get SignatureValue in the wire format.
Provide a communication channel with local or remote NDN forwarder.
Name abstraction to represent an absolute name.
const ssize_t POS_SIG_VALUE
function< void(const std::string &)> OnFailure
void onData(const Interest &interest, const Data &data, const shared_ptr< ValidationRequest > &nextStep)
Process the received certificate.
size_t size() const
Get the number of components.
static Oid SECP384R1("1.3.132.0.34")
const ssize_t POS_SIG_INFO
ConstBufferPtr computeSha256Digest(const uint8_t *data, size_t dataLength)
Compute the sha-256 digest of data.
size_t wireEncode(EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
Fast encoding or block size estimation.
const size_t MIN_LENGTH_SIG_ONLY
minimal number of components for Signed Interest
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
uint32_t getType() const
Get signature type.
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
virtual void onNack(const Interest &interest, const lp::Nack &nack, int nRemainingRetries, const OnFailure &onFailure, const shared_ptr< ValidationRequest > &validationRequest)
trigger when interest retrieves a Nack.
static bool verifySignature(const Data &data, const v1::PublicKey &publicKey)
Verify the data using the publicKey.
const Signature & getSignature() const
shared_ptr< const Buffer > ConstBufferPtr
KeyType getKeyType() const
represents an error in TLV encoding or decoding
const Name & getName() const
A Signature is storage for the signature-related information (info and value) in a Data packet...
static Oid SECP256R1("1.2.840.10045.3.1.7")
virtual void onTimeout(const Interest &interest, int nRemainingRetries, const OnFailure &onFailure, const shared_ptr< ValidationRequest > &validationRequest)
trigger when interest for certificate times out.