blob: cf8bb358aa44ce0628a1f580b2c13e719f97b1db [file] [log] [blame]
Yumin Xiafa2bce72017-04-09 16:20:25 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev60514ec2020-06-03 14:18:53 -04002/*
3 * Copyright (c) 2014-2020, Regents of the University of California.
Yumin Xiafa2bce72017-04-09 16:20:25 -07004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NDNS_VALIDATOR_CERTIFICATE_FETCHER_NDNS_APPCERT_HPP
21#define NDNS_VALIDATOR_CERTIFICATE_FETCHER_NDNS_APPCERT_HPP
22
23#include <ndn-cxx/ims/in-memory-storage.hpp>
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040024#include <ndn-cxx/security/validator.hpp>
Yumin Xiafa2bce72017-04-09 16:20:25 -070025
26namespace ndn {
27namespace ndns {
28
29/**
30 * @brief Fetch NDNS-stored application certificate(APPCERT type record)
31 * By an iterative-query process, it will retrieve the record, execute authentications,
32 * and de-encapsulate record to get application's certificate.
33 */
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040034class CertificateFetcherAppCert : public security::CertificateFetcher
Yumin Xiafa2bce72017-04-09 16:20:25 -070035{
36public:
37 explicit
38 CertificateFetcherAppCert(Face& face,
39 size_t nsCacheSize = 500,
40 size_t startComponentIndex = 0);
41
42protected:
43 /**
44 * @brief retrive appcert record, validate, and de-encapsulate
45 * This method will first retrive the record by an iterative query.
46 * Then it will pass it to validator.
47 * If validated, de-encapsulate and call continueValidation.
48 */
49 void
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040050 doFetch(const shared_ptr<security::CertificateRequest>& certRequest,
51 const shared_ptr<security::ValidationState>& state,
Yumin Xiafa2bce72017-04-09 16:20:25 -070052 const ValidationContinuation& continueValidation) override;
53
54private:
55 /**
56 * @brief Callback invoked when rrset is retrived, including nack
57 */
58 void
59 onQuerySuccessCallback(const Data& data,
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040060 const shared_ptr<security::CertificateRequest>& certRequest,
61 const shared_ptr<security::ValidationState>& state,
Yumin Xiafa2bce72017-04-09 16:20:25 -070062 const ValidationContinuation& continueValidation);
63
64 /**
65 * @brief Callback invoked when iterative query failed
66 *
67 * @todo retry for some amount of time
68 */
69 void
70 onQueryFailCallback(const std::string& errMsg,
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040071 const shared_ptr<security::CertificateRequest>& certRequest,
72 const shared_ptr<security::ValidationState>& state,
Yumin Xiafa2bce72017-04-09 16:20:25 -070073 const ValidationContinuation& continueValidation);
74
75 /**
76 * @brief Callback invoked when rrset validation succeeded
77 */
78 void
79 onValidationSuccessCallback(const Data& data,
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040080 const shared_ptr<security::CertificateRequest>& certRequest,
81 const shared_ptr<security::ValidationState>& state,
Yumin Xiafa2bce72017-04-09 16:20:25 -070082 const ValidationContinuation& continueValidation);
83
84 /**
85 * @brief Callback invoked when rrset validation failed
86 */
87 void
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040088 onValidationFailCallback(const security::ValidationError& err,
89 const shared_ptr<security::CertificateRequest>& certRequest,
90 const shared_ptr<security::ValidationState>& state,
Yumin Xiafa2bce72017-04-09 16:20:25 -070091 const ValidationContinuation& continueValidation);
92
93private:
94 Face& m_face;
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040095 unique_ptr<security::Validator> m_validator;
Yumin Xiafa2bce72017-04-09 16:20:25 -070096 InMemoryStorage* m_nsCache;
97 size_t m_startComponentIndex;
98};
99
100} // namespace ndns
101} // namespace ndn
102
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400103#endif // NDNS_VALIDATOR_CERTIFICATE_FETCHER_NDNS_APPCERT_HPP