Exemplo n.º 1
0
    def _createNameFilter(configSection):
        """
        This is a helper for create() to create a filter from the configuration
        section which is type "name".

        :param BoostInfoTree configSection: The section containing the
          definition of the filter.
        :return: A new filter created from the configuration section.
        :rtype: ConfigFilter
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            # Get the filter.name.
            name = Name(nameUri)

            # Get the filter.relation.
            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError("Expected <filter.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(
                relationValue)

            return ConfigRelationNameFilter(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexNameFilter(regexString)
            except:
                raise ValidatorConfigError("Wrong filter.regex: " +
                                           regexString)

        raise ValidatorConfigError("Wrong filter(name) properties")
Exemplo n.º 2
0
    def _createNameFilter(configSection):
        """
        This is a helper for create() to create a filter from the configuration
        section which is type "name".

        :param BoostInfoTree configSection: The section containing the
          definition of the filter.
        :return: A new filter created from the configuration section.
        :rtype: ConfigFilter
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            # Get the filter.name.
            name = Name(nameUri)

            # Get the filter.relation.
            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError("Expected <filter.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(relationValue)

            return ConfigRelationNameFilter(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexNameFilter(regexString)
            except:
                raise ValidatorConfigError("Wrong filter.regex: " + regexString)

        raise ValidatorConfigError("Wrong filter(name) properties")
Exemplo n.º 3
0
    def checkNames(self, packetName, keyLocatorName, state):
        """
        :param Name packetName:
        :param Name keyLocatorName:
        :param ValidationState state:
        :rtype: bool
        """
        if not self._packetNameRegex.match(packetName):
            state.fail(
                ValidationError(
                    ValidationError.POLICY_ERROR,
                    "The packet " + packetName.toUri() + " (KeyLocator=" +
                    keyLocatorName.toUri() +
                    ") does not match the hyper relation packet name regex " +
                    self._packetNameRegex.getExpr()))
            return False
        if not self._keyNameRegex.match(keyLocatorName):
            state.fail(
                ValidationError(
                    ValidationError.POLICY_ERROR,
                    "The packet " + packetName.toUri() + " (KeyLocator=" +
                    keyLocatorName.toUri() +
                    ") does not match the hyper relation key name regex " +
                    self._keyNameRegex.getExpr()))
            return False

        keyNameMatchExpansion = self._keyNameRegex.expand(
            self._keyNameExpansion)
        packetNameMatchExpansion = self._packetNameRegex.expand(
            self._packetNameExpansion)
        result = ConfigNameRelation.checkNameRelation(
            self._hyperRelation, keyNameMatchExpansion,
            packetNameMatchExpansion)
        if not result:
            state.fail(
                ValidationError(
                    ValidationError.POLICY_ERROR,
                    "KeyLocator check failed: hyper relation " +
                    ConfigNameRelation.toString(self._hyperRelation) +
                    " packet name match=" + packetNameMatchExpansion.toUri() +
                    ", key name match=" + keyNameMatchExpansion.toUri() +
                    " of packet " + packetName.toUri() + " (KeyLocator=" +
                    keyLocatorName.toUri() + ") is invalid"))

        return result
Exemplo n.º 4
0
    def matchName(self, packetName):
        """
        Implementation of the check for match.

        :param Name packetName: The packet name, which is already stripped of
          signature components if this is a signed Interest name.
        :return: True for a match.
        :rtype: bool
        """
        return ConfigNameRelation.checkNameRelation(self._relation, self._name,
                                                    packetName)
Exemplo n.º 5
0
    def matchName(self, packetName):
        """
        Implementation of the check for match.

        :param Name packetName: The packet name, which is already stripped of
          signature components if this is a signed Interest name.
        :return: True for a match.
        :rtype: bool
        """
        return ConfigNameRelation.checkNameRelation(
          self._relation, self._name, packetName)
Exemplo n.º 6
0
    def checkNames(self, packetName, keyLocatorName, state):
        """
        :param Name packetName:
        :param Name keyLocatorName:
        :param ValidationState state:
        :rtype: bool
        """
        # packetName is not used in this check.

        identity = PibKey.extractIdentityFromKeyName(keyLocatorName)
        result = ConfigNameRelation.checkNameRelation(
          self._relation, self._name, identity)
        if not result:
            state.fail(ValidationError(ValidationError.POLICY_ERROR,
              "KeyLocator check failed: name relation " + self._name.toUri() + " " +
              ConfigNameRelation.toString(self._relation) + " for packet " +
              packetName.toUri() + " is invalid (KeyLocator=" +
              keyLocatorName.toUri() + ", identity=" + identity.toUri() + ")"))

        return result
Exemplo n.º 7
0
    def checkNames(self, packetName, keyLocatorName, state):
        """
        :param Name packetName:
        :param Name keyLocatorName:
        :param ValidationState state:
        :rtype: bool
        """
        if not self._packetNameRegex.match(packetName):
            state.fail(ValidationError(ValidationError.POLICY_ERROR,
              "The packet " + packetName.toUri() + " (KeyLocator=" +
              keyLocatorName.toUri() +
              ") does not match the hyper relation packet name regex " +
              self._packetNameRegex.getExpr()))
            return False
        if not self._keyNameRegex.match(keyLocatorName):
            state.fail(ValidationError(ValidationError.POLICY_ERROR,
              "The packet " + packetName.toUri() + " (KeyLocator=" +
              keyLocatorName.toUri() +
              ") does not match the hyper relation key name regex " +
              self._keyNameRegex.getExpr()))
            return False

        keyNameMatchExpansion = self._keyNameRegex.expand(self._keyNameExpansion)
        packetNameMatchExpansion = self._packetNameRegex.expand(
          self._packetNameExpansion)
        result = ConfigNameRelation.checkNameRelation(
          self._hyperRelation, keyNameMatchExpansion, packetNameMatchExpansion)
        if not result:
            state.fail(ValidationError(ValidationError.POLICY_ERROR,
              "KeyLocator check failed: hyper relation " +
              ConfigNameRelation.toString(self._hyperRelation) +
              " packet name match=" + packetNameMatchExpansion.toUri() +
              ", key name match=" + keyNameMatchExpansion.toUri() + " of packet " +
              packetName.toUri() + " (KeyLocator=" + keyLocatorName.toUri() +
              ") is invalid"))

        return result
Exemplo n.º 8
0
    def checkNames(self, packetName, keyLocatorName, state):
        """
        :param Name packetName:
        :param Name keyLocatorName:
        :param ValidationState state:
        :rtype: bool
        """
        # packetName is not used in this check.

        identity = PibKey.extractIdentityFromKeyName(keyLocatorName)
        result = ConfigNameRelation.checkNameRelation(self._relation,
                                                      self._name, identity)
        if not result:
            state.fail(
                ValidationError(
                    ValidationError.POLICY_ERROR,
                    "KeyLocator check failed: name relation " +
                    self._name.toUri() + " " +
                    ConfigNameRelation.toString(self._relation) +
                    " for packet " + packetName.toUri() +
                    " is invalid (KeyLocator=" + keyLocatorName.toUri() +
                    ", identity=" + identity.toUri() + ")"))

        return result
Exemplo n.º 9
0
    def _createKeyLocatorNameChecker(configSection):
        """
        :param BoostInfoTree configSection:
        :rtype: ConfigChecker
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            name = Name(nameUri)

            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(
                relationValue)
            return ConfigNameRelationChecker(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexChecker(regexString)
            except:
                raise ValidatorConfigError(
                    "Invalid checker.key-locator.regex: " + regexString)

        hyperRelationList = configSection["hyper-relation"]
        if len(hyperRelationList) == 1:
            hyperRelation = hyperRelationList[0]

            # Get k-regex.
            keyRegex = hyperRelation.getFirstValue("k-regex")
            if keyRegex == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.k-regex>")

            # Get k-expand.
            keyExpansion = hyperRelation.getFirstValue("k-expand")
            if keyExpansion == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.k-expand")

            # Get h-relation.
            hyperRelationString = hyperRelation.getFirstValue("h-relation")
            if hyperRelationString == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.h-relation>")

            # Get p-regex.
            packetNameRegex = hyperRelation.getFirstValue("p-regex")
            if packetNameRegex == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.p-regex>")

            # Get p-expand.
            packetNameExpansion = hyperRelation.getFirstValue("p-expand")
            if packetNameExpansion == None:
                raise ValidatorConfigError(
                    "Expected <checker.key-locator.hyper-relation.p-expand>")

            relation = ConfigNameRelation.getNameRelationFromString(
                hyperRelationString)

            try:
                return ConfigHyperRelationChecker(packetNameRegex,
                                                  packetNameExpansion,
                                                  keyRegex, keyExpansion,
                                                  relation)
            except:
                raise ValidatorConfigError(
                    "Invalid regex for key-locator.hyper-relation")

        raise ValidatorConfigError("Unsupported checker.key-locator")
Exemplo n.º 10
0
    def _createKeyLocatorNameChecker(configSection):
        """
        :param BoostInfoTree configSection:
        :rtype: ConfigChecker
        """
        nameUri = configSection.getFirstValue("name")
        if nameUri != None:
            name = Name(nameUri)

            relationValue = configSection.getFirstValue("relation")
            if relationValue == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.relation>")

            relation = ConfigNameRelation.getNameRelationFromString(relationValue)
            return ConfigNameRelationChecker(name, relation)

        regexString = configSection.getFirstValue("regex")
        if regexString != None:
            try:
                return ConfigRegexChecker(regexString)
            except:
                raise ValidatorConfigError(
                  "Invalid checker.key-locator.regex: " + regexString)

        hyperRelationList = configSection["hyper-relation"]
        if len(hyperRelationList) == 1:
            hyperRelation = hyperRelationList[0]

            # Get k-regex.
            keyRegex = hyperRelation.getFirstValue("k-regex")
            if keyRegex == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.k-regex>")

            # Get k-expand.
            keyExpansion = hyperRelation.getFirstValue("k-expand")
            if keyExpansion == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.k-expand")

            # Get h-relation.
            hyperRelationString = hyperRelation.getFirstValue("h-relation")
            if hyperRelationString == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.h-relation>")

            # Get p-regex.
            packetNameRegex = hyperRelation.getFirstValue("p-regex")
            if packetNameRegex == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.p-regex>")

            # Get p-expand.
            packetNameExpansion = hyperRelation.getFirstValue("p-expand")
            if packetNameExpansion == None:
                raise ValidatorConfigError(
                  "Expected <checker.key-locator.hyper-relation.p-expand>")

            relation = ConfigNameRelation.getNameRelationFromString(
              hyperRelationString)

            try:
                return ConfigHyperRelationChecker(
                  packetNameRegex, packetNameExpansion, keyRegex, keyExpansion,
                  relation)
            except:
                raise ValidatorConfigError(
                  "Invalid regex for key-locator.hyper-relation")

        raise ValidatorConfigError("Unsupported checker.key-locator")