blob: 390dc085217263653db3e4a74150771a156f4560 [file] [log] [blame]
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2017 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_VALIDATOR_CONFIG_CHECKER_HPP
23#define NDN_SECURITY_V2_VALIDATOR_CONFIG_CHECKER_HPP
24
25#include "common.hpp"
26#include "name-relation.hpp"
27#include "../../../name.hpp"
28#include "../../../util/regex.hpp"
29
30namespace ndn {
31namespace security {
32namespace v2 {
33
34class ValidationState;
35
36namespace validator_config {
37
38class Checker : noncopyable
39{
40public:
41 virtual
42 ~Checker() = default;
43
44 /**
45 * @brief Check if packet name ane KeyLocator satisfy the checker's conditions
46 *
47 * @param pktType tlv::Interest or tlv::Data
48 * @param pktName packet's name
49 * @param klName KeyLocator's name
50 * @param state Validation state
51 *
52 * @retval false data is immediately invalid. Will call state::fail() with proper code and message.
53 * @retval true further signature verification is needed.
54 */
55 bool
56 check(uint32_t pktType, const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state);
57
58 /**
59 * @brief create a checker from configuration section
60 *
61 * @param configSection The section containing the definition of checker.
62 * @param configFilename The configuration file name.
63 * @return a checker created from configuration
64 */
65 static unique_ptr<Checker>
66 create(const ConfigSection& configSection, const std::string& configFilename);
67
68private:
69 static unique_ptr<Checker>
70 createCustomizedChecker(const ConfigSection& configSection, const std::string& configFilename);
71
72 static unique_ptr<Checker>
73 createHierarchicalChecker(const ConfigSection& configSection, const std::string& configFilename);
74
75 static unique_ptr<Checker>
76 createKeyLocatorChecker(const ConfigSection& configSection, const std::string& configFilename);
77
78 static unique_ptr<Checker>
79 createKeyLocatorNameChecker(const ConfigSection& configSection, const std::string& configFilename);
80
81protected:
82 virtual bool
83 checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) = 0;
84};
85
86class NameRelationChecker : public Checker
87{
88public:
89 NameRelationChecker(const Name& name, const NameRelation& relation);
90
91protected:
92 bool
93 checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) override;
94
95private:
96 Name m_name;
97 NameRelation m_relation;
98};
99
100class RegexChecker : public Checker
101{
102public:
103 explicit
104 RegexChecker(const Regex& regex);
105
106protected:
107 bool
108 checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) override;
109
110private:
111 Regex m_regex;
112};
113
114class HyperRelationChecker : public Checker
115{
116public:
117 HyperRelationChecker(const std::string& pktNameExpr, const std::string pktNameExpand,
118 const std::string& klNameExpr, const std::string klNameExpand,
119 const NameRelation& hyperRelation);
120
121protected:
122 bool
123 checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) override;
124
125private:
126 Regex m_hyperPRegex;
127 Regex m_hyperKRegex;
128 NameRelation m_hyperRelation;
129};
130
131} // namespace validator_config
132} // namespace v2
133} // namespace security
134} // namespace ndn
135
136#endif // NDN_SECURITY_V2_VALIDATOR_CONFIG_CHECKER_HPP