28 #include <boost/algorithm/string.hpp>    29 #include <boost/filesystem.hpp>    30 #include <boost/lexical_cast.hpp>    35 namespace validator_config {
    55   , m_relation(relation)
    66     std::ostringstream os;
    67     os << 
"KeyLocator check failed: name relation " << m_name << 
" " << m_relation
    68        << 
" for packet " << pktName << 
" is invalid"    69        << 
" (KeyLocator=" << klName << 
", identity=" << identity << 
")";
    83   bool result = m_regex.
match(klName);
    85     std::ostringstream os;
    86     os << 
"KeyLocator check failed: regex " << m_regex << 
" for packet " << pktName << 
" is invalid"    87        << 
" (KeyLocator=" << klName << 
")";
    95                                            const std::string& klNameExpr, 
const std::string klNameExpand,
    97   : m_hyperPRegex(pktNameExpr, pktNameExpand)
    98   , m_hyperKRegex(klNameExpr, klNameExpand)
    99   , m_hyperRelation(hyperRelation)
   106   if (!m_hyperPRegex.
match(pktName) || !m_hyperKRegex.
match(klName)) {
   107     std::ostringstream os;
   108     os << 
"Packet " << pktName << 
" (" << 
"KeyLocator=" << klName << 
") does not match "   109        << 
"the hyper relation rule pkt=" << m_hyperPRegex << 
", key=" << m_hyperKRegex;
   116     std::ostringstream os;
   117     os << 
"KeyLocator check failed: hyper relation " << m_hyperRelation
   118        << 
" pkt=" << m_hyperPRegex << 
", key=" << m_hyperKRegex
   119        << 
" of packet " << pktName << 
" (KeyLocator=" << klName << 
") is invalid";
   128   auto propertyIt = configSection.begin();
   131   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, 
"type")) {
   132     BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.type>"));
   135   std::string type = propertyIt->second.data();
   137   if (boost::iequals(type, 
"customized")) {
   138     return createCustomizedChecker(configSection, configFilename);
   140   else if (boost::iequals(type, 
"hierarchical")) {
   141     return createHierarchicalChecker(configSection, configFilename);
   144     BOOST_THROW_EXCEPTION(
Error(
"Unsupported checker type: " + type));
   149 Checker::createCustomizedChecker(
const ConfigSection& configSection,
   150                                         const std::string& configFilename)
   152   auto propertyIt = configSection.begin();
   157   if (propertyIt != configSection.end() && boost::iequals(propertyIt->first, 
"sig-type")) {
   163   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, 
"key-locator")) {
   164     BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator>"));
   167   auto checker = createKeyLocatorChecker(propertyIt->second, configFilename);
   170   if (propertyIt != configSection.end()) {
   171     BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker"));
   178 Checker::createHierarchicalChecker(
const ConfigSection& configSection,
   179                                           const std::string& configFilename)
   181   auto propertyIt = configSection.begin();
   186   if (propertyIt != configSection.end() && boost::iequals(propertyIt->first, 
"sig-type")) {
   191   if (propertyIt != configSection.end()) {
   192     BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker"));
   195   return make_unique<HyperRelationChecker>(
"^(<>*)$",        
"\\1",
   196                                            "^(<>*)<KEY><>$", 
"\\1",
   203 Checker::createKeyLocatorChecker(
const ConfigSection& configSection, 
const std::string& configFilename)
   205   auto propertyIt = configSection.begin();
   208   if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, 
"type"))
   209     BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.type>"));
   211   std::string type = propertyIt->second.data();
   213   if (boost::iequals(type, 
"name"))
   214     return createKeyLocatorNameChecker(configSection, configFilename);
   216     BOOST_THROW_EXCEPTION(
Error(
"Unsupported checker.key-locator.type: " + type));
   220 Checker::createKeyLocatorNameChecker(
const ConfigSection& configSection, 
const std::string& configFilename)
   222   auto propertyIt = configSection.begin();
   225   if (propertyIt == configSection.end())
   226     BOOST_THROW_EXCEPTION(
Error(
"Expect more checker.key-locator properties"));
   228   if (boost::iequals(propertyIt->first, 
"name")) {
   231       name = 
Name(propertyIt->second.data());
   234       BOOST_THROW_EXCEPTION(
Error(
"Invalid checker.key-locator.name: " + propertyIt->second.data()));
   238     if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first, 
"relation")) {
   239       BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.relation>"));
   242     std::string relationString = propertyIt->second.data();
   247     if (propertyIt != configSection.end()) {
   248       BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker.key-locator"));
   250     return make_unique<NameRelationChecker>(name, relation);
   252   else if (boost::iequals(propertyIt->first, 
"regex")) {
   253     std::string regexString = propertyIt->second.data();
   256     if (propertyIt != configSection.end()) {
   257       BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker.key-locator"));
   261       return make_unique<RegexChecker>(regexString);
   264       BOOST_THROW_EXCEPTION(
Error(
"Invalid checker.key-locator.regex: " + regexString));
   267   else if (boost::iequals(propertyIt->first, 
"hyper-relation")) {
   270     ConfigSection::const_iterator hPropertyIt = hSection.begin();
   273     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, 
"k-regex")) {
   274       BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.k-regex>"));
   277     std::string kRegex = hPropertyIt->second.data();
   281     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, 
"k-expand")) {
   282       BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.k-expand>"));
   285     std::string kExpand = hPropertyIt->second.data();
   289     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, 
"h-relation")) {
   290       BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.h-relation>"));
   293     std::string hRelation = hPropertyIt->second.data();
   297     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, 
"p-regex")) {
   298       BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.p-regex>"));
   301     std::string pRegex = hPropertyIt->second.data();
   305     if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first, 
"p-expand")) {
   306       BOOST_THROW_EXCEPTION(
Error(
"Expect <checker.key-locator.hyper-relation.p-expand>"));
   309     std::string pExpand = hPropertyIt->second.data();
   312     if (hPropertyIt != hSection.end()) {
   313       BOOST_THROW_EXCEPTION(
Error(
"Expect the end of checker.key-locator.hyper-relation"));
   318       return make_unique<HyperRelationChecker>(pRegex, pExpand, kRegex, kExpand, relation);
   321       BOOST_THROW_EXCEPTION(
Error(
"Invalid regex for key-locator.hyper-relation"));
   325     BOOST_THROW_EXCEPTION(
Error(
"Unsupported checker.key-locator"));
 
Copyright (c) 2011-2015 Regents of the University of California. 
 
NameRelationChecker(const Name &name, const NameRelation &relation)
 
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
 
const size_t MIN_SIZE
minimal number of components for Signed Interest 
 
RegexChecker(const Regex ®ex)
 
Catch-all error for security policy errors that don't fit in other categories. 
 
bool checkNameRelation(NameRelation relation, const Name &name1, const Name &name2)
check whether name1 and name2 satisfies relation 
 
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
 
NameRelation getNameRelationFromString(const std::string &relationString)
convert relationString to NameRelation 
 
size_t size() const 
Get number of components. 
 
Represents an absolute name. 
 
boost::property_tree::ptree ConfigSection
 
virtual Name expand(const std::string &expand="")
 
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
 
bool match(const Name &name)
 
PartialName getPrefix(ssize_t nComponents) const 
Extract a prefix of the name. 
 
HyperRelationChecker(const std::string &pktNameExpr, const std::string pktNameExpand, const std::string &klNameExpr, const std::string klNameExpand, const NameRelation &hyperRelation)
 
bool check(uint32_t pktType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state)
Check if packet name ane KeyLocator satisfy the checker's conditions. 
 
virtual bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state)=0
 
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName. 
 
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
create a checker from configuration section