30 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << ' ' << x)
40 : m_inner(std::move(inner))
43 BOOST_ASSERT(m_inner !=
nullptr);
50 m_inner->setCertificateStorage(certStorage);
55 const shared_ptr<ValidationState>& state,
58 auto dataValidationState = std::dynamic_pointer_cast<DataValidationState>(state);
59 if (dataValidationState ==
nullptr) {
60 return m_inner->fetch(certRequest, state, continueValidation);
64 shared_ptr<BundleNameTag> bundleNameTag = state->getTag<
BundleNameTag>();
65 if (bundleNameTag ==
nullptr) {
66 const Name& originalDataName = dataValidationState->getOriginalData().getName();
67 if (originalDataName.
empty()) {
68 return m_inner->fetch(certRequest, state, continueValidation);
71 Name bundleNamePrefix = deriveBundleName(originalDataName);
72 fetchFirstBundleSegment(bundleNamePrefix, certRequest, state, continueValidation);
75 Name fullBundleName = bundleNameTag->
get();
76 fetchNextBundleSegment(fullBundleName, fullBundleName.
get(-1).
getSuccessor(),
77 certRequest, state, continueValidation);
82 CertificateBundleFetcher::fetchFirstBundleSegment(
const Name& bundleNamePrefix,
83 const shared_ptr<CertificateRequest>& certRequest,
84 const shared_ptr<ValidationState>& state,
85 const ValidationContinuation& continueValidation)
94 dataCallback(data,
true, certRequest, state, continueValidation);
97 nackCallback(nack, certRequest, state, continueValidation, bundleNamePrefix);
100 timeoutCallback(certRequest, state, continueValidation, bundleNamePrefix);
105 CertificateBundleFetcher::fetchNextBundleSegment(
const Name& fullBundleName,
const name::Component& segmentNo,
106 const shared_ptr<CertificateRequest>& certRequest,
107 const shared_ptr<ValidationState>& state,
108 const ValidationContinuation& continueValidation)
110 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<
FinalBlockIdTag>();
111 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->get()) {
112 return m_inner->fetch(certRequest, state, continueValidation);
115 Interest bundleInterest(fullBundleName.getPrefix(-1).append(segmentNo));
122 dataCallback(data,
false, certRequest, state, continueValidation);
125 nackCallback(nack, certRequest, state, continueValidation, fullBundleName);
128 timeoutCallback(certRequest, state, continueValidation, fullBundleName);
133 CertificateBundleFetcher::dataCallback(
const Data& bundleData,
134 bool isSegmentZeroExpected,
135 const shared_ptr<CertificateRequest>& certRequest,
136 const shared_ptr<ValidationState>& state,
137 const ValidationContinuation& continueValidation)
141 name::Component currentSegment = bundleData.getName().get(-1);
142 if (!currentSegment.isSegment()) {
143 return m_inner->fetch(certRequest, state, continueValidation);
146 if (isSegmentZeroExpected && currentSegment.toSegment() != 0) {
149 certRequest, state, continueValidation);
152 state->setTag(make_shared<BundleNameTag>(bundleData.getName()));
154 const auto& finalBlockId = bundleData.getFinalBlock();
156 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
159 Block bundleContent = bundleData.getContent();
160 bundleContent.parse();
163 for (
const auto& block : bundleContent.elements()) {
168 continueValidation(*cert, state);
173 CertificateBundleFetcher::nackCallback(
const lp::Nack& nack,
174 const shared_ptr<CertificateRequest>& certRequest,
175 const shared_ptr<ValidationState>& state,
176 const ValidationContinuation& continueValidation,
177 const Name& bundleName)
182 m_inner->fetch(certRequest, state, continueValidation);
186 CertificateBundleFetcher::timeoutCallback(
const shared_ptr<CertificateRequest>& certRequest,
187 const shared_ptr<ValidationState>& state,
188 const ValidationContinuation& continueValidation,
189 const Name& bundleName)
193 m_inner->fetch(certRequest, state, continueValidation);
197 CertificateBundleFetcher::deriveBundleName(
const Name& name)
199 Name bundleName = name;
200 const auto& lastComponent = name.at(-1);
202 if (lastComponent.isImplicitSha256Digest()) {
203 if (name.size() >= 2 && name.get(-2).isSegment()) {
204 bundleName = name.getPrefix(-2);
207 bundleName = name.getPrefix(-1);
210 else if (lastComponent.isSegment()) {
211 bundleName = name.getPrefix(-1);
214 bundleName.append(
"_BUNDLE");
215 bundleName.appendNumber(0);
#define NDN_LOG_DEBUG_DEPTH(x)
Represents a Data packet.
Provide a communication channel with local or remote NDN forwarder.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express an Interest.
Represents an Interest packet.
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.
Interest & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
Represents an absolute name.
bool empty() const noexcept
Checks if the name is empty, i.e., has no components.
const Component & get(ssize_t i) const noexcept
Returns an immutable reference to the component at the specified index.
Provides a tag type for simple types.
Represents a Network Nack.
static Component fromSegment(uint64_t segmentNo)
Create a segment number component using NDN naming conventions.
Component getSuccessor() const
Get the successor of this name component.
Fetch certificate bundle from the network.
CertificateBundleFetcher(unique_ptr< CertificateFetcher > inner, Face &face)
void doFetch(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Asynchronous certificate fetching implementation.
void setCertificateStorage(CertificateStorage &certStorage) override
Set the storage for this and inner certificate fetcher.
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
CertificateStorage * m_certStorage
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
Storage for trusted anchors, verified certificate cache, and unverified certificate cache.
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes).
const CertificateCache & getUnverifiedCertCache() const
#define NDN_LOG_INIT(name)
Define a non-member log module.
Contains the ndn-cxx security framework.
SimpleTag< name::Component, 1001 > FinalBlockIdTag