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-2018 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_V2_VALIDATION_STATE_HPP
23 #define NDN_SECURITY_V2_VALIDATION_STATE_HPP
24 
28 #include "ndn-cxx/util/signal.hpp"
29 
30 #include <list>
31 #include <unordered_set>
32 #include <boost/logic/tribool.hpp>
33 
34 namespace ndn {
35 namespace security {
36 namespace v2 {
37 
38 class Validator;
39 
58 class ValidationState : public TagHost, noncopyable
59 {
60 public:
65 
66  virtual
68 
69  boost::logic::tribool
70  getOutcome() const
71  {
72  return m_outcome;
73  }
74 
78  virtual void
79  fail(const ValidationError& error) = 0;
80 
84  size_t
85  getDepth() const;
86 
90  bool
91  hasSeenCertificateName(const Name& certName);
92 
103  void
104  addCertificate(const Certificate& cert);
105 
106 private: // Interface intended to be used only by Validator class
112  virtual void
113  verifyOriginalPacket(const Certificate& trustedCert) = 0;
114 
118  virtual void
119  bypassValidation() = 0;
120 
135  const Certificate*
136  verifyCertificateChain(const Certificate& trustedCert);
137 
138 protected:
139  boost::logic::tribool m_outcome;
140 
141 private:
142  std::unordered_set<Name> m_seenCertificateNames;
143 
150  std::list<v2::Certificate> m_certificateChain;
151 
152  friend class Validator;
153 };
154 
159 {
160 public:
167  DataValidationState(const Data& data,
168  const DataValidationSuccessCallback& successCb,
169  const DataValidationFailureCallback& failureCb);
170 
177  ~DataValidationState() final;
178 
179  void
180  fail(const ValidationError& error) final;
181 
185  const Data&
186  getOriginalData() const;
187 
188 private:
189  void
190  verifyOriginalPacket(const Certificate& trustedCert) final;
191 
192  void
193  bypassValidation() final;
194 
195 private:
196  Data m_data;
197  DataValidationSuccessCallback m_successCb;
198  DataValidationFailureCallback m_failureCb;
199 };
200 
205 {
206 public:
213  InterestValidationState(const Interest& interest,
214  const InterestValidationSuccessCallback& successCb,
215  const InterestValidationFailureCallback& failureCb);
216 
223  ~InterestValidationState() final;
224 
225  void
226  fail(const ValidationError& error) final;
227 
231  const Interest&
232  getOriginalInterest() const;
233 
234 public:
236 
237 private:
238  void
239  verifyOriginalPacket(const Certificate& trustedCert) final;
240 
241  void
242  bypassValidation() final;
243 
244 private:
245  Interest m_interest;
248 };
249 
250 } // namespace v2
251 } // namespace security
252 } // namespace ndn
253 
254 #endif // NDN_SECURITY_V2_VALIDATION_STATE_HPP
ndn::security::v2::ValidationError
Validation error code and optional detailed error message.
Definition: validation-error.hpp:35
ndn::security::v2::Validator
Interface for validating data and interest packets.
Definition: validator.hpp:62
ndn::security::v2::DataValidationState
Validation state for a data packet.
Definition: validation-state.hpp:159
ndn::security::v2::Validator
ndn security v2 Validator
Definition: validator.cpp:32
ndn::security::v2::DataValidationFailureCallback
function< void(const Data &data, const ValidationError &error)> DataValidationFailureCallback
Callback to report a failed Data validation.
Definition: validation-callback.hpp:42
certificate.hpp
signal.hpp
ndn::security::v2::DataValidationState::fail
void fail(const ValidationError &error) final
Call the failure callback.
Definition: validation-state.cpp:132
ndn::security::v2::ValidationState::getDepth
size_t getDepth() const
Definition: validation-state.cpp:48
tag-host.hpp
ndn::security::v2::InterestValidationState::afterSuccess
util::Signal< InterestValidationState, Interest > afterSuccess
Definition: validation-state.hpp:235
ndn::security::v2::ValidationState::m_outcome
boost::logic::tribool m_outcome
Definition: validation-state.hpp:139
ndn::security::v2::InterestValidationSuccessCallback
function< void(const Interest &interest)> InterestValidationSuccessCallback
Callback to report a successful Interest validation.
Definition: validation-callback.hpp:47
ndn::security::v2::InterestValidationState::fail
void fail(const ValidationError &error) final
Call the failure callback.
Definition: validation-state.cpp:192
ndn::security::v2::DataValidationState::~DataValidationState
~DataValidationState() final
Destructor.
Definition: validation-state.cpp:99
validation-callback.hpp
ndn::security::v2::InterestValidationState::getOriginalInterest
const Interest & getOriginalInterest() const
Definition: validation-state.cpp:201
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition: signal.hpp:52
ndn::Name
Represents an absolute name.
Definition: name.hpp:44
ndn::security::v2::InterestValidationState::InterestValidationState
InterestValidationState(const Interest &interest, const InterestValidationSuccessCallback &successCb, const InterestValidationFailureCallback &failureCb)
Create validation state for interest.
Definition: validation-state.cpp:148
ndn::security::v2::Certificate
The certificate following the certificate format naming convention.
Definition: certificate.hpp:82
ndn::security::v2::ValidationState::~ValidationState
virtual ~ValidationState()
Definition: validation-state.cpp:41
ndn::security::v2::InterestValidationState::~InterestValidationState
~InterestValidationState() final
Destructor.
Definition: validation-state.cpp:159
ndn::security::v2::InterestValidationFailureCallback
function< void(const Interest &interest, const ValidationError &error)> InterestValidationFailureCallback
Callback to report a failed Interest validation.
Definition: validation-callback.hpp:52
ndn::security::v2::ValidationState::fail
virtual void fail(const ValidationError &error)=0
Call the failure callback.
ndn::security::v2::ValidationState
Validation state.
Definition: validation-state.hpp:59
ndn::security::v2::ValidationState::addCertificate
void addCertificate(const Certificate &cert)
Add cert to the top of the certificate chain.
Definition: validation-state.cpp:60
ndn::Interest
Represents an Interest packet.
Definition: interest.hpp:44
ndn::TagHost
Base class to store tag information (e.g., inside Interest and Data packets)
Definition: tag-host.hpp:35
ndn::security::v2::ValidationState::ValidationState
ValidationState()
Create validation state.
Definition: validation-state.cpp:36
ndn::Data
Represents a Data packet.
Definition: data.hpp:36
ndn::security::v2::DataValidationSuccessCallback
function< void(const Data &data)> DataValidationSuccessCallback
Callback to report a successful Data validation.
Definition: validation-callback.hpp:37
ndn::security::v2::DataValidationState::getOriginalData
const Data & getOriginalData() const
Definition: validation-state.cpp:141
ndn::security::v2::ValidationState::getOutcome
boost::logic::tribool getOutcome() const
Definition: validation-state.hpp:70
ndn::security::v2::InterestValidationState
Validation state for an interest packet.
Definition: validation-state.hpp:205
ndn::security::v2::DataValidationState::DataValidationState
DataValidationState(const Data &data, const DataValidationSuccessCallback &successCb, const DataValidationFailureCallback &failureCb)
Create validation state for data.
Definition: validation-state.cpp:88
ndn::security::v2::ValidationState::hasSeenCertificateName
bool hasSeenCertificateName(const Name &certName)
Check if certName has been previously seen and record the supplied name.
Definition: validation-state.cpp:54
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34