blob: 717a3f1e00e07d699ad1400a3bb52499600f8fa2 [file] [log] [blame]
Alexander Afanasyev7bc10fa2017-01-13 16:56:26 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande3e39a4d2018-08-30 16:49:13 -05002/*
Davide Pesavento25d4f1c2020-04-29 23:31:04 -04003 * Copyright (c) 2013-2020 Regents of the University of California.
Alexander Afanasyev7bc10fa2017-01-13 16:56:26 -08004 *
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
Davide Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/security/v2/certificate-fetcher.hpp"
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040023#include "ndn-cxx/security/v2/certificate-request.hpp"
24#include "ndn-cxx/security/v2/certificate-storage.hpp"
25#include "ndn-cxx/security/v2/validation-state.hpp"
Davide Pesavento7e780642018-11-24 15:51:34 -050026#include "ndn-cxx/util/logger.hpp"
Alexander Afanasyev7bc10fa2017-01-13 16:56:26 -080027
28namespace ndn {
29namespace security {
30namespace v2 {
31
32NDN_LOG_INIT(ndn.security.v2.CertificateFetcher);
33
34#define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x)
35
36CertificateFetcher::CertificateFetcher()
37 : m_certStorage(nullptr)
38{
39}
40
41CertificateFetcher::~CertificateFetcher() = default;
42
43void
44CertificateFetcher::setCertificateStorage(CertificateStorage& certStorage)
45{
46 m_certStorage = &certStorage;
47}
48
49void
50CertificateFetcher::fetch(const shared_ptr<CertificateRequest>& certRequest,
51 const shared_ptr<ValidationState>& state,
52 const ValidationContinuation& continueValidation)
53{
54 BOOST_ASSERT(m_certStorage != nullptr);
Ashlesh Gawande3e39a4d2018-08-30 16:49:13 -050055 auto cert = m_certStorage->getUnverifiedCertCache().find(certRequest->interest);
Alexander Afanasyev7bc10fa2017-01-13 16:56:26 -080056 if (cert != nullptr) {
57 NDN_LOG_DEBUG_DEPTH("Found certificate in **un**verified key cache " << cert->getName());
58 continueValidation(*cert, state);
59 return;
60 }
Davide Pesavento25d4f1c2020-04-29 23:31:04 -040061
Alexander Afanasyev7bc10fa2017-01-13 16:56:26 -080062 doFetch(certRequest, state,
63 [continueValidation, this] (const Certificate& cert, const shared_ptr<ValidationState>& state) {
64 m_certStorage->cacheUnverifiedCert(Certificate(cert));
65 continueValidation(cert, state);
66 });
67}
68
69} // namespace v2
70} // namespace security
71} // namespace ndn