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-2020 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_VALIDATION_STATE_HPP
23 #define NDN_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
113  virtual void
114  verifyOriginalPacket(const 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;
141 
142 private:
143  std::unordered_set<Name> m_seenCertificateNames;
144 
151  std::list<v2::Certificate> m_certificateChain;
152 
153  friend class 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&
187  getOriginalData() const;
188 
189 private:
190  void
191  verifyOriginalPacket(const Certificate& trustedCert) final;
192 
193  void
194  bypassValidation() final;
195 
196 private:
197  Data m_data;
198  DataValidationSuccessCallback m_successCb;
199  DataValidationFailureCallback m_failureCb;
200 };
201 
206 {
207 public:
214  InterestValidationState(const Interest& interest,
215  const InterestValidationSuccessCallback& successCb,
216  const InterestValidationFailureCallback& failureCb);
217 
224  ~InterestValidationState() final;
225 
226  void
227  fail(const ValidationError& error) final;
228 
232  const Interest&
233  getOriginalInterest() const;
234 
235 public:
237 
238 private:
239  void
240  verifyOriginalPacket(const Certificate& trustedCert) final;
241 
242  void
243  bypassValidation() final;
244 
245 private:
246  Interest m_interest;
249 };
250 
252 
253 } // inline namespace v2
254 } // namespace security
255 } // namespace ndn
256 
257 #endif // NDN_SECURITY_VALIDATION_STATE_HPP
ValidationState()
Create validation state.
Definition: data.cpp:26
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.
bool hasSeenCertificateName(const Name &certName)
Check if certName has been previously seen and record the supplied name.
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:50
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:44
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:39
function< void(const Interest &interest)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.
Interface for validating data and interest packets.
Definition: validator.hpp:61