NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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-2021 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:
66 
67  virtual
69 
70  boost::logic::tribool
71  getOutcome() const
72  {
73  return m_outcome;
74  }
75 
79  virtual void
80  fail(const ValidationError& error) = 0;
81 
85  size_t
86  getDepth() const;
87 
91  bool
92  hasSeenCertificateName(const Name& certName);
93 
104  void
105  addCertificate(const Certificate& cert);
106 
107 private: // Interface intended to be used only by Validator class
115  virtual void
116  verifyOriginalPacket(const optional<Certificate>& trustedCert) = 0;
117 
121  virtual void
122  bypassValidation() = 0;
123 
138  const Certificate*
139  verifyCertificateChain(const Certificate& trustedCert);
140 
141 protected:
142  boost::logic::tribool m_outcome;
143 
144 private:
145  std::unordered_set<Name> m_seenCertificateNames;
146 
153  std::list<Certificate> m_certificateChain;
154 
155  friend Validator;
156 };
157 
162 {
163 public:
170  DataValidationState(const Data& data,
171  const DataValidationSuccessCallback& successCb,
172  const DataValidationFailureCallback& failureCb);
173 
180  ~DataValidationState() final;
181 
182  void
183  fail(const ValidationError& error) final;
184 
188  const Data&
189  getOriginalData() const;
190 
191 private:
192  void
193  verifyOriginalPacket(const optional<Certificate>& trustedCert) final;
194 
195  void
196  bypassValidation() final;
197 
198 private:
199  Data m_data;
200  DataValidationSuccessCallback m_successCb;
201  DataValidationFailureCallback m_failureCb;
202 };
203 
208 {
209 public:
216  InterestValidationState(const Interest& interest,
217  const InterestValidationSuccessCallback& successCb,
218  const InterestValidationFailureCallback& failureCb);
219 
226  ~InterestValidationState() final;
227 
228  void
229  fail(const ValidationError& error) final;
230 
234  const Interest&
235  getOriginalInterest() const;
236 
237 public:
239 
240 private:
241  void
242  verifyOriginalPacket(const optional<Certificate>& trustedCert) final;
243 
244  void
245  bypassValidation() final;
246 
247 private:
248  Interest m_interest;
251 };
252 
254 
255 } // inline namespace v2
256 } // namespace security
257 } // namespace ndn
258 
259 #endif // NDN_CXX_SECURITY_VALIDATION_STATE_HPP
ValidationState()
Create validation state.
Copyright (c) 2011-2015 Regents of the University of California.
Represents an NDN certificate following the version 2.0 format.
Definition: certificate.hpp:60
function< void(const Data &data)> DataValidationSuccessCallback
Callback to report a successful Data validation.
bool hasSeenCertificateName(const Name &certName)
Check if certName has been previously seen and record the supplied name.
ndn security Validator
Definition: validator.cpp:32
Base class to store tag information (e.g., inside Interest and Data packets)
Definition: tag-host.hpp:34
void addCertificate(const Certificate &cert)
Add cert to the top of the certificate chain.
Represents an Interest packet.
Definition: interest.hpp:48
function< void(const Data &data, const ValidationError &error)> DataValidationFailureCallback
Callback to report a failed Data validation.
provides a lightweight signal / event system
Definition: signal.hpp:52
Validation state for a data packet.
boost::logic::tribool getOutcome() const
provides a tag type for simple types
Definition: tag.hpp:58
Validation state for an interest packet.
util::Signal< InterestValidationState, Interest > afterSuccess
Represents an absolute name.
Definition: name.hpp:41
function< void(const Interest &interest, const ValidationError &error)> InterestValidationFailureCallback
Callback to report a failed Interest validation.
Validation error code and optional detailed error message.
virtual void fail(const ValidationError &error)=0
Call the failure callback.
Represents a Data packet.
Definition: data.hpp:37
function< void(const Interest &interest)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.
Interface for validating data and interest packets.
Definition: validator.hpp:61