33 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(this->getDepth() + 1, '>') << " " << x) 34 #define NDN_LOG_TRACE_DEPTH(x) NDN_LOG_TRACE(std::string(this->getDepth() + 1, '>') << " " << x) 37 : m_outcome(
boost::logic::indeterminate)
44 BOOST_ASSERT(!boost::logic::indeterminate(
m_outcome));
50 return m_certificateChain.size();
56 return !m_seenCertificateNames.insert(certName).second;
62 m_certificateChain.push_front(cert);
66 ValidationState::verifyCertificateChain(
const Certificate& trustedCert)
69 for (
auto it = m_certificateChain.begin(); it != m_certificateChain.end(); ++it) {
70 const auto& certToValidate = *it;
73 this->
fail({ValidationError::Code::INVALID_SIGNATURE,
"Invalid signature of certificate `" +
74 certToValidate.getName().toUri() +
"`"});
75 m_certificateChain.erase(it, m_certificateChain.end());
80 validatedCert = &certToValidate;
92 , m_successCb(successCb)
93 , m_failureCb(failureCb)
95 BOOST_ASSERT(m_successCb !=
nullptr);
96 BOOST_ASSERT(m_failureCb !=
nullptr);
101 if (boost::logic::indeterminate(
m_outcome)) {
102 this->
fail({ValidationError::Code::IMPLEMENTATION_ERROR,
103 "Validator/policy did not invoke success or failure callback"});
108 DataValidationState::verifyOriginalPacket(
const optional<Certificate>& trustedCert)
113 BOOST_ASSERT(boost::logic::indeterminate(
m_outcome));
117 this->
fail({ValidationError::Code::INVALID_SIGNATURE,
"Invalid signature of data `" +
123 DataValidationState::bypassValidation()
127 BOOST_ASSERT(boost::logic::indeterminate(
m_outcome));
135 m_failureCb(m_data, error);
136 BOOST_ASSERT(boost::logic::indeterminate(
m_outcome));
151 : m_interest(interest)
152 , m_failureCb(failureCb)
155 BOOST_ASSERT(successCb !=
nullptr);
156 BOOST_ASSERT(m_failureCb !=
nullptr);
161 if (boost::logic::indeterminate(
m_outcome)) {
162 this->
fail({ValidationError::Code::IMPLEMENTATION_ERROR,
163 "Validator/policy did not invoke success or failure callback"});
168 InterestValidationState::verifyOriginalPacket(
const optional<Certificate>& trustedCert)
173 BOOST_ASSERT(boost::logic::indeterminate(
m_outcome));
177 this->
fail({ValidationError::Code::INVALID_SIGNATURE,
"Invalid signature of interest `" +
183 InterestValidationState::bypassValidation()
187 BOOST_ASSERT(boost::logic::indeterminate(
m_outcome));
195 m_failureCb(m_interest, error);
196 BOOST_ASSERT(boost::logic::indeterminate(
m_outcome));
ValidationState()
Create validation state.
DataValidationState(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Create validation state for data.
const Data & getOriginalData() const
Copyright (c) 2011-2015 Regents of the University of California.
Represents an NDN certificate following the version 2.0 format.
void fail(const ValidationError &error) final
Call the failure callback.
bool verifySignature(const InputBuffers &blobs, span< const uint8_t > sig, const transform::PublicKey &key)
Verify blobs using key against sig.
const Interest & getOriginalInterest() const
function< void(const Data &data)> DataValidationSuccessCallback
Callback to report a successful Data validation.
bool hasSeenCertificateName(const Name &certName)
Check if certName has been previously seen and record the supplied name.
void addCertificate(const Certificate &cert)
Add cert to the top of the certificate chain.
Represents an Interest packet.
#define NDN_LOG_DEBUG_DEPTH(x)
function< void(const Data &data, const ValidationError &error)> DataValidationFailureCallback
Callback to report a failed Data validation.
#define NDN_LOG_TRACE_DEPTH(x)
virtual ~ValidationState()
util::Signal< InterestValidationState, Interest > afterSuccess
const Name & getName() const noexcept
Get name.
Represents an absolute name.
#define NDN_LOG_TRACE(expression)
~InterestValidationState() final
Destructor.
void fail(const ValidationError &error) final
Call the failure callback.
function< void(const Interest &interest, const ValidationError &error)> InterestValidationFailureCallback
Callback to report a failed Interest validation.
InterestValidationState(const Interest &interest, const InterestValidationSuccessCallback &successCb, const InterestValidationFailureCallback &failureCb)
Create validation state for interest.
Validation error code and optional detailed error message.
const Name & getName() const noexcept
~DataValidationState() final
Destructor.
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
#define NDN_LOG_INIT(name)
declare a log module
virtual void fail(const ValidationError &error)=0
Call the failure callback.
Represents a Data packet.
boost::logic::tribool m_outcome
function< void(const Interest &interest)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.