Exemple #1
0
        /// <summary>
        /// This is a helper for create() to create a filter from the configuration
        /// section which is type "name".
        /// </summary>
        ///
        /// <param name="configSection">The section containing the definition of the filter.</param>
        /// <returns>A new filter created from the configuration section.</returns>
        private static ConfigFilter createNameFilter(BoostInfoTree configSection)
        {
            String nameUri = configSection.getFirstValue("name");

            if (nameUri != null)
            {
                // Get the filter.name.
                Name name = new Name(nameUri);

                // Get the filter.relation.
                String relationValue = configSection.getFirstValue("relation");
                if (relationValue == null)
                {
                    throw new ValidatorConfigError("Expected <filter.relation>");
                }

                ConfigNameRelation.Relation relation = net.named_data.jndn.security.v2.validator_config.ConfigNameRelation
                                                       .getNameRelationFromString(relationValue);

                return(new ConfigRelationNameFilter(name, relation));
            }

            String regexString = configSection.getFirstValue("regex");

            if (regexString != null)
            {
                try {
                    return(new ConfigRegexNameFilter(regexString));
                } catch (Exception e) {
                    throw new ValidatorConfigError("Wrong filter.regex: "
                                                   + regexString);
                }
            }

            throw new ValidatorConfigError("Wrong filter(name) properties");
        }
Exemple #2
0
        /// <summary>
        /// Create a filter from the configuration section.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <returns>A new filter created from the configuration section.</returns>
        public static ConfigFilter create(BoostInfoTree configSection)
        {
            String filterType = configSection.getFirstValue("type");

            if (filterType == null)
            {
                throw new ValidatorConfigError("Expected <filter.type>");
            }

            if (filterType.Equals("name", StringComparison.InvariantCultureIgnoreCase))
            {
                return(createNameFilter(configSection));
            }
            else
            {
                throw new ValidatorConfigError("Unsupported filter.type: "
                                               + filterType);
            }
        }
Exemple #3
0
        private static ConfigChecker createKeyLocatorChecker(
            BoostInfoTree configSection)
        {
            // Get checker.key-locator.type .
            String keyLocatorType = configSection.getFirstValue("type");

            if (keyLocatorType == null)
            {
                throw new ValidatorConfigError(
                          "Expected <checker.key-locator.type>");
            }

            if (keyLocatorType.Equals("name", StringComparison.InvariantCultureIgnoreCase))
            {
                return(createKeyLocatorNameChecker(configSection));
            }
            else
            {
                throw new ValidatorConfigError(
                          "Unsupported checker.key-locator.type: " + keyLocatorType);
            }
        }
Exemple #4
0
        /// <summary>
        /// Get the "refresh" value. If the value is 9, return a period of one hour.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <returns>The refresh period in milliseconds. However if there is no
        /// "refresh" value, return a large number (effectively no refresh).</returns>
        private static double getRefreshPeriod(BoostInfoTree configSection)
        {
            String refreshString = configSection.getFirstValue("refresh");

            if (refreshString == null)
            {
                // Return a large value (effectively no refresh).
                return(1e14d);
            }

            double  refreshSeconds = 0;
            Pattern regex1         = ILOG.J2CsMapping.Text.Pattern.Compile("(\\d+)([hms])");
            Matcher refreshMatch   = regex1.Matcher(refreshString);

            if (refreshMatch.Find())
            {
                refreshSeconds = Int32.Parse(refreshMatch.Group(1));
                if (!refreshMatch.Group(2).equals("s"))
                {
                    refreshSeconds *= 60;
                    if (!refreshMatch.Group(2).equals("m"))
                    {
                        refreshSeconds *= 60;
                    }
                }
            }

            if (refreshSeconds == 0.0d)
            {
                // Use an hour instead of 0.
                return(3600 * 1000.0d);
            }
            else
            {
                // Convert from seconds to milliseconds.
                return(refreshSeconds * 1000.0d);
            }
        }
Exemple #5
0
        /// <summary>
        /// Create a checker from the configuration section.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <returns>A new checker created from the configuration section.</returns>
        public static ConfigChecker create(BoostInfoTree configSection)
        {
            // Get checker.type.
            String checkerType = configSection.getFirstValue("type");

            if (checkerType == null)
            {
                throw new ValidatorConfigError("Expected <checker.type>");
            }

            if (checkerType.Equals("customized", StringComparison.InvariantCultureIgnoreCase))
            {
                return(createCustomizedChecker(configSection));
            }
            else if (checkerType.Equals("hierarchical", StringComparison.InvariantCultureIgnoreCase))
            {
                return(createHierarchicalChecker(configSection));
            }
            else
            {
                throw new ValidatorConfigError("Unsupported checker type: "
                                               + checkerType);
            }
        }
Exemple #6
0
        /// <summary>
        /// Create a rule from configuration section.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <returns>A new ConfigRule created from the configuration</returns>
        public static ConfigRule create(BoostInfoTree configSection)
        {
            // Get rule.id .
            String ruleId = configSection.getFirstValue("id");

            if (ruleId == null)
            {
                throw new ValidatorConfigError("Expecting <rule.id>");
            }

            // Get rule.for .
            String usage = configSection.getFirstValue("for");

            if (usage == null)
            {
                throw new ValidatorConfigError("Expecting <rule.for> in rule: "
                                               + ruleId);
            }

            bool isForInterest;

            if (usage.Equals("data", StringComparison.InvariantCultureIgnoreCase))
            {
                isForInterest = false;
            }
            else if (usage.Equals("interest", StringComparison.InvariantCultureIgnoreCase))
            {
                isForInterest = true;
            }
            else
            {
                throw new ValidatorConfigError("Unrecognized <rule.for>: " + usage
                                               + " in rule: " + ruleId);
            }

            ConfigRule rule = new ConfigRule(ruleId, isForInterest);

            // Get rule.filter(s)
            ArrayList <BoostInfoTree> filterList = configSection.get("filter");

            for (int i = 0; i < filterList.Count; ++i)
            {
                rule.addFilter(net.named_data.jndn.security.v2.validator_config.ConfigFilter.create(filterList[i]));
            }

            // Get rule.checker(s)
            ArrayList <BoostInfoTree> checkerList = configSection.get("checker");

            for (int i_0 = 0; i_0 < checkerList.Count; ++i_0)
            {
                rule.addChecker(net.named_data.jndn.security.v2.validator_config.ConfigChecker.create(checkerList[i_0]));
            }

            // Check other stuff.
            if (checkerList.Count == 0)
            {
                throw new ValidatorConfigError(
                          "No <rule.checker> is specified in rule: " + ruleId);
            }

            return(rule);
        }
Exemple #7
0
        private static ConfigChecker createKeyLocatorNameChecker(
            BoostInfoTree configSection)
        {
            String nameUri = configSection.getFirstValue("name");

            if (nameUri != null)
            {
                Name name = new Name(nameUri);

                String relationValue = configSection.getFirstValue("relation");
                if (relationValue == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <checker.key-locator.relation>");
                }

                ConfigNameRelation.Relation relation = net.named_data.jndn.security.v2.validator_config.ConfigNameRelation
                                                       .getNameRelationFromString(relationValue);
                return(new ConfigNameRelationChecker(name, relation));
            }

            String regexString = configSection.getFirstValue("regex");

            if (regexString != null)
            {
                try {
                    return(new ConfigRegexChecker(regexString));
                } catch (Exception e) {
                    throw new ValidatorConfigError(
                              "Invalid checker.key-locator.regex: " + regexString);
                }
            }

            ArrayList <BoostInfoTree> hyperRelationList = configSection
                                                          .get("hyper-relation");

            if (hyperRelationList.Count == 1)
            {
                BoostInfoTree hyperRelation = hyperRelationList[0];

                // Get k-regex.
                String keyRegex = hyperRelation.getFirstValue("k-regex");
                if (keyRegex == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <checker.key-locator.hyper-relation.k-regex>");
                }

                // Get k-expand.
                String keyExpansion = hyperRelation.getFirstValue("k-expand");
                if (keyExpansion == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <checker.key-locator.hyper-relation.k-expand");
                }

                // Get h-relation.
                String hyperRelationString = hyperRelation
                                             .getFirstValue("h-relation");
                if (hyperRelationString == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <checker.key-locator.hyper-relation.h-relation>");
                }

                // Get p-regex.
                String packetNameRegex = hyperRelation.getFirstValue("p-regex");
                if (packetNameRegex == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <checker.key-locator.hyper-relation.p-regex>");
                }

                // Get p-expand.
                String packetNameExpansion = hyperRelation
                                             .getFirstValue("p-expand");
                if (packetNameExpansion == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <checker.key-locator.hyper-relation.p-expand>");
                }

                ConfigNameRelation.Relation relation_0 = net.named_data.jndn.security.v2.validator_config.ConfigNameRelation
                                                         .getNameRelationFromString(hyperRelationString);

                try {
                    return(new ConfigHyperRelationChecker(packetNameRegex,
                                                          packetNameExpansion, keyRegex, keyExpansion, relation_0));
                } catch (Exception e_1) {
                    throw new ValidatorConfigError(
                              "Invalid regex for key-locator.hyper-relation");
                }
            }

            throw new ValidatorConfigError("Unsupported checker.key-locator");
        }
Exemple #8
0
        /// <summary>
        /// Process the trust-anchor configuration section and call
        /// validator_.loadAnchor as needed.
        /// </summary>
        ///
        /// <param name="configSection"></param>
        /// <param name="inputName">Used for log messages, etc.</param>
        private void processConfigTrustAnchor(BoostInfoTree configSection,
                                              String inputName)
        {
            String anchorType = configSection.getFirstValue("type");

            if (anchorType == null)
            {
                throw new ValidatorConfigError("Expected <trust-anchor.type>");
            }

            if (anchorType.Equals("file", StringComparison.InvariantCultureIgnoreCase))
            {
                // Get trust-anchor.file .
                String fileName = configSection.getFirstValue("file-name");
                if (fileName == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <trust-anchor.file-name>");
                }

                double refreshPeriod = getRefreshPeriod(configSection);
                try {
                    validator_.loadAnchor(fileName, fileName, refreshPeriod, false);
                } catch (TrustAnchorContainer.Error ex) {
                    throw new ValidatorConfigError("Error in loadAnchor: " + ex);
                }

                return;
            }
            else if (anchorType.Equals("base64", StringComparison.InvariantCultureIgnoreCase))
            {
                // Get trust-anchor.base64-string .
                String base64String = configSection.getFirstValue("base64-string");
                if (base64String == null)
                {
                    throw new ValidatorConfigError(
                              "Expected <trust-anchor.base64-string>");
                }

                byte[]        encoding    = net.named_data.jndn.util.Common.base64Decode(base64String);
                CertificateV2 certificate = new CertificateV2();
                try {
                    certificate.wireDecode(new Blob(encoding));
                } catch (Exception ex_0) {
                    throw new ValidatorConfigError(
                              "Cannot decode certificate from base64-string: " + ex_0);
                }
                try {
                    validator_.loadAnchor("", certificate);
                } catch (TrustAnchorContainer.Error ex_1) {
                    throw new ValidatorConfigError("Error in loadAnchor: " + ex_1);
                }

                return;
            }
            else if (anchorType.Equals("dir", StringComparison.InvariantCultureIgnoreCase))
            {
                // Get trust-anchor.dir .
                String dirString = configSection.getFirstValue("dir");
                if (dirString == null)
                {
                    throw new ValidatorConfigError("Expected <trust-anchor.dir>");
                }

                double refreshPeriod_2 = getRefreshPeriod(configSection);
                try {
                    validator_
                    .loadAnchor(dirString, dirString, refreshPeriod_2, true);
                } catch (TrustAnchorContainer.Error ex_3) {
                    throw new ValidatorConfigError("Error in loadAnchor: " + ex_3);
                }

                return;
            }
            else if (anchorType.Equals("any", StringComparison.InvariantCultureIgnoreCase))
            {
                shouldBypass_ = true;
            }
            else
            {
                throw new ValidatorConfigError("Unsupported trust-anchor.type");
            }
        }