checker.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_VALIDATOR_CONFIG_CHECKER_HPP
23 #define NDN_CXX_SECURITY_VALIDATOR_CONFIG_CHECKER_HPP
24 
25 #include "ndn-cxx/name.hpp"
28 #include "ndn-cxx/util/regex.hpp"
29 
30 namespace ndn::security {
31 
32 class ValidationState;
33 
34 namespace validator_config {
35 
36 class Checker : noncopyable
37 {
38 public:
39  class Result
40  {
41  public:
47  explicit operator bool() const
48  {
49  return m_error.empty();
50  }
51 
56  const std::string&
58  {
59  return m_error;
60  }
61 
62  private:
63  explicit
64  Result(std::string error);
65 
66  private:
67  std::string m_error;
68 
69  friend Checker;
70  };
71 
72  explicit
74 
75  virtual
76  ~Checker() = default;
77 
87  Result
88  check(uint32_t pktType, tlv::SignatureTypeValue sigType,
89  const Name& pktName, const Name& klName, const ValidationState& state);
90 
98  static unique_ptr<Checker>
99  create(const ConfigSection& configSection, const std::string& configFilename);
100 
101 protected:
106  virtual Result
107  checkNames(const Name& pktName, const Name& klName);
108 
109  static Result
111  {
112  return Result("");
113  }
114 
115  class NegativeResultBuilder;
116 
117  static NegativeResultBuilder
118  reject();
119 
120 private:
121  static unique_ptr<Checker>
122  createCustomizedChecker(const ConfigSection& configSection, const std::string& configFilename);
123 
124  static unique_ptr<Checker>
125  createHierarchicalChecker(const ConfigSection& configSection, const std::string& configFilename);
126 
127  static unique_ptr<Checker>
128  createKeyLocatorChecker(tlv::SignatureTypeValue sigType,
129  const ConfigSection& configSection, const std::string& configFilename);
130 
131  static unique_ptr<Checker>
132  createKeyLocatorNameChecker(tlv::SignatureTypeValue sigType,
133  const ConfigSection& configSection, const std::string& configFilename);
134 
135 protected:
137 };
138 
140 {
141 public:
142  NameRelationChecker(tlv::SignatureTypeValue sigType, const Name& name, const NameRelation& relation);
143 
144 protected:
145  Result
146  checkNames(const Name& pktName, const Name& klName) override;
147 
148 private:
149  Name m_name;
150  NameRelation m_relation;
151 };
152 
153 class RegexChecker : public Checker
154 {
155 public:
156  explicit
157  RegexChecker(tlv::SignatureTypeValue sigType, const Regex& regex);
158 
159 protected:
160  Result
161  checkNames(const Name& pktName, const Name& klName) override;
162 
163 private:
164  Regex m_regex;
165 };
166 
168 {
169 public:
171  const std::string& pktNameExpr, const std::string& pktNameExpand,
172  const std::string& klNameExpr, const std::string& klNameExpand,
173  const NameRelation& hyperRelation);
174 
175 protected:
176  Result
177  checkNames(const Name& pktName, const Name& klName) override;
178 
179 private:
180  Regex m_hyperPRegex;
181  Regex m_hyperKRegex;
182  NameRelation m_hyperRelation;
183 };
184 
185 } // namespace validator_config
186 } // namespace ndn::security
187 
188 #endif // NDN_CXX_SECURITY_VALIDATOR_CONFIG_CHECKER_HPP
Represents an absolute name.
Definition: name.hpp:45
const std::string & getErrorMessage() const
Return checker error message.
Definition: checker.hpp:57
tlv::SignatureTypeValue m_sigType
Definition: checker.hpp:136
virtual Result checkNames(const Name &pktName, const Name &klName)
Base version of name checking.
Definition: checker.cpp:103
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
Create a checker from configuration section.
Definition: checker.cpp:177
Result check(uint32_t pktType, tlv::SignatureTypeValue sigType, const Name &pktName, const Name &klName, const ValidationState &state)
Check if packet name and KeyLocator satisfy the checker's conditions.
Definition: checker.cpp:68
Checker(tlv::SignatureTypeValue sigType)
Definition: checker.cpp:30
static NegativeResultBuilder reject()
Definition: checker.cpp:62
HyperRelationChecker(tlv::SignatureTypeValue sigType, const std::string &pktNameExpr, const std::string &pktNameExpand, const std::string &klNameExpr, const std::string &klNameExpand, const NameRelation &hyperRelation)
Definition: checker.cpp:144
Result checkNames(const Name &pktName, const Name &klName) override
Base version of name checking.
Definition: checker.cpp:156
Result checkNames(const Name &pktName, const Name &klName) override
Base version of name checking.
Definition: checker.cpp:116
NameRelationChecker(tlv::SignatureTypeValue sigType, const Name &name, const NameRelation &relation)
Definition: checker.cpp:108
Result checkNames(const Name &pktName, const Name &klName) override
Base version of name checking.
Definition: checker.cpp:135
RegexChecker(tlv::SignatureTypeValue sigType, const Regex &regex)
Definition: checker.cpp:128
boost::property_tree::ptree ConfigSection
Definition: common.hpp:33
Contains the ndn-cxx security framework.
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:127
@ SignatureSha256WithEcdsa
Definition: tlv.hpp:130