32 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x) 33 #define NDN_LOG_TRACE_DEPTH(x) NDN_LOG_TRACE(std::string(state->getDepth() + 1, '>') << " " << x) 37 : m_inner(std::move(inner))
39 , m_bundleInterestLifetime(1000)
41 BOOST_ASSERT(m_inner !=
nullptr);
47 m_bundleInterestLifetime =
time;
53 return m_bundleInterestLifetime;
60 m_inner->setCertificateStorage(certStorage);
65 const shared_ptr<ValidationState>& state,
68 auto dataValidationState = dynamic_pointer_cast<DataValidationState>(state);
69 if (dataValidationState ==
nullptr) {
70 return m_inner->fetch(certRequest, state, continueValidation);
74 shared_ptr<BundleNameTag> bundleNameTag = state->getTag<
BundleNameTag>();
75 if (bundleNameTag ==
nullptr) {
76 const Name& originalDataName = dataValidationState->getOriginalData().getName();
77 if (originalDataName.
empty()) {
78 return m_inner->fetch(certRequest, state, continueValidation);
81 Name bundleNamePrefix = deriveBundleName(originalDataName);
82 fetchFirstBundleSegment(bundleNamePrefix, certRequest, state, continueValidation);
85 Name fullBundleName = bundleNameTag->
get();
86 fetchNextBundleSegment(fullBundleName, fullBundleName.
get(-1).
getSuccessor(),
87 certRequest, state, continueValidation);
92 CertificateBundleFetcher::fetchFirstBundleSegment(
const Name& bundleNamePrefix,
93 const shared_ptr<CertificateRequest>& certRequest,
94 const shared_ptr<ValidationState>& state,
95 const ValidationContinuation& continueValidation)
104 dataCallback(data,
true, certRequest, state, continueValidation);
107 nackCallback(nack, certRequest, state, continueValidation, bundleNamePrefix);
110 timeoutCallback(certRequest, state, continueValidation, bundleNamePrefix);
115 CertificateBundleFetcher::fetchNextBundleSegment(
const Name& fullBundleName,
const name::Component& segmentNo,
116 const shared_ptr<CertificateRequest>& certRequest,
117 const shared_ptr<ValidationState>& state,
118 const ValidationContinuation& continueValidation)
120 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<FinalBlockIdTag>();
121 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->get()) {
122 return m_inner->fetch(certRequest, state, continueValidation);
125 Interest bundleInterest(fullBundleName.getPrefix(-1).append(segmentNo));
132 dataCallback(data,
false, certRequest, state, continueValidation);
135 nackCallback(nack, certRequest, state, continueValidation, fullBundleName);
138 timeoutCallback(certRequest, state, continueValidation, fullBundleName);
143 CertificateBundleFetcher::dataCallback(
const Data& bundleData,
144 bool isSegmentZeroExpected,
145 const shared_ptr<CertificateRequest>& certRequest,
146 const shared_ptr<ValidationState>& state,
147 const ValidationContinuation& continueValidation)
152 if (!currentSegment.isSegment()) {
153 return m_inner->fetch(certRequest, state, continueValidation);
156 if (isSegmentZeroExpected && currentSegment.toSegment() != 0) {
159 certRequest, state, continueValidation);
162 state->setTag(make_shared<BundleNameTag>(bundleData.getName()));
164 const auto& finalBlockId = bundleData.getFinalBlock();
166 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
169 Block bundleContent = bundleData.getContent();
170 bundleContent.parse();
173 for (
const auto& block : bundleContent.elements()) {
178 continueValidation(*cert, state);
183 CertificateBundleFetcher::nackCallback(
const lp::Nack& nack,
184 const shared_ptr<CertificateRequest>& certRequest,
185 const shared_ptr<ValidationState>& state,
186 const ValidationContinuation& continueValidation,
187 const Name& bundleName)
192 m_inner->fetch(certRequest, state, continueValidation);
196 CertificateBundleFetcher::timeoutCallback(
const shared_ptr<CertificateRequest>& certRequest,
197 const shared_ptr<ValidationState>& state,
198 const ValidationContinuation& continueValidation,
199 const Name& bundleName)
203 m_inner->fetch(certRequest, state, continueValidation);
207 CertificateBundleFetcher::deriveBundleName(
const Name&
name)
213 if (
name.size() >= 2 &&
name.get(-2).isSegment()) {
214 bundleName =
name.getPrefix(-2);
217 bundleName =
name.getPrefix(-1);
221 bundleName =
name.getPrefix(-1);
223 bundleName.append(
"_BUNDLE");
224 bundleName.appendNumber(00);
Copyright (c) 2011-2015 Regents of the University of California.
#define NDN_LOG_DEBUG_DEPTH(x)
Interest & setMustBeFresh(bool mustBeFresh)
Add or remove MustBeFresh element.
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
const Component & get(ssize_t i) const
Get the component at the given index.
void setBundleInterestLifetime(time::milliseconds time)
Set the lifetime of certificate bundle interest.
CertificateStorage * m_certStorage
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes)
Represents an Interest packet.
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
CertificateBundleFetcher(unique_ptr< CertificateFetcher > inner, Face &face)
represents a Network Nack
NackReason getReason() const
provides a tag type for simple types
static Component fromSegment(uint64_t segmentNo)
Create segment number component using NDN naming conventions.
Component getSuccessor() const
Get the successor of this name component.
const CertificateCache & getUnverifiedCertCache() const
const Block & get(uint32_t type) const
Get the first sub element of specified TLV-TYPE.
constexpr const T & get() const noexcept
Storage for trusted anchors, verified certificate cache, and unverified certificate cache.
bool isSegment() const
Check if the component is segment number per NDN naming conventions.
Provide a communication channel with local or remote NDN forwarder.
void doFetch(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation) override
Asynchronous certificate fetching implementation.
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
Represents an absolute name.
Fetch certificate bundle from the network.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
Represents a name component.
bool empty() const
Check if name is empty.
#define NDN_LOG_INIT(name)
declare a log module
Interest & setInterestLifetime(time::milliseconds lifetime)
Set Interest's lifetime.
Represents a Data packet.
void setCertificateStorage(CertificateStorage &certStorage) override
Set the storage for this and inner certificate fetcher.
time::milliseconds getBundleInterestLifetime() const
Interest & setCanBePrefix(bool canBePrefix)
Add or remove CanBePrefix element.