certificate-fetcher.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
26 #include "ndn-cxx/util/logger.hpp"
27 
28 namespace ndn::security {
29 
31 
32 #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x)
33 
35  : m_certStorage(nullptr)
36 {
37 }
38 
40 
41 void
43 {
44  m_certStorage = &certStorage;
45 }
46 
47 void
48 CertificateFetcher::fetch(const shared_ptr<CertificateRequest>& certRequest,
49  const shared_ptr<ValidationState>& state,
50  const ValidationContinuation& continueValidation)
51 {
52  BOOST_ASSERT(m_certStorage != nullptr);
53  auto cert = m_certStorage->getUnverifiedCertCache().find(certRequest->interest);
54  if (cert != nullptr) {
55  NDN_LOG_DEBUG_DEPTH("Found certificate in **un**verified key cache " << cert->getName());
56  continueValidation(*cert, state);
57  return;
58  }
59 
60  doFetch(certRequest, state,
61  [continueValidation, this] (const Certificate& cert, const shared_ptr<ValidationState>& state) {
63  continueValidation(cert, state);
64  });
65 }
66 
67 } // namespace ndn::security
#define NDN_LOG_DEBUG_DEPTH(x)
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
Interface used by the validator to fetch missing certificates.
virtual void setCertificateStorage(CertificateStorage &certStorage)
Assign certificate storage to check known certificate and to cache unverified ones.
void fetch(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Asynchronously fetch certificate.
std::function< void(const Certificate &cert, const shared_ptr< ValidationState > &state)> ValidationContinuation
Storage for trusted anchors, verified certificate cache, and unverified certificate cache.
void cacheUnverifiedCert(Certificate &&cert)
Cache unverified certificate for a period of time (5 minutes).
const CertificateCache & getUnverifiedCertCache() const
Represents an NDN certificate.
Definition: certificate.hpp:58
#define NDN_LOG_INIT(name)
Define a non-member log module.
Definition: logger.hpp:169
Contains the ndn-cxx security framework.
Definition: data.cpp:25