All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
validator.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_VALIDATOR_HPP
24 #define NDN_VALIDATOR_HPP
25 
26 #include "certificate-fetcher-offline.hpp"
27 #include "validation-policy.hpp"
28 
29 namespace ndn {
30 
55 class Validator : public CertificateStorage {
56 public:
64  Validator
65  (const ptr_lib::shared_ptr<ValidationPolicy>& policy,
66  const ptr_lib::shared_ptr<CertificateFetcher>& certificateFetcher =
67  ptr_lib::make_shared<CertificateFetcherOffline>());
68 
74  getPolicy() { return *policy_; }
75 
81  getFetcher() { return *certificateFetcher_; }
82 
87  void
88  setMaxDepth(size_t maxDepth) { maxDepth_ = maxDepth; }
89 
94  size_t
95  getMaxDepth() const { return maxDepth_; }
96 
105  void
106  validate
107  (const Data& data, const DataValidationSuccessCallback& successCallback,
108  const DataValidationFailureCallback& failureCallback);
109 
118  void
119  validate
120  (const Interest& interest,
121  const InterestValidationSuccessCallback& successCallback,
122  const InterestValidationFailureCallback& failureCallback);
123 
124 private:
130  void
131  validateCertificate
132  (const ptr_lib::shared_ptr<CertificateV2>& certificate,
133  const ptr_lib::shared_ptr<ValidationState>& state);
134 
140  void
141  requestCertificate
142  (const ptr_lib::shared_ptr<CertificateRequest>& certificateRequest,
143  const ptr_lib::shared_ptr<ValidationState>& state);
144 
148  void
149  continueValidateCertificate
150  (const ptr_lib::shared_ptr<CertificateRequest>& certificateRequest,
151  const ptr_lib::shared_ptr<ValidationState>& state,
152  const ptr_lib::shared_ptr<CertificateV2>& certificate)
153  {
154  if (!certificateRequest)
155  state->fail(ValidationError
156  (ValidationError::POLICY_ERROR,
157  "Validation policy is not allowed to designate `" +
158  certificate->getName().toUri() + "` as a trust anchor"));
159  else {
160  // We need to fetch the key and validate it.
161  state->addCertificate(*certificate);
162  requestCertificate(certificateRequest, state);
163  }
164  }
165 
169  void
170  continueValidate
171  (const ptr_lib::shared_ptr<CertificateRequest>& certificateRequest,
172  const ptr_lib::shared_ptr<ValidationState>& state)
173  {
174  if (!certificateRequest)
175  state->bypassValidation();
176  else
177  // We need to fetch the key and validate it.
178  requestCertificate(certificateRequest, state);
179  }
180 
181  ptr_lib::shared_ptr<ValidationPolicy> policy_;
182  ptr_lib::shared_ptr<CertificateFetcher> certificateFetcher_;
183  size_t maxDepth_;
184 };
185 
186 }
187 
188 #endif
CertificateFetcher & getFetcher()
Get the CertificateFetcher given to (or created in) the constructor.
Definition: validator.hpp:81
func_lib::function< void(const Data &data, const ValidationError &error)> DataValidationFailureCallback
A DataValidationFailureCallback function object is used to report a failed Data validation.
Definition: validation-state.hpp:44
Definition: data.hpp:37
ValidationPolicy is an abstract base class that implements a validation policy for Data and Interest ...
Definition: validation-policy.hpp:41
void setMaxDepth(size_t maxDepth)
Set the maximum depth of the certificate chain.
Definition: validator.hpp:88
void validate(const Data &data, const DataValidationSuccessCallback &successCallback, const DataValidationFailureCallback &failureCallback)
Asynchronously validate the Data packet.
Definition: validator.cpp:52
CertificateFetcher is an abstract base class which provides an interface used by the validator to fet...
Definition: certificate-fetcher.hpp:36
Validator(const ptr_lib::shared_ptr< ValidationPolicy > &policy, const ptr_lib::shared_ptr< CertificateFetcher > &certificateFetcher=ptr_lib::make_shared< CertificateFetcherOffline >())
Create a Validator with the policy and fetcher.
Definition: validator.cpp:35
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
The CertificateStorage class stores trusted anchors and has a verified certificate cache...
Definition: certificate-storage.hpp:35
func_lib::function< void(const Data &data)> DataValidationSuccessCallback
A DataValidationSuccessCallback function object is used to report a successful Data validation...
Definition: validation-state.hpp:37
The Validator class provides an interface for validating data and interest packets.
Definition: validator.hpp:55
func_lib::function< void(const Interest &interest)> InterestValidationSuccessCallback
An InterestValidationSuccessCallback function object is used to report a successful Interest validati...
Definition: validation-state.hpp:51
size_t getMaxDepth() const
Get the maximum depth of the certificate chain.
Definition: validator.hpp:95
ValidationPolicy & getPolicy()
Get the ValidationPolicy given to the constructor.
Definition: validator.hpp:74
A ValidationError holds an error code and an optional detailed error message.
Definition: validation-error.hpp:34
func_lib::function< void(const Interest &interest, const ValidationError &error)> InterestValidationFailureCallback
An InterestValidationFailureCallback function object is used to report a failed Interest validation...
Definition: validation-state.hpp:59