34 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x)
35 #define NDN_LOG_TRACE_DEPTH(x) NDN_LOG_TRACE(std::string(state->getDepth() + 1, '>') << " " << x)
38 : m_policy(std::move(policy))
39 , m_certFetcher(std::move(certFetcher))
42 BOOST_ASSERT(m_policy !=
nullptr);
43 BOOST_ASSERT(m_certFetcher !=
nullptr);
44 m_policy->setValidator(*
this);
45 m_certFetcher->setCertificateStorage(*
this);
59 return *m_certFetcher;
79 auto state = make_shared<DataValidationState>(data, successCb, failureCb);
82 m_policy->checkPolicy(data, state,
83 [
this] (
const shared_ptr<CertificateRequest>& certRequest,
const shared_ptr<ValidationState>& state) {
84 if (certRequest ==
nullptr) {
85 state->bypassValidation();
89 requestCertificate(certRequest, state);
99 auto state = make_shared<InterestValidationState>(interest, successCb, failureCb);
102 state->setTag(make_shared<SignedInterestFormatTag>(fmt));
106 m_policy->checkPolicy(interest, state,
107 [
this] (
const shared_ptr<CertificateRequest>& certRequest,
const shared_ptr<ValidationState>& state) {
108 if (certRequest ==
nullptr) {
109 state->bypassValidation();
113 requestCertificate(certRequest, state);
124 return state->fail({ValidationError::Code::EXPIRED_CERT,
"Retrieved certificate is not yet valid or expired "
125 "`" + cert.
getName().toUri() +
"`"});
128 m_policy->checkPolicy(cert, state,
129 [
this, cert] (
const shared_ptr<CertificateRequest>& certRequest,
const shared_ptr<ValidationState>& state) {
130 if (certRequest ==
nullptr) {
132 cert.
getName().toUri() +
"` as a trust anchor"});
136 state->addCertificate(cert);
137 requestCertificate(certRequest, state);
143 Validator::requestCertificate(
const shared_ptr<CertificateRequest>& certRequest,
144 const shared_ptr<ValidationState>& state)
147 if (state->getDepth() >= m_maxDepth) {
148 state->fail({ValidationError::Code::EXCEEDED_DEPTH_LIMIT,
149 "Exceeded validation depth limit (" +
to_string(m_maxDepth) +
")"});
154 state->verifyOriginalPacket(nullopt);
158 if (state->hasSeenCertificateName(certRequest->interest.getName())) {
159 state->fail({ValidationError::Code::LOOP_DETECTED,
160 "Validation loop detected for certificate `" + certRequest->interest.getName().toUri() +
"`"});
167 if (cert !=
nullptr) {
170 cert = state->verifyCertificateChain(*cert);
171 if (cert !=
nullptr) {
172 state->verifyOriginalPacket(*cert);
174 for (
auto trustedCert = std::make_move_iterator(state->m_certificateChain.begin());
175 trustedCert != std::make_move_iterator(state->m_certificateChain.end());
182 m_certFetcher->fetch(certRequest, state, [
this] (
const Certificate& cert,
const shared_ptr<ValidationState>& state) {
Represents a Data packet.
const Name & getName() const noexcept
Get name.
Represents an Interest packet.
const Name & getName() const noexcept
optional< SignatureInfo > getSignatureInfo() const
Get the InterestSignatureInfo.
static const Name & getDigestSha256Identity()
A localhost identity to indicate that the signature is generated using SHA-256.
Interface used by the validator to fetch missing certificates.
const Certificate * findTrustedCert(const Interest &interestForCert) const
Find a trusted certificate in trust anchor container or in verified cache.
void loadAnchor(const std::string &groupId, Certificate &&cert)
load static trust anchor.
void resetVerifiedCerts()
Remove any cached verified certificates.
void resetAnchors()
remove any previously loaded static or dynamic trust anchor
void cacheVerifiedCert(Certificate &&cert)
Cache verified certificate a period of time (1 hour)
Represents an NDN certificate following the version 2.0 format.
bool isValid(const time::system_clock::TimePoint &ts=time::system_clock::now()) const
Check if the certificate is valid at ts.
Abstraction that implements validation policy for Data and Interest packets.
Interface for validating data and interest packets.
ValidationPolicy & getPolicy()
void cacheVerifiedCertificate(Certificate &&cert)
Cache verified cert a period of time (1 hour)
void setMaxDepth(size_t depth)
Set the maximum depth of the certificate chain.
size_t getMaxDepth() const
void resetAnchors()
remove any previously loaded static or dynamic trust anchor
CertificateFetcher & getFetcher()
Validator(unique_ptr< ValidationPolicy > policy, unique_ptr< CertificateFetcher > certFetcher)
Validator constructor.
void resetVerifiedCertificates()
Remove any cached verified certificates.
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
void loadAnchor(const std::string &groupId, Certificate &&cert)
load static trust anchor.
#define NDN_LOG_INIT(name)
Define a non-member log module.
std::string to_string(const errinfo_stacktrace &x)
function< void(const Interest &interest, const ValidationError &error)> InterestValidationFailureCallback
Callback to report a failed Interest validation.
function< void(const Data &data)> DataValidationSuccessCallback
Callback to report a successful Data validation.
function< void(const Data &data, const ValidationError &error)> DataValidationFailureCallback
Callback to report a failed Data validation.
function< void(const Interest &interest)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.
@ V03
Sign Interest using Packet Specification v0.3 semantics.
@ V02
Sign Interest using Packet Specification v0.2 semantics.
boost::chrono::nanoseconds nanoseconds
#define NDN_LOG_DEBUG_DEPTH(x)
#define NDN_LOG_TRACE_DEPTH(x)