26 #include <ndn-cxx/util/io.hpp>
35 , m_confParam(confParam)
37 , m_validator(m_confParam.getValidator())
38 , m_afterSegmentValidatedConnection(m_lsdb.afterSegmentValidatedSignal.connect(
43 auto idCert = ndn::io::load<ndn::security::Certificate>(x);
47 registerKeyPrefixes();
53 m_certificates[certificate.getKeyName()] = certificate;
57 const ndn::security::Certificate*
60 auto it = m_certificates.find(keyName);
61 return it != m_certificates.end() ? &it->second :
nullptr;
65 CertificateStore::clear()
67 m_certificates.clear();
71 CertificateStore::setInterestFilter(
const ndn::Name& prefix,
bool loopback)
73 m_face.setInterestFilter(ndn::InterestFilter(prefix).allowLoopback(loopback),
74 std::bind(&CertificateStore::onKeyInterest,
this, _1, _2),
75 std::bind(&CertificateStore::onKeyPrefixRegSuccess,
this, _1),
76 std::bind(&CertificateStore::registrationFailed,
this, _1),
81 CertificateStore::registerKeyPrefixes()
83 std::vector<ndn::Name> prefixes;
87 nlsrKeyPrefix.append(
"nlsr");
88 nlsrKeyPrefix.append(ndn::security::Certificate::KEY_COMPONENT);
89 prefixes.push_back(nlsrKeyPrefix);
93 routerKeyPrefix.append(ndn::security::Certificate::KEY_COMPONENT);
94 prefixes.push_back(routerKeyPrefix);
97 ndn::Name operatorKeyPrefix = m_confParam.
getNetwork();
98 operatorKeyPrefix.append(m_confParam.
getSiteName());
99 operatorKeyPrefix.append(std::string(
"%C1.Operator"));
100 prefixes.push_back(operatorKeyPrefix);
103 ndn::Name siteKeyPrefix = m_confParam.
getNetwork();
105 siteKeyPrefix.append(ndn::security::Certificate::KEY_COMPONENT);
106 prefixes.push_back(siteKeyPrefix);
110 for (
const auto& i : prefixes) {
111 setInterestFilter(i);
116 CertificateStore::onKeyInterest(
const ndn::Name& name,
const ndn::Interest& interest)
118 NLSR_LOG_DEBUG(
"Got interest for certificate. Interest: " << interest.getName());
120 const auto* cert =
find(interest.getName());
130 CertificateStore::onKeyPrefixRegSuccess(
const ndn::Name& name)
132 NLSR_LOG_DEBUG(
"KEY prefix: " << name <<
" registration is successful");
136 CertificateStore::registrationFailed(
const ndn::Name& name)
139 NDN_THROW(std::runtime_error(
"Prefix registration failed"));
145 const auto* cert = m_validator.getUnverifiedCertCache().find(keyName);
150 ndn::Name certName = ndn::security::extractKeyNameFromCertName(cert->getName());
153 setInterestFilter(certName);
155 const ndn::Name& keyLocatorName = cert->getSignatureInfo().getKeyLocator().getName();
156 if (cert->getKeyName() != keyLocatorName) {
162 NLSR_LOG_TRACE(
"Cert for " << keyName <<
" was not found in the Validator's cache. ");
169 const auto keyName = lsaSegment.getSignatureInfo().getKeyLocator().getName();
170 if (!
find(keyName)) {
175 NLSR_LOG_TRACE(
"Certificate is already in the store: " << keyName);
A class to house all the configuration parameters for NLSR.
const ndn::security::SigningInfo & getSigningInfo() const
const ndn::Name & getSiteName() const
const std::unordered_set< std::string > & getIdCerts() const
const ndn::Name & getNetwork() const
const ndn::Name & getRouterPrefix() const
Store certificates for names.
void insert(const ndn::security::Certificate &certificate)
const ndn::security::Certificate * find(const ndn::Name &keyName) const
Find a certificate.
void afterFetcherSignalEmitted(const ndn::Data &lsaSegment)
CertificateStore(ndn::Face &face, ConfParameter &confParam, Lsdb &lsdb)
void publishCertFromCache(const ndn::Name &keyName)
Retrieves the chain of certificates from Validator's cache and store them in Nlsr's own CertificateSt...
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California.
#define NLSR_LOG_DEBUG(x)
#define INIT_LOGGER(name)
#define NLSR_LOG_ERROR(x)
#define NLSR_LOG_TRACE(x)
Copyright (c) 2014-2020, The University of Memphis, Regents of the University of California,...