validator.hpp
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 
22 #ifndef NDN_CXX_SECURITY_VALIDATOR_HPP
23 #define NDN_CXX_SECURITY_VALIDATOR_HPP
24 
31 
32 namespace ndn {
33 
34 class Face;
35 
36 namespace security {
37 
61 {
62 public:
69  Validator(unique_ptr<ValidationPolicy> policy, unique_ptr<CertificateFetcher> certFetcher);
70 
71  ~Validator() noexcept;
72 
74  getPolicy() const noexcept
75  {
76  return *m_policy;
77  }
78 
80  getFetcher() const noexcept
81  {
82  return *m_certFetcher;
83  }
84 
88  size_t
89  getMaxDepth() const noexcept
90  {
91  return m_maxDepth;
92  }
93 
97  void
98  setMaxDepth(size_t depth) noexcept
99  {
100  m_maxDepth = depth;
101  }
102 
108  void
109  validate(const Data& data,
110  const DataValidationSuccessCallback& successCb,
111  const DataValidationFailureCallback& failureCb);
112 
118  void
119  validate(const Interest& interest,
120  const InterestValidationSuccessCallback& successCb,
121  const InterestValidationFailureCallback& failureCb);
122 
123 public: // anchor management
132  void
133  loadAnchor(const std::string& groupId, Certificate&& cert);
134 
146  void
147  loadAnchor(const std::string& groupId, const std::string& certfilePath,
148  time::nanoseconds refreshPeriod, bool isDir = false);
149 
153  void
154  resetAnchors();
155 
161  void
163 
167  void
169 
170 private: // Common validator operations
177  void
178  validate(const Certificate& cert, const shared_ptr<ValidationState>& state);
179 
186  void
187  continueValidation(const shared_ptr<CertificateRequest>& certRequest,
188  const shared_ptr<ValidationState>& state);
189 
196  void
197  requestCertificate(const shared_ptr<CertificateRequest>& certRequest,
198  const shared_ptr<ValidationState>& state);
199 
200 private:
201  unique_ptr<ValidationPolicy> m_policy;
202  unique_ptr<CertificateFetcher> m_certFetcher;
203  size_t m_maxDepth{25};
204 };
205 
206 } // namespace security
207 } // namespace ndn
208 
209 #endif // NDN_CXX_SECURITY_VALIDATOR_HPP
Represents a Data packet.
Definition: data.hpp:39
Represents an Interest packet.
Definition: interest.hpp:50
Interface used by the validator to fetch missing certificates.
Storage for trusted anchors, verified certificate cache, and unverified certificate cache.
Represents an NDN certificate.
Definition: certificate.hpp:58
Abstraction that implements a validation policy for Interest and Data packets.
Interface for validating data and interest packets.
Definition: validator.hpp:61
void setMaxDepth(size_t depth) noexcept
Set the maximum depth of the certificate chain.
Definition: validator.hpp:98
void cacheVerifiedCertificate(Certificate &&cert)
Cache verified cert a period of time (1 hour).
Definition: validator.cpp:188
ValidationPolicy & getPolicy() const noexcept
Definition: validator.hpp:74
void loadAnchor(const std::string &groupId, Certificate &&cert)
Load static trust anchor.
Definition: validator.cpp:169
CertificateFetcher & getFetcher() const noexcept
Definition: validator.hpp:80
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
Definition: validator.cpp:47
size_t getMaxDepth() const noexcept
Return the maximum depth of the certificate chain.
Definition: validator.hpp:89
void resetVerifiedCertificates()
Remove any cached verified certificates.
Definition: validator.cpp:194
void resetAnchors()
Remove any previously loaded static or dynamic trust anchor.
Definition: validator.cpp:182
Validator(unique_ptr< ValidationPolicy > policy, unique_ptr< CertificateFetcher > certFetcher)
Validator constructor.
Definition: validator.cpp:34
std::function< void(const Interest &)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.
std::function< void(const Interest &, const ValidationError &)> InterestValidationFailureCallback
Callback to report a failed Interest validation.
std::function< void(const Data &)> DataValidationSuccessCallback
Callback to report a successful Data validation.
std::function< void(const Data &, const ValidationError &)> DataValidationFailureCallback
Callback to report a failed Data validation.
::boost::chrono::nanoseconds nanoseconds
Definition: time.hpp:54
Definition: data.cpp:25