27 #include <ndn-cxx/util/io.hpp>
37 , m_confParam(confParam)
38 , m_validator(m_confParam.getValidator())
40 for (
const auto& certfile : confParam.
getIdCerts()) {
41 std::ifstream ifs(certfile);
42 insert(ndn::io::loadTlv<ndn::security::Certificate>(ifs));
45 registerKeyPrefixes();
48 const auto kl = data.getKeyLocator();
49 if (!kl || kl->getType() != ndn::tlv::Name) {
50 NLSR_LOG_TRACE(
"Cannot determine KeyLocator Name for: " << data.getName());
52 else if (
const auto klName = kl->getName(); !
find(klName)) {
65 m_certificates[certificate.getKeyName()] = certificate;
66 NLSR_LOG_TRACE(
"Certificate inserted successfully\n" << certificate);
69 const ndn::security::Certificate*
72 if (ndn::security::Certificate::isValidName(name)) {
73 return findByCertName(name);
75 return findByKeyName(name);
78 const ndn::security::Certificate*
79 CertificateStore::findByKeyName(
const ndn::Name& keyName)
const
81 auto it = m_certificates.find(keyName);
82 return it != m_certificates.end() ? &it->second :
nullptr;
85 const ndn::security::Certificate*
86 CertificateStore::findByCertName(
const ndn::Name& certName)
const
88 auto found = findByKeyName(ndn::security::extractKeyNameFromCertName(certName));
89 if (found ==
nullptr || found->getName() != certName) {
96 CertificateStore::setInterestFilter(
const ndn::Name& prefix)
98 m_face.setInterestFilter(ndn::InterestFilter(prefix).allowLoopback(
false),
99 std::bind(&CertificateStore::onKeyInterest,
this, _1, _2),
100 std::bind(&CertificateStore::onKeyPrefixRegSuccess,
this, _1),
101 std::bind(&CertificateStore::registrationFailed,
this, _1),
106 CertificateStore::registerKeyPrefixes()
108 std::vector<ndn::Name> prefixes;
112 nlsrKeyPrefix.append(
"nlsr");
113 nlsrKeyPrefix.append(ndn::security::Certificate::KEY_COMPONENT);
114 prefixes.push_back(nlsrKeyPrefix);
118 routerKeyPrefix.append(ndn::security::Certificate::KEY_COMPONENT);
119 prefixes.push_back(routerKeyPrefix);
122 ndn::Name operatorKeyPrefix = m_confParam.
getNetwork();
123 operatorKeyPrefix.append(m_confParam.
getSiteName());
124 operatorKeyPrefix.append(std::string(
"%C1.Operator"));
125 prefixes.push_back(operatorKeyPrefix);
128 ndn::Name siteKeyPrefix = m_confParam.
getNetwork();
130 siteKeyPrefix.append(ndn::security::Certificate::KEY_COMPONENT);
131 prefixes.push_back(siteKeyPrefix);
135 for (
const auto& i : prefixes) {
136 setInterestFilter(i);
141 CertificateStore::onKeyInterest(
const ndn::Name&,
const ndn::Interest& interest)
143 NLSR_LOG_TRACE(
"Got certificate Interest: " << interest.getName());
145 const auto* cert =
find(interest.getName());
147 NLSR_LOG_DEBUG(
"Certificate not found for: " << interest.getName());
155 CertificateStore::onKeyPrefixRegSuccess(
const ndn::Name& name)
161 CertificateStore::registrationFailed(
const ndn::Name& name)
164 NDN_THROW(std::runtime_error(
"Prefix registration failed: " + name.toUri()));
170 const auto* cert = m_validator.getUnverifiedCertCache().find(keyName);
174 ndn::Name certName = ndn::security::extractKeyNameFromCertName(cert->getName());
177 setInterestFilter(certName);
179 const ndn::Name& keyLocatorName = cert->getSignatureInfo().getKeyLocator().getName();
180 if (cert->getKeyName() != keyLocatorName) {
186 NLSR_LOG_TRACE(
"Cert for " << keyName <<
" was not found in the Validator's cache");
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
ndn::signal::Signal< Lsdb, ndn::Data > afterSegmentValidatedSignal
Store certificates for names.
const ndn::security::Certificate * find(const ndn::Name &name) const
Find a certificate.
void insert(const ndn::security::Certificate &certificate)
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.