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 m_policy->checkPolicy(interest, state,
103 [
this] (
const shared_ptr<CertificateRequest>& certRequest,
const shared_ptr<ValidationState>& state) {
104 if (certRequest ==
nullptr) {
105 state->bypassValidation();
109 requestCertificate(certRequest, state);
120 return state->fail({ValidationError::Code::EXPIRED_CERT,
"Retrieved certificate is not yet valid or expired "
121 "`" + cert.
getName().toUri() +
"`"});
124 m_policy->checkPolicy(cert, state,
125 [
this, cert] (
const shared_ptr<CertificateRequest>& certRequest,
const shared_ptr<ValidationState>& state) {
126 if (certRequest ==
nullptr) {
128 cert.
getName().toUri() +
"` as a trust anchor"});
132 state->addCertificate(cert);
133 requestCertificate(certRequest, state);
139 Validator::requestCertificate(
const shared_ptr<CertificateRequest>& certRequest,
140 const shared_ptr<ValidationState>& state)
143 if (state->getDepth() >= m_maxDepth) {
144 state->fail({ValidationError::Code::EXCEEDED_DEPTH_LIMIT,
145 "Exceeded validation depth limit (" +
to_string(m_maxDepth) +
")"});
149 if (state->hasSeenCertificateName(certRequest->interest.getName())) {
150 state->fail({ValidationError::Code::LOOP_DETECTED,
151 "Validation loop detected for certificate `" + certRequest->interest.getName().toUri() +
"`"});
158 if (cert !=
nullptr) {
161 cert = state->verifyCertificateChain(*cert);
162 if (cert !=
nullptr) {
163 state->verifyOriginalPacket(*cert);
165 for (
auto trustedCert = std::make_move_iterator(state->m_certificateChain.begin());
166 trustedCert != std::make_move_iterator(state->m_certificateChain.end());
173 m_certFetcher->fetch(certRequest, state, [
this] (
const Certificate& cert,
const shared_ptr<ValidationState>& state) {
192 time::nanoseconds refreshPeriod,
bool isDir)