Alexander Afanasyev | e5a19b8 | 2017-01-30 22:30:46 -0800 | [diff] [blame^] | 1 | /* -*- 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 | |
| 30 | namespace ndn { |
| 31 | namespace security { |
| 32 | namespace v2 { |
| 33 | |
| 34 | class ValidationState; |
| 35 | |
| 36 | namespace validator_config { |
| 37 | |
| 38 | class Checker : noncopyable |
| 39 | { |
| 40 | public: |
| 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 | |
| 68 | private: |
| 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 | |
| 81 | protected: |
| 82 | virtual bool |
| 83 | checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) = 0; |
| 84 | }; |
| 85 | |
| 86 | class NameRelationChecker : public Checker |
| 87 | { |
| 88 | public: |
| 89 | NameRelationChecker(const Name& name, const NameRelation& relation); |
| 90 | |
| 91 | protected: |
| 92 | bool |
| 93 | checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) override; |
| 94 | |
| 95 | private: |
| 96 | Name m_name; |
| 97 | NameRelation m_relation; |
| 98 | }; |
| 99 | |
| 100 | class RegexChecker : public Checker |
| 101 | { |
| 102 | public: |
| 103 | explicit |
| 104 | RegexChecker(const Regex& regex); |
| 105 | |
| 106 | protected: |
| 107 | bool |
| 108 | checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) override; |
| 109 | |
| 110 | private: |
| 111 | Regex m_regex; |
| 112 | }; |
| 113 | |
| 114 | class HyperRelationChecker : public Checker |
| 115 | { |
| 116 | public: |
| 117 | HyperRelationChecker(const std::string& pktNameExpr, const std::string pktNameExpand, |
| 118 | const std::string& klNameExpr, const std::string klNameExpand, |
| 119 | const NameRelation& hyperRelation); |
| 120 | |
| 121 | protected: |
| 122 | bool |
| 123 | checkNames(const Name& pktName, const Name& klName, const shared_ptr<ValidationState>& state) override; |
| 124 | |
| 125 | private: |
| 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 |