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-2022 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 
29 #include "ndn-cxx/util/signal.hpp"
30 
31 #include <list>
32 #include <unordered_set>
33 #include <boost/logic/tribool.hpp>
34 
35 namespace ndn {
36 namespace security {
37 inline namespace v2 {
38 
39 class Validator;
40 
59 class ValidationState : public TagHost, noncopyable
60 {
61 public:
62  virtual
64 
65  boost::logic::tribool
66  getOutcome() const noexcept
67  {
68  return m_outcome;
69  }
70 
74  virtual void
75  fail(const ValidationError& error) = 0;
76 
80  size_t
81  getDepth() const noexcept
82  {
83  return m_certificateChain.size();
84  }
85 
89  bool
90  hasSeenCertificateName(const Name& certName);
91 
102  void
103  addCertificate(const Certificate& cert);
104 
105 private: // Interface intended to be used only by Validator class
113  virtual void
114  verifyOriginalPacket(const optional<Certificate>& trustedCert) = 0;
115 
119  virtual void
120  bypassValidation() = 0;
121 
136  const Certificate*
137  verifyCertificateChain(const Certificate& trustedCert);
138 
139 protected:
140  boost::logic::tribool m_outcome{boost::logic::indeterminate};
141 
142 private:
143  std::unordered_set<Name> m_seenCertificateNames;
144 
151  std::list<Certificate> m_certificateChain;
152 
153  friend Validator;
154 };
155 
160 {
161 public:
168  DataValidationState(const Data& data,
169  const DataValidationSuccessCallback& successCb,
170  const DataValidationFailureCallback& failureCb);
171 
178  ~DataValidationState() final;
179 
180  void
181  fail(const ValidationError& error) final;
182 
186  const Data&
188  {
189  return m_data;
190  }
191 
192 private:
193  void
194  verifyOriginalPacket(const optional<Certificate>& trustedCert) final;
195 
196  void
197  bypassValidation() final;
198 
199 private:
200  Data m_data;
201  DataValidationSuccessCallback m_successCb;
202  DataValidationFailureCallback m_failureCb;
203 };
204 
209 {
210 public:
217  InterestValidationState(const Interest& interest,
218  const InterestValidationSuccessCallback& successCb,
219  const InterestValidationFailureCallback& failureCb);
220 
227  ~InterestValidationState() final;
228 
229  void
230  fail(const ValidationError& error) final;
231 
235  const Interest&
237  {
238  return m_interest;
239  }
240 
241 public:
243 
244 private:
245  void
246  verifyOriginalPacket(const optional<Certificate>& trustedCert) final;
247 
248  void
249  bypassValidation() final;
250 
251 private:
252  Interest m_interest;
255 };
256 
258 
259 } // inline namespace v2
260 } // namespace security
261 } // namespace ndn
262 
263 #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:44
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:36
Represents an NDN certificate.
Definition: certificate.hpp:60
Validation state for a data packet.
void fail(const ValidationError &error) final
Call the failure callback.
DataValidationState(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Create validation state for data.
Validation state for an interest packet.
util::Signal< InterestValidationState, Interest > afterSuccess
Validation error code and optional detailed error message.
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.
boost::logic::tribool getOutcome() const noexcept
void addCertificate(const Certificate &cert)
Add cert to the top of the certificate chain.
Interface for validating data and interest packets.
Definition: validator.hpp:62
Provides a lightweight signal / event system.
Definition: signal.hpp:53
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.
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.
Definition: data.cpp:25