36 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x)
37 #define NDN_LOG_TRACE_DEPTH(x) NDN_LOG_TRACE(std::string(state->getDepth() + 1, '>') << " " << x)
41 : m_inner(std::move(inner))
43 , m_bundleInterestLifetime(1000)
45 BOOST_ASSERT(m_inner !=
nullptr);
51 m_bundleInterestLifetime = time;
57 return m_bundleInterestLifetime;
64 m_inner->setCertificateStorage(certStorage);
69 const shared_ptr<ValidationState>& state,
72 auto dataValidationState = dynamic_pointer_cast<DataValidationState>(state);
73 if (dataValidationState ==
nullptr) {
74 return m_inner->fetch(certRequest, state, continueValidation);
78 shared_ptr<BundleNameTag> bundleNameTag = state->getTag<
BundleNameTag>();
79 if (bundleNameTag ==
nullptr) {
80 const Name& originalDataName = dataValidationState->getOriginalData().getName();
81 if (originalDataName.
empty()) {
82 return m_inner->fetch(certRequest, state, continueValidation);
85 Name bundleNamePrefix = deriveBundleName(originalDataName);
86 fetchFirstBundleSegment(bundleNamePrefix, certRequest, state, continueValidation);
89 Name fullBundleName = bundleNameTag->
get();
90 fetchNextBundleSegment(fullBundleName, fullBundleName.
get(-1).
getSuccessor(),
91 certRequest, state, continueValidation);
96 CertificateBundleFetcher::fetchFirstBundleSegment(
const Name& bundleNamePrefix,
97 const shared_ptr<CertificateRequest>& certRequest,
98 const shared_ptr<ValidationState>& state,
99 const ValidationContinuation& continueValidation)
108 dataCallback(data,
true, certRequest, state, continueValidation);
111 nackCallback(nack, certRequest, state, continueValidation, bundleNamePrefix);
114 timeoutCallback(certRequest, state, continueValidation, bundleNamePrefix);
119 CertificateBundleFetcher::fetchNextBundleSegment(
const Name& fullBundleName,
const name::Component& segmentNo,
120 const shared_ptr<CertificateRequest>& certRequest,
121 const shared_ptr<ValidationState>& state,
122 const ValidationContinuation& continueValidation)
124 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<FinalBlockIdTag>();
125 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->get()) {
126 return m_inner->fetch(certRequest, state, continueValidation);
129 Interest bundleInterest(fullBundleName.getPrefix(-1).append(segmentNo));
136 dataCallback(data,
false, certRequest, state, continueValidation);
139 nackCallback(nack, certRequest, state, continueValidation, fullBundleName);
142 timeoutCallback(certRequest, state, continueValidation, fullBundleName);
147 CertificateBundleFetcher::dataCallback(
const Data& bundleData,
148 bool isSegmentZeroExpected,
149 const shared_ptr<CertificateRequest>& certRequest,
150 const shared_ptr<ValidationState>& state,
151 const ValidationContinuation& continueValidation)
155 name::Component currentSegment = bundleData.getName().get(-1);
156 if (!currentSegment.isSegment()) {
157 return m_inner->fetch(certRequest, state, continueValidation);
160 if (isSegmentZeroExpected && currentSegment.toSegment() != 0) {
163 certRequest, state, continueValidation);
166 state->setTag(make_shared<BundleNameTag>(bundleData.getName()));
168 const auto& finalBlockId = bundleData.getFinalBlock();
170 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
173 Block bundleContent = bundleData.getContent();
174 bundleContent.parse();
177 for (
const auto& block : bundleContent.elements()) {
182 continueValidation(*cert, state);
187 CertificateBundleFetcher::nackCallback(
const lp::Nack& nack,
188 const shared_ptr<CertificateRequest>& certRequest,
189 const shared_ptr<ValidationState>& state,
190 const ValidationContinuation& continueValidation,
191 const Name& bundleName)
196 m_inner->fetch(certRequest, state, continueValidation);
200 CertificateBundleFetcher::timeoutCallback(
const shared_ptr<CertificateRequest>& certRequest,
201 const shared_ptr<ValidationState>& state,
202 const ValidationContinuation& continueValidation,
203 const Name& bundleName)
207 m_inner->fetch(certRequest, state, continueValidation);
211 CertificateBundleFetcher::deriveBundleName(
const Name& name)
213 name::Component lastComponent = name.at(-1);
215 Name bundleName = name;
216 if (lastComponent.isImplicitSha256Digest()) {
217 if (name.size() >= 2 && name.get(-2).isSegment()) {
218 bundleName = name.getPrefix(-2);
221 bundleName = name.getPrefix(-1);
224 else if (lastComponent.isSegment()) {
225 bundleName = name.getPrefix(-1);
227 bundleName.append(
"_BUNDLE");
228 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 & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix 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.
void setBundleInterestLifetime(time::milliseconds time)
Set the lifetime of certificate bundle interest.
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.
time::milliseconds getBundleInterestLifetime() const
CertificateBundleFetcher(unique_ptr< CertificateFetcher > inner, Face &face)
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.
const CertificateCache & getUnverifiedCertCache() const
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes).
#define NDN_LOG_INIT(name)
Define a non-member log module.
boost::chrono::milliseconds milliseconds