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-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_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 {
31 namespace security {
32 inline namespace v2 {
33 
34 class ValidationState;
35 
36 namespace validator_config {
37 
38 class Checker : noncopyable
39 {
40 public:
41  class Result
42  {
43  public:
49  explicit operator bool() const
50  {
51  return m_error.empty();
52  }
53 
58  const std::string&
60  {
61  return m_error;
62  }
63 
64  private:
65  explicit
66  Result(std::string error);
67 
68  private:
69  std::string m_error;
70 
71  friend Checker;
72  };
73 
74  explicit
76 
77  virtual
78  ~Checker() = default;
79 
89  Result
90  check(uint32_t pktType, tlv::SignatureTypeValue sigType,
91  const Name& pktName, const Name& klName, const ValidationState& state);
92 
100  static unique_ptr<Checker>
101  create(const ConfigSection& configSection, const std::string& configFilename);
102 
103 protected:
108  virtual Result
109  checkNames(const Name& pktName, const Name& klName);
110 
111  static Result
113  {
114  return Result("");
115  }
116 
117  class NegativeResultBuilder;
118 
119  static NegativeResultBuilder
120  reject();
121 
122 private:
123  static unique_ptr<Checker>
124  createCustomizedChecker(const ConfigSection& configSection, const std::string& configFilename);
125 
126  static unique_ptr<Checker>
127  createHierarchicalChecker(const ConfigSection& configSection, const std::string& configFilename);
128 
129  static unique_ptr<Checker>
130  createKeyLocatorChecker(tlv::SignatureTypeValue sigType,
131  const ConfigSection& configSection, const std::string& configFilename);
132 
133  static unique_ptr<Checker>
134  createKeyLocatorNameChecker(tlv::SignatureTypeValue sigType,
135  const ConfigSection& configSection, const std::string& configFilename);
136 
137 protected:
139 };
140 
142 {
143 public:
144  NameRelationChecker(tlv::SignatureTypeValue sigType, const Name& name, const NameRelation& relation);
145 
146 protected:
147  Result
148  checkNames(const Name& pktName, const Name& klName) override;
149 
150 private:
151  Name m_name;
152  NameRelation m_relation;
153 };
154 
155 class RegexChecker : public Checker
156 {
157 public:
158  explicit
159  RegexChecker(tlv::SignatureTypeValue sigType, const Regex& regex);
160 
161 protected:
162  Result
163  checkNames(const Name& pktName, const Name& klName) override;
164 
165 private:
166  Regex m_regex;
167 };
168 
170 {
171 public:
173  const std::string& pktNameExpr, const std::string pktNameExpand,
174  const std::string& klNameExpr, const std::string klNameExpand,
175  const NameRelation& hyperRelation);
176 
177 protected:
178  Result
179  checkNames(const Name& pktName, const Name& klName) override;
180 
181 private:
182  Regex m_hyperPRegex;
183  Regex m_hyperKRegex;
184  NameRelation m_hyperRelation;
185 };
186 
187 } // namespace validator_config
188 } // inline namespace v2
189 } // namespace security
190 } // namespace ndn
191 
192 #endif // NDN_CXX_SECURITY_VALIDATOR_CONFIG_CHECKER_HPP
Represents an absolute name.
Definition: name.hpp:44
const std::string & getErrorMessage() const
Return checker error message.
Definition: checker.hpp:59
static NegativeResultBuilder reject()
Definition: checker.cpp:67
Checker(tlv::SignatureTypeValue sigType)
Definition: checker.cpp:35
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:73
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
Create a checker from configuration section.
Definition: checker.cpp:182
virtual Result checkNames(const Name &pktName, const Name &klName)
Base version of name checking.
Definition: checker.cpp:108
Result checkNames(const Name &pktName, const Name &klName) override
Base version of name checking.
Definition: checker.cpp:161
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:149
Result checkNames(const Name &pktName, const Name &klName) override
Base version of name checking.
Definition: checker.cpp:121
NameRelationChecker(tlv::SignatureTypeValue sigType, const Name &name, const NameRelation &relation)
Definition: checker.cpp:113
RegexChecker(tlv::SignatureTypeValue sigType, const Regex &regex)
Definition: checker.cpp:133
Result checkNames(const Name &pktName, const Name &klName) override
Base version of name checking.
Definition: checker.cpp:140
boost::property_tree::ptree ConfigSection
Definition: common.hpp:36
SignatureTypeValue
SignatureType values.
Definition: tlv.hpp:127
@ SignatureSha256WithEcdsa
Definition: tlv.hpp:130
Definition: data.cpp:25