validation-state.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_VALIDATION_STATE_HPP
23 #define NDN_CXX_SECURITY_VALIDATION_STATE_HPP
24 
30 
31 #include <list>
32 #include <unordered_set>
33 #include <boost/logic/tribool.hpp>
34 
35 namespace ndn::security {
36 
37 class Validator;
38 
57 class ValidationState : public TagHost, noncopyable
58 {
59 public:
60  virtual
62 
63  boost::logic::tribool
64  getOutcome() const noexcept
65  {
66  return m_outcome;
67  }
68 
72  virtual void
73  fail(const ValidationError& error) = 0;
74 
78  size_t
79  getDepth() const noexcept
80  {
81  return m_certificateChain.size();
82  }
83 
87  bool
88  hasSeenCertificateName(const Name& certName);
89 
100  void
101  addCertificate(const Certificate& cert);
102 
103 private: // Interface intended to be used only by Validator class
111  virtual void
112  verifyOriginalPacket(const std::optional<Certificate>& trustedCert) = 0;
113 
117  virtual void
118  bypassValidation() = 0;
119 
134  const Certificate*
135  verifyCertificateChain(const Certificate& trustedCert);
136 
137 protected:
138  boost::logic::tribool m_outcome{boost::logic::indeterminate};
139 
140 private:
141  std::unordered_set<Name> m_seenCertificateNames;
142 
149  std::list<Certificate> m_certificateChain;
150 
151  friend Validator;
152 };
153 
158 {
159 public:
166  DataValidationState(const Data& data,
167  const DataValidationSuccessCallback& successCb,
168  const DataValidationFailureCallback& failureCb);
169 
176  ~DataValidationState() final;
177 
178  void
179  fail(const ValidationError& error) final;
180 
184  const Data&
186  {
187  return m_data;
188  }
189 
190 private:
191  void
192  verifyOriginalPacket(const std::optional<Certificate>& trustedCert) final;
193 
194  void
195  bypassValidation() final;
196 
197 private:
198  Data m_data;
199  DataValidationSuccessCallback m_successCb;
200  DataValidationFailureCallback m_failureCb;
201 };
202 
207 {
208 public:
215  InterestValidationState(const Interest& interest,
216  const InterestValidationSuccessCallback& successCb,
217  const InterestValidationFailureCallback& failureCb);
218 
225  ~InterestValidationState() final;
226 
227  void
228  fail(const ValidationError& error) final;
229 
233  const Interest&
235  {
236  return m_interest;
237  }
238 
239 public:
241 
242 private:
243  void
244  verifyOriginalPacket(const std::optional<Certificate>& trustedCert) final;
245 
246  void
247  bypassValidation() final;
248 
249 private:
250  Interest m_interest;
253 };
254 
256 
257 } // namespace ndn::security
258 
259 #endif // NDN_CXX_SECURITY_VALIDATION_STATE_HPP
Represents a Data packet.
Definition: data.hpp:39
Represents an Interest packet.
Definition: interest.hpp:50
Represents an absolute name.
Definition: name.hpp:45
Provides a tag type for simple types.
Definition: tag.hpp:56
Base class to store tag information, e.g., inside Interest and Data packets.
Definition: tag-host.hpp:37
Represents an NDN certificate.
Definition: certificate.hpp:58
Validation state for a data packet.
DataValidationState(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Create validation state for data.
void fail(const ValidationError &error) final
Call the failure callback.
Validation state for an interest packet.
const Interest & getOriginalInterest() const
signal::Signal< InterestValidationState, Interest > afterSuccess
Validation error code and optional detailed error message.
size_t getDepth() const noexcept
boost::logic::tribool getOutcome() const noexcept
bool hasSeenCertificateName(const Name &certName)
Check if certName has been previously seen and record the supplied name.
virtual void fail(const ValidationError &error)=0
Call the failure callback.
void addCertificate(const Certificate &cert)
Add cert to the top of the certificate chain.
Interface for validating data and interest packets.
Definition: validator.hpp:61
Provides a lightweight signal / event system.
Definition: signal.hpp:51
Contains the ndn-cxx security framework.
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.