Alexander Afanasyev | 7bc10fa | 2017-01-13 16:56:26 -0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2017 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 | |
| 22 | #include "certificate-fetcher.hpp" |
| 23 | #include "util/logger.hpp" |
| 24 | |
| 25 | namespace ndn { |
| 26 | namespace security { |
| 27 | namespace v2 { |
| 28 | |
| 29 | NDN_LOG_INIT(ndn.security.v2.CertificateFetcher); |
| 30 | |
| 31 | #define NDN_LOG_DEBUG_DEPTH(x) NDN_LOG_DEBUG(std::string(state->getDepth() + 1, '>') << " " << x) |
| 32 | |
| 33 | CertificateFetcher::CertificateFetcher() |
| 34 | : m_certStorage(nullptr) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | CertificateFetcher::~CertificateFetcher() = default; |
| 39 | |
| 40 | void |
| 41 | CertificateFetcher::setCertificateStorage(CertificateStorage& certStorage) |
| 42 | { |
| 43 | m_certStorage = &certStorage; |
| 44 | } |
| 45 | |
| 46 | void |
| 47 | CertificateFetcher::fetch(const shared_ptr<CertificateRequest>& certRequest, |
| 48 | const shared_ptr<ValidationState>& state, |
| 49 | const ValidationContinuation& continueValidation) |
| 50 | { |
| 51 | BOOST_ASSERT(m_certStorage != nullptr); |
| 52 | auto cert = m_certStorage->getUnverifiedCertCache().find(certRequest->m_interest); |
| 53 | if (cert != nullptr) { |
| 54 | NDN_LOG_DEBUG_DEPTH("Found certificate in **un**verified key cache " << cert->getName()); |
| 55 | continueValidation(*cert, state); |
| 56 | return; |
| 57 | } |
| 58 | doFetch(certRequest, state, |
| 59 | [continueValidation, this] (const Certificate& cert, const shared_ptr<ValidationState>& state) { |
| 60 | m_certStorage->cacheUnverifiedCert(Certificate(cert)); |
| 61 | continueValidation(cert, state); |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | } // namespace v2 |
| 66 | } // namespace security |
| 67 | } // namespace ndn |