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-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 #ifndef NDN_SECURITY_V2_VALIDATOR_HPP
23 #define NDN_SECURITY_V2_VALIDATOR_HPP
24 
25 #include "certificate-fetcher.hpp"
26 #include "certificate-request.hpp"
27 #include "certificate-storage.hpp"
28 #include "validation-callback.hpp"
29 #include "validation-policy.hpp"
30 #include "validation-state.hpp"
31 
32 namespace ndn {
33 
34 class Face;
35 
36 namespace security {
37 namespace v2 {
38 
62 {
63 public:
70  Validator(unique_ptr<ValidationPolicy> policy, unique_ptr<CertificateFetcher> certFetcher);
71 
72  ~Validator();
73 
75  getPolicy();
76 
78  getFetcher();
79 
83  void
84  setMaxDepth(size_t depth);
85 
89  size_t
90  getMaxDepth() const;
91 
97  void
98  validate(const Data& data,
99  const DataValidationSuccessCallback& successCb,
100  const DataValidationFailureCallback& failureCb);
101 
107  void
108  validate(const Interest& interest,
109  const InterestValidationSuccessCallback& successCb,
110  const InterestValidationFailureCallback& failureCb);
111 
112 public: // anchor management
121  void
122  loadAnchor(const std::string& groupId, Certificate&& cert);
123 
135  void
136  loadAnchor(const std::string& groupId, const std::string& certfilePath,
137  time::nanoseconds refreshPeriod, bool isDir = false);
138 
142  void
143  resetAnchors();
144 
150  void
152 
156  void
158 
159 private: // Common validator operations
166  void
167  validate(const Certificate& cert, const shared_ptr<ValidationState>& state);
168 
175  void
176  requestCertificate(const shared_ptr<CertificateRequest>& certRequest,
177  const shared_ptr<ValidationState>& state);
178 
179 private:
180  unique_ptr<ValidationPolicy> m_policy;
181  unique_ptr<CertificateFetcher> m_certFetcher;
182  size_t m_maxDepth;
183 };
184 
185 } // namespace v2
186 } // namespace security
187 } // namespace ndn
188 
189 #endif // NDN_SECURITY_V2_VALIDATOR_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
The certificate following the certificate format naming convention.
Definition: certificate.hpp:81
function< void(const Data &data)> DataValidationSuccessCallback
Callback to report a successful Data validation.
Interface used by the validator to fetch missing certificates.
void cacheVerifiedCertificate(Certificate &&cert)
Cache verified cert a period of time (1 hour)
Definition: validator.cpp:204
Represents an Interest packet.
Definition: interest.hpp:42
function< void(const Data &data, const ValidationError &error)> DataValidationFailureCallback
Callback to report a failed Data validation.
void setMaxDepth(size_t depth)
Set the maximum depth of the certificate chain.
Definition: validator.cpp:63
Abstraction that implements validation policy for Data and Interest packets.
CertificateFetcher & getFetcher()
Definition: validator.cpp:57
ValidationPolicy & getPolicy()
Definition: validator.cpp:51
Storage for trusted anchors, verified certificate cache, and unverified certificate cache...
void validate(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Asynchronously validate data.
Definition: validator.cpp:75
void loadAnchor(const std::string &groupId, Certificate &&cert)
load static trust anchor.
Definition: validator.cpp:185
size_t getMaxDepth() const
Definition: validator.cpp:69
void resetVerifiedCertificates()
Remove any cached verified certificates.
Definition: validator.cpp:210
Validator(unique_ptr< ValidationPolicy > policy, unique_ptr< CertificateFetcher > certFetcher)
Validator constructor.
Definition: validator.cpp:37
function< void(const Interest &interest, const ValidationError &error)> InterestValidationFailureCallback
Callback to report a failed Interest validation.
void resetAnchors()
remove any previously loaded static or dynamic trust anchor
Definition: validator.cpp:198
Represents a Data packet.
Definition: data.hpp:35
function< void(const Interest &interest)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.
Interface for validating data and interest packets.
Definition: validator.hpp:61