/// <summary> /// Load the configuration from the given configSection. This replaces any /// existing configuration. /// </summary> /// /// <param name="configSection"></param> /// <param name="inputName">Used for log messages, etc.</param> public void load(BoostInfoTree configSection, String inputName) { if (isConfigured_) { // Reset the previous configuration. shouldBypass_ = false; ILOG.J2CsMapping.Collections.Collections.Clear(dataRules_); ILOG.J2CsMapping.Collections.Collections.Clear(interestRules_); validator_.resetAnchors(); validator_.resetVerifiedCertificates(); } isConfigured_ = true; ArrayList <BoostInfoTree> validatorList = configSection.get("validator"); if (validatorList.Count != 1) { throw new ValidatorConfigError( "ValidationPolicyConfig: Expected one validator section"); } BoostInfoTree validatorSection = validatorList[0]; // Get the rules. ArrayList <BoostInfoTree> ruleList = validatorSection.get("rule"); for (int i = 0; i < ruleList.Count; ++i) { ConfigRule rule = net.named_data.jndn.security.v2.validator_config.ConfigRule.create(ruleList[i]); if (rule.getIsForInterest()) { ILOG.J2CsMapping.Collections.Collections.Add(interestRules_, rule); } else { ILOG.J2CsMapping.Collections.Collections.Add(dataRules_, rule); } } // Get the trust anchors. ArrayList <BoostInfoTree> trustAnchorList = validatorSection .get("trust-anchor"); for (int i_0 = 0; i_0 < trustAnchorList.Count; ++i_0) { processConfigTrustAnchor(trustAnchorList[i_0], inputName); } }
private static ConfigChecker createCustomizedChecker( BoostInfoTree configSection) { // Ignore sig-type. // Get checker.key-locator . ArrayList <BoostInfoTree> keyLocatorSection = configSection .get("key-locator"); if (keyLocatorSection.Count != 1) { throw new ValidatorConfigError("Expected one <checker.key-locator>"); } return(createKeyLocatorChecker(keyLocatorSection[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); }
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"); }