24 #ifndef NDN_SECURITY_CONF_KEY_LOCATOR_CHECKER_HPP 25 #define NDN_SECURITY_CONF_KEY_LOCATOR_CHECKER_HPP 27 #include "../../common.hpp" 28 #include "../../data.hpp" 29 #include "../../interest.hpp" 30 #include "../../util/regex.hpp" 31 #include "../security-common.hpp" 32 #include <boost/algorithm/string.hpp> 40 class KeyLocatorCheckerFactory;
68 std::string& failInfo)
76 std::string& failInfo)
80 failInfo =
"No Signature";
85 return check(signedName, keyLocator, failInfo);
93 std::string& failInfo) = 0;
101 return (name1 == name2);
105 return (name1.
isPrefixOf(name2) && name1 != name2);
118 , m_relation(relation)
126 std::string& failInfo)
133 failInfo =
"KeyLocatorChecker failed!";
138 failInfo =
"KeyLocator does not have name";
161 std::string& failInfo)
165 if (m_regex.match(keyLocator.
getName()))
168 failInfo =
"KeyLocatorChecker failed!";
173 failInfo =
"KeyLocator does not have name";
186 const std::string& kExpr,
const std::string kExpand,
188 : m_hyperPRegex(new
Regex(pExpr, pExpand))
189 , m_hyperKRegex(new
Regex(kExpr, kExpand))
190 , m_hyperRelation(hyperRelation)
198 std::string& failInfo)
202 if (m_hyperPRegex->match(packetName) &&
203 m_hyperKRegex->match(keyLocator.
getName()) &&
205 m_hyperKRegex->expand(),
206 m_hyperPRegex->expand()))
209 failInfo =
"KeyLocatorChecker failed!";
214 failInfo =
"KeyLocator does not have name";
221 shared_ptr<Regex> m_hyperPRegex;
222 shared_ptr<Regex> m_hyperKRegex;
230 static shared_ptr<KeyLocatorChecker>
233 ConfigSection::const_iterator propertyIt = configSection.begin();
236 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type"))
237 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.type>!"));
239 std::string type = propertyIt->second.data();
241 if (boost::iequals(type,
"name"))
242 return createKeyLocatorNameChecker(configSection, filename);
244 BOOST_THROW_EXCEPTION(
Error(
"Unsupported checker.key-locator.type: " + type));
248 static shared_ptr<KeyLocatorChecker>
249 createKeyLocatorNameChecker(
const ConfigSection& configSection,
250 const std::string& filename)
252 ConfigSection::const_iterator propertyIt = configSection.begin();
255 if (propertyIt == configSection.end())
256 BOOST_THROW_EXCEPTION(
Error(
"Expect more checker.key-locator properties"));
258 if (boost::iequals(propertyIt->first,
"name"))
263 name =
Name(propertyIt->second.data());
267 BOOST_THROW_EXCEPTION(
Error(
"Invalid checker.key-locator.name: " +
268 propertyIt->second.data()));
272 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation"))
273 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.relation>!"));
275 std::string relationString = propertyIt->second.data();
279 if (boost::iequals(relationString,
"equal"))
281 else if (boost::iequals(relationString,
"is-prefix-of"))
283 else if (boost::iequals(relationString,
"is-strict-prefix-of"))
286 BOOST_THROW_EXCEPTION(
Error(
"Unsupported relation: " + relationString));
288 if (propertyIt != configSection.end())
289 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker.key-locator!"));
291 return shared_ptr<RelationKeyLocatorNameChecker>
294 else if (boost::iequals(propertyIt->first,
"regex"))
296 std::string regexString = propertyIt->second.data();
299 if (propertyIt != configSection.end())
300 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker.key-locator!"));
304 return shared_ptr<RegexKeyLocatorNameChecker>
309 BOOST_THROW_EXCEPTION(
Error(
"Invalid checker.key-locator.regex: " + regexString));
312 else if (boost::iequals(propertyIt->first,
"hyper-relation"))
316 ConfigSection::const_iterator hPropertyIt = hSection.begin();
319 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"k-regex"))
320 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.k-regex>!"));
322 std::string kRegex = hPropertyIt->second.data();
326 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"k-expand"))
327 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.k-expand>!"));
329 std::string kExpand = hPropertyIt->second.data();
333 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"h-relation"))
334 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.h-relation>!"));
336 std::string hRelation = hPropertyIt->second.data();
340 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"p-regex"))
341 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.p-regex>!"));
343 std::string pRegex = hPropertyIt->second.data();
347 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"p-expand"))
348 BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.p-expand>!"));
350 std::string pExpand = hPropertyIt->second.data();
353 if (hPropertyIt != hSection.end())
354 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker.key-locator.hyper-relation!"));
357 if (boost::iequals(hRelation,
"equal"))
359 else if (boost::iequals(hRelation,
"is-prefix-of"))
361 else if (boost::iequals(hRelation,
"is-strict-prefix-of"))
364 BOOST_THROW_EXCEPTION(
Error(
"Unsupported checker.key-locator.hyper-relation.h-relation: " 369 return shared_ptr<HyperKeyLocatorNameChecker>
376 BOOST_THROW_EXCEPTION(
Error(
"Invalid regex for key-locator.hyper-relation"));
380 BOOST_THROW_EXCEPTION(
Error(
"Unsupported checker.key-locator"));
389 #endif // NDN_SECURITY_CONF_KEY_LOCATOR_CHECKER_HPP RegexKeyLocatorNameChecker(const Regex ®ex)
virtual bool check(const Name &packetName, const KeyLocator &keyLocator, std::string &failInfo)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Copyright (c) 2011-2015 Regents of the University of California.
virtual bool check(const Name &packetName, const KeyLocator &keyLocator, std::string &failInfo)
const Name & getName() const
Get name of the Data packet.
const Name & getName() const
get Name element
represents an Interest packet
RelationKeyLocatorNameChecker(const Name &name, const KeyLocatorChecker::Relation &relation)
Copyright (c) 2013-2015 Regents of the University of California.
KeyLocatorChecker is one of the classes used by ValidatorConfig.
static shared_ptr< KeyLocatorChecker > create(const ConfigSection &configSection, const std::string &filename)
bool check(const Data &data, const KeyLocator &keyLocator, std::string &failInfo)
Error that can be thrown from Name.
bool check(const Interest &interest, const KeyLocator &keyLocator, std::string &failInfo)
virtual ~KeyLocatorChecker()
HyperKeyLocatorNameChecker(const std::string &pExpr, const std::string pExpand, const std::string &kExpr, const std::string kExpand, const Relation &hyperRelation)
Name abstraction to represent an absolute name.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
size_t size() const
Get the number of components.
boost::property_tree::ptree ConfigSection
virtual bool check(const Name &packetName, const KeyLocator &keyLocator, std::string &failInfo)
bool checkRelation(const Relation &relation, const Name &name1, const Name &name2)
const Name & getName() const