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) 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,
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,
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,
120 shared_ptr<FinalBlockIdTag> finalBlockId = state->getTag<
FinalBlockIdTag>();
121 if (finalBlockId !=
nullptr && segmentNo > finalBlockId->
get()) {
122 return m_inner->fetch(certRequest, state, continueValidation);
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,
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()));
166 state->setTag(make_shared<FinalBlockIdTag>(*finalBlockId));
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,
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,
199 const Name& bundleName)
203 m_inner->fetch(certRequest, state, continueValidation);
207 CertificateBundleFetcher::deriveBundleName(
const Name& name)
211 Name bundleName = name;
223 bundleName.
append(
"_BUNDLE");
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
The certificate following the certificate format naming convention.
const Name & getName() const
Get name.
#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 Block & getContent() const
Get Content.
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 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)
#define NDN_LOG_INIT(name)
Define a non-member log module.
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 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.
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.
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.
size_t size() const
Returns the number of components.
Represents a name component.
bool empty() const
Checks if the name is empty, i.e.
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.