validation-policy.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_POLICY_HPP
23 #define NDN_CXX_SECURITY_VALIDATION_POLICY_HPP
24 
25 #include "ndn-cxx/data.hpp"
26 #include "ndn-cxx/interest.hpp"
29 
30 namespace ndn::security {
31 
35 class ValidationPolicy : noncopyable
36 {
37 public:
38  using ValidationContinuation = std::function<void(const shared_ptr<CertificateRequest>& certRequest,
39  const shared_ptr<ValidationState>& state)>;
40 
41  virtual
42  ~ValidationPolicy() = default;
43 
58  void
59  setInnerPolicy(unique_ptr<ValidationPolicy> innerPolicy);
60 
64  bool
66  {
67  return m_innerPolicy != nullptr;
68  }
69 
77 
81  void
82  setValidator(Validator& validator);
83 
98  virtual void
99  checkPolicy(const Data& data, const shared_ptr<ValidationState>& state,
100  const ValidationContinuation& continueValidation) = 0;
101 
116  virtual void
117  checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state,
118  const ValidationContinuation& continueValidation) = 0;
119 
136  virtual void
137  checkPolicy(const Certificate& certificate, const shared_ptr<ValidationState>& state,
138  const ValidationContinuation& continueValidation)
139  {
140  checkPolicy(static_cast<const Data&>(certificate), state, continueValidation);
141  }
142 
144  Validator* m_validator = nullptr;
145  unique_ptr<ValidationPolicy> m_innerPolicy;
146 };
147 
161 getSignatureInfo(const Interest& interest, ValidationState& state);
162 
169 Name
170 getKeyLocatorName(const SignatureInfo& sigInfo, ValidationState& state);
171 
177 Name
178 extractIdentityNameFromKeyLocator(const Name& keyLocator);
179 
180 } // namespace ndn::security
181 
182 #endif // NDN_CXX_SECURITY_VALIDATION_POLICY_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
Represents a SignatureInfo or InterestSignatureInfo TLV element.
Represents an NDN certificate.
Definition: certificate.hpp:58
Abstraction that implements a validation policy for Interest and Data packets.
virtual ~ValidationPolicy()=default
void setValidator(Validator &validator)
Set validator to which the policy is associated.
virtual void checkPolicy(const Interest &interest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check interest against the policy.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
ValidationPolicy & getInnerPolicy()
Return the inner policy.
virtual void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check data against the policy.
bool hasInnerPolicy() const
Check if inner policy is set.
void setInnerPolicy(unique_ptr< ValidationPolicy > innerPolicy)
Set inner policy.
virtual void checkPolicy(const Certificate &certificate, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Check certificate against the policy.
unique_ptr< ValidationPolicy > m_innerPolicy
Interface for validating data and interest packets.
Definition: validator.hpp:61
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:48
Contains the ndn-cxx security framework.
Name extractIdentityNameFromKeyLocator(const Name &keyLocator)
Extract identity name from key, version-less certificate, or certificate name.
SignatureInfo getSignatureInfo(const Interest &interest, ValidationState &state)
Extract SignatureInfo from a signed Interest.
Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
Extract the KeyLocator name from a SignatureInfo element.