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) 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,
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,
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,
124 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<
FinalBlockIdTag>();
125 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->
get()) {
126 return m_inner->fetch(certRequest, state, continueValidation);
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,
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()));
170 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
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,
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,
203 const Name& bundleName)
207 m_inner->fetch(certRequest, state, continueValidation);
211 CertificateBundleFetcher::deriveBundleName(
const Name&
name)
215 Name bundleName = name;
227 bundleName.
append(
"_BUNDLE");
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
Copyright (c) 2011-2015 Regents of the University of California.
Represents an NDN certificate following the version 2.0 format.
#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
Returns an immutable reference to the component at the specified index.
void setBundleInterestLifetime(time::milliseconds time)
Set the lifetime of certificate bundle interest.
CertificateStorage * m_certStorage
void parse() const
Parse TLV-VALUE into sub-elements.
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes)
Represents a TLV element of the NDN packet format.
Represents an Interest packet.
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
CertificateBundleFetcher(unique_ptr< CertificateFetcher > inner, Face &face)
Name & appendNumber(uint64_t number)
Append a component with a NonNegativeInteger.
Name & append(const Component &component)
Append a component.
const element_container & elements() const
Get container of sub-elements.
represents a Network Nack
Validation state for a data packet.
NackReason getReason() const
provides a tag type for simple types
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking...
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.
const CertificateCache & getUnverifiedCertCache() const
const Block & get(uint32_t type) const
Return the first sub-element of the specified TLV-TYPE.
NDN_CXX_NODISCARD bool empty() const
Checks if the name is empty, i.e.
Storage for trusted anchors, verified certificate cache, and unverified certificate cache...
bool isSegment() const
Check if the component is a 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.
const Name & getName() const noexcept
Get name.
bool isImplicitSha256Digest() const
Check if the component is an ImplicitSha256DigestComponent.
Represents an absolute name.
PendingInterestHandle expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
size_t size() const
Returns the number of components.
Represents a name component.
const Block & getContent() const noexcept
Get the Content element.
#define NDN_LOG_INIT(name)
declare a log module
Interest & setInterestLifetime(time::milliseconds lifetime)
Set the Interest's lifetime.
Represents a Data packet.
const optional< name::Component > & getFinalBlock() const
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.
boost::chrono::milliseconds milliseconds