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-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_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 {
31 namespace security {
32 inline namespace v2 {
33 
37 class ValidationPolicy : noncopyable
38 {
39 public:
40  using ValidationContinuation = std::function<void(const shared_ptr<CertificateRequest>& certRequest,
41  const shared_ptr<ValidationState>& state)>;
42 
43  virtual
44  ~ValidationPolicy() = default;
45 
60  void
61  setInnerPolicy(unique_ptr<ValidationPolicy> innerPolicy);
62 
66  bool
68  {
69  return m_innerPolicy != nullptr;
70  }
71 
79 
83  void
84  setValidator(Validator& validator);
85 
100  virtual void
101  checkPolicy(const Data& data, const shared_ptr<ValidationState>& state,
102  const ValidationContinuation& continueValidation) = 0;
103 
118  virtual void
119  checkPolicy(const Interest& interest, const shared_ptr<ValidationState>& state,
120  const ValidationContinuation& continueValidation) = 0;
121 
138  virtual void
139  checkPolicy(const Certificate& certificate, const shared_ptr<ValidationState>& state,
140  const ValidationContinuation& continueValidation)
141  {
142  checkPolicy(static_cast<const Data&>(certificate), state, continueValidation);
143  }
144 
146  Validator* m_validator = nullptr;
147  unique_ptr<ValidationPolicy> m_innerPolicy;
148 };
149 
163 getSignatureInfo(const Interest& interest, ValidationState& state);
164 
171 Name
172 getKeyLocatorName(const SignatureInfo& sigInfo, ValidationState& state);
173 
179 Name
180 extractIdentityNameFromKeyLocator(const Name& keyLocator);
181 
182 } // inline namespace v2
183 } // namespace security
184 } // namespace ndn
185 
186 #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:44
Represents a SignatureInfo or InterestSignatureInfo TLV element.
Represents an NDN certificate.
Definition: certificate.hpp:60
Abstraction that implements a validation policy for Interest and Data packets.
virtual void checkPolicy(const Interest &interest, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check interest against the policy.
ValidationPolicy & getInnerPolicy()
Return the inner policy.
void setValidator(Validator &validator)
Set validator to which the policy is associated.
std::function< void(const shared_ptr< CertificateRequest > &certRequest, const shared_ptr< ValidationState > &state)> ValidationContinuation
virtual void checkPolicy(const Certificate &certificate, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)
Check certificate against the policy.
unique_ptr< ValidationPolicy > m_innerPolicy
bool hasInnerPolicy() const
Check if inner policy is set.
virtual void checkPolicy(const Data &data, const shared_ptr< ValidationState > &state, const ValidationContinuation &continueValidation)=0
Check data against the policy.
void setInnerPolicy(unique_ptr< ValidationPolicy > innerPolicy)
Set inner policy.
Interface for validating data and interest packets.
Definition: validator.hpp:62
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:47
Name getKeyLocatorName(const SignatureInfo &si, ValidationState &state)
Extract the KeyLocator name from a SignatureInfo element.
SignatureInfo getSignatureInfo(const Interest &interest, ValidationState &state)
Extract SignatureInfo from a signed Interest.
Name extractIdentityNameFromKeyLocator(const Name &keyLocator)
Extract identity name from key, version-less certificate, or certificate name.
Definition: data.cpp:25