public BoostInfoTree() { this.subtrees_ = new ArrayList<TreeEntry>(); this.value_ = ""; this.parent_ = null; this.lastChild_ = null; }
/// <summary> /// Create a new BoostInfoTree and insert it as a sub-tree with the given name. /// </summary> /// /// <param name="treeName">The name of the new sub-tree.</param> /// <param name="value">The value associated with the new sub-tree.</param> /// <returns>The created sub-tree.</returns> public BoostInfoTree createSubtree(String treeName, String value_ren) { BoostInfoTree newTree = new BoostInfoTree(value_ren, this); addSubtree(treeName, newTree); return(newTree); }
public BoostInfoTree(String value_ren, BoostInfoTree parent) { this.subtrees_ = new ArrayList <TreeEntry>(); this.value_ = ""; this.parent_ = null; this.lastChild_ = null; value_ = value_ren; parent_ = parent; }
public BoostInfoTree(String value_ren, BoostInfoTree parent) { this.subtrees_ = new ArrayList<TreeEntry>(); this.value_ = ""; this.parent_ = null; this.lastChild_ = null; value_ = value_ren; parent_ = parent; }
/// <summary> /// Internal import method with an explicit context node. /// </summary> /// /// <param name="stream">The stream for reading the INFO content.</param> /// <param name="ctx">The node currently being populated.</param> /// <returns>The ctx.</returns> private BoostInfoTree read(TextReader stream, BoostInfoTree ctx) { String line = null; while ((line = stream.readLine()) != null) { ctx = parseLine(line.trim(), ctx); } return(ctx); }
/// <summary> /// Insert a BoostInfoTree as a sub-tree with the given name. /// </summary> /// /// <param name="treeName">The name of the new sub-tree.</param> /// <param name="newTree">The sub-tree to add.</param> public void addSubtree(String treeName, BoostInfoTree newTree) { ArrayList subtreeList = find(treeName); if (subtreeList != null) ILOG.J2CsMapping.Collections.Collections.Add(subtreeList,newTree); else { BoostInfoTree.TreeEntry entry = new BoostInfoTree.TreeEntry (treeName); ILOG.J2CsMapping.Collections.Collections.Add(subtrees_,entry); ILOG.J2CsMapping.Collections.Collections.Add(entry.subtreeList_,newTree); } newTree.parent_ = this; lastChild_ = newTree; }
/// <summary> /// Look up using the key and return a list of the subtrees. /// </summary> /// /// <param name="key">The key which may be a path separated with '/'.</param> /// <returns>A new ArrayList of BoostInfoTree which are the subtrees.</returns> public ArrayList get(String key) { ArrayList foundVals = new ArrayList(); // Strip beginning '/'. key = ILOG.J2CsMapping.Util.StringUtil.ReplaceFirst(key, "^/+", ""); if (key.Length == 0) { ILOG.J2CsMapping.Collections.Collections.Add(foundVals, this); return(foundVals); } String[] path = ILOG.J2CsMapping.Text.RegExUtil.Split(key, "/"); ArrayList subtrees = find(path[0]); if (subtrees == null) { return(foundVals); } if (path.Length == 1) { return((ArrayList)subtrees.Clone()); } // newPath = path.slice(1).join('/') // Implement manually because older Java versions don't have join. String newPath = ""; for (int i = 1; i < path.Length; ++i) { if (i > 1) { newPath += "/"; } newPath += path[i]; } for (int i_0 = 0; i_0 < subtrees.Count; ++i_0) { BoostInfoTree t = (BoostInfoTree)subtrees[i_0]; ArrayList partial = t.get(newPath); foundVals.AddRange(partial); } return(foundVals); }
/// <summary> /// Insert a BoostInfoTree as a sub-tree with the given name. /// </summary> /// /// <param name="treeName">The name of the new sub-tree.</param> /// <param name="newTree">The sub-tree to add.</param> public void addSubtree(String treeName, BoostInfoTree newTree) { ArrayList subtreeList = find(treeName); if (subtreeList != null) { ILOG.J2CsMapping.Collections.Collections.Add(subtreeList, newTree); } else { BoostInfoTree.TreeEntry entry = new BoostInfoTree.TreeEntry(treeName); ILOG.J2CsMapping.Collections.Collections.Add(subtrees_, entry); ILOG.J2CsMapping.Collections.Collections.Add(entry.subtreeList_, newTree); } newTree.parent_ = this; lastChild_ = newTree; }
public BoostInfoParser() { this.root_ = new BoostInfoTree(); }
/// <summary> /// Internal import method with an explicit context node. /// </summary> /// /// <param name="stream">The stream for reading the INFO content.</param> /// <param name="ctx">The node currently being populated.</param> /// <returns>The ctx.</returns> private BoostInfoTree read(TextReader stream, BoostInfoTree ctx) { String line = null; while ((line = stream.readLine()) != null) ctx = parseLine(line.trim(), ctx); return ctx; }
/// <summary> /// Internal helper method for parsing INFO files line by line. /// </summary> /// private BoostInfoTree parseLine(String line, BoostInfoTree context) { // Skip blank lines and comments. int commentStart = line.indexOf(';'); if (commentStart >= 0) line = line.Substring(0,(commentStart)-(0)).trim(); if (line.Length == 0) return context; // Usually we are expecting key and optional value. // Use ArrayList without generics so it works with older Java compilers. ArrayList<String> strings = new ArrayList<String>(); shlex_split(line, strings); bool isSectionStart = false; bool isSectionEnd = false; for (int i = 0; i < strings.Count; ++i) { isSectionStart = (isSectionStart || "{".equals(strings[i])); isSectionEnd = (isSectionEnd || "}".equals(strings[i])); } if (!isSectionStart && !isSectionEnd) { String key = strings[0]; String val = ""; if (strings.Count > 1) val = strings[1]; // If it is an "#include", load the new file instead of inserting keys. if ("#include".equals(key)) { TextReader stream = new FileReader(val); // Use "try/finally instead of "try-with-resources" or "using" // which are not supported before Java 7. try { context = read(stream, context); } finally { stream.close(); } } else context.createSubtree(key, val); return context; } // OK, who is the joker who put a { on the same line as the key name?! int sectionStart = line.indexOf('{'); if (sectionStart > 0) { String firstPart = line.Substring(0,(sectionStart)-(0)); String secondPart = line.Substring(sectionStart); BoostInfoTree ctx = parseLine(firstPart, context); return parseLine(secondPart, ctx); } // If we encounter a {, we are beginning a new context. // TODO: Error if there was already a subcontext here. if (line[0] == '{') { context = context.getLastChild(); return context; } // If we encounter a }, we are ending a list context. if (line[0] == '}') { context = context.getParent(); return context; } throw new Exception("BoostInfoParser: input line is malformed"); }
/// <summary> /// Internal helper method for parsing INFO files line by line. /// </summary> /// private BoostInfoTree parseLine(String line, BoostInfoTree context) { // Skip blank lines and comments. int commentStart = line.indexOf(';'); if (commentStart >= 0) { line = line.Substring(0, (commentStart) - (0)).trim(); } if (line.Length == 0) { return(context); } // Usually we are expecting key and optional value. // Use ArrayList without generics so it works with older Java compilers. ArrayList <String> strings = new ArrayList <String>(); shlex_split(line, strings); bool isSectionStart = false; bool isSectionEnd = false; for (int i = 0; i < strings.Count; ++i) { isSectionStart = (isSectionStart || "{".equals(strings[i])); isSectionEnd = (isSectionEnd || "}".equals(strings[i])); } if (!isSectionStart && !isSectionEnd) { String key = strings[0]; String val = ""; if (strings.Count > 1) { val = strings[1]; } // If it is an "#include", load the new file instead of inserting keys. if ("#include".equals(key)) { TextReader stream = new FileReader(val); // Use "try/finally instead of "try-with-resources" or "using" // which are not supported before Java 7. try { context = read(stream, context); } finally { stream.close(); } } else { context.createSubtree(key, val); } return(context); } // OK, who is the joker who put a { on the same line as the key name?! int sectionStart = line.indexOf('{'); if (sectionStart > 0) { String firstPart = line.Substring(0, (sectionStart) - (0)); String secondPart = line.Substring(sectionStart); BoostInfoTree ctx = parseLine(firstPart, context); return(parseLine(secondPart, ctx)); } // If we encounter a {, we are beginning a new context. // TODO: Error if there was already a subcontext here. if (line[0] == '{') { context = context.getLastChild(); return(context); } // If we encounter a }, we are ending a list context. if (line[0] == '}') { context = context.getParent(); return(context); } throw new Exception("BoostInfoParser: input line is malformed"); }
/// <summary> /// Once a rule is found to match data or a signed interest, the name in the /// KeyLocator must satisfy the condition in the 'checker' section of the rule, /// else the data or interest is rejected. /// </summary> /// /// <param name="signatureName">The certificate name from the KeyLocator.</param> /// <param name="objectName">components.</param> /// <param name="rule"></param> /// <param name="failureReason"></param> /// <returns>True if matches.</returns> private bool checkSignatureMatch(Name signatureName, Name objectName, BoostInfoTree rule, String[] failureReason) { BoostInfoTree checker = (BoostInfoTree) rule.get("checker")[0]; String checkerType = checker.getFirstValue("type"); if (checkerType.equals("fixed-signer")) { BoostInfoTree signerInfo = (BoostInfoTree) checker.get("signer")[0]; String signerType = signerInfo.getFirstValue("type"); Certificate cert = null; if (signerType.equals("file")) { cert = lookupCertificate(signerInfo.getFirstValue("file-name"), true); if (cert == null) { failureReason[0] = "Can't find fixed-signer certificate file: " + signerInfo.getFirstValue("file-name"); return false; } } else if (signerType.equals("base64")) { cert = lookupCertificate( signerInfo.getFirstValue("base64-string"), false); if (cert == null) { failureReason[0] = "Can't find fixed-signer certificate base64: " + signerInfo.getFirstValue("base64-string"); return false; } } else { failureReason[0] = "Unrecognized fixed-signer signerType: " + signerType; return false; } if (cert.getName().equals(signatureName)) return true; else { failureReason[0] = "fixed-signer cert name \"" + cert.getName().toUri() + "\" does not equal signatureName \"" + signatureName.toUri() + "\""; return false; } } else if (checkerType.equals("hierarchical")) { // This just means the data/interest name has the signing identity as a prefix. // That means everything before "ksk-?" in the key name. String identityRegex = "^([^<KEY>]*)<KEY>(<>*)<ksk-.+><ID-CERT>"; Matcher identityMatch = net.named_data.jndn.util.NdnRegexMatcher.match(identityRegex, signatureName); if (identityMatch != null) { Name identityPrefix = new Name(identityMatch.Group(1)) .append(new Name(identityMatch.Group(2))); if (matchesRelation(objectName, identityPrefix, "is-prefix-of")) return true; else { failureReason[0] = "The hierarchical objectName \"" + objectName.toUri() + "\" is not a prefix of \"" + identityPrefix + "\""; return false; } } else { failureReason[0] = "The hierarchical identityRegex \"" + identityRegex + "\" does not match signatureName \"" + signatureName.toUri() + "\""; return false; } } else if (checkerType.equals("customized")) { BoostInfoTree keyLocatorInfo = (BoostInfoTree) checker.get( "key-locator")[0]; // Not checking type - only name is supported. // Is this a simple relation? String simpleRelationType = keyLocatorInfo .getFirstValue("relation"); if (simpleRelationType != null) { Name matchName = new Name(keyLocatorInfo.getFirstValue("name")); if (matchesRelation(signatureName, matchName, simpleRelationType)) return true; else { failureReason[0] = "The custom signatureName \"" + signatureName.toUri() + "\" does not match matchName \"" + matchName.toUri() + "\" using relation " + simpleRelationType; return false; } } // Is this a simple regex? String simpleKeyRegex = keyLocatorInfo.getFirstValue("regex"); if (simpleKeyRegex != null) { if (net.named_data.jndn.util.NdnRegexMatcher.match(simpleKeyRegex, signatureName) != null) return true; else { failureReason[0] = "The custom signatureName \"" + signatureName.toUri() + "\" does not regex match simpleKeyRegex \"" + simpleKeyRegex + "\""; return false; } } // Is this a hyper-relation? ArrayList hyperRelationList = keyLocatorInfo.get("hyper-relation"); if (hyperRelationList.Count >= 1) { BoostInfoTree hyperRelation = (BoostInfoTree) hyperRelationList[0]; String keyRegex = hyperRelation.getFirstValue("k-regex"); String keyExpansion = hyperRelation.getFirstValue("k-expand"); String nameRegex = hyperRelation.getFirstValue("p-regex"); String nameExpansion = hyperRelation.getFirstValue("p-expand"); String relationType = hyperRelation.getFirstValue("h-relation"); if (keyRegex != null && keyExpansion != null && nameRegex != null && nameExpansion != null && relationType != null) { Matcher keyMatch = net.named_data.jndn.util.NdnRegexMatcher.match(keyRegex, signatureName); if (keyMatch == null || keyMatch.groupCount() < 1) { failureReason[0] = "The custom hyper-relation signatureName \"" + signatureName.toUri() + "\" does not match the keyRegex \"" + keyRegex + "\""; return false; } String keyMatchPrefix = expand(keyMatch, keyExpansion); Matcher nameMatch = net.named_data.jndn.util.NdnRegexMatcher.match(nameRegex, objectName); if (nameMatch == null || nameMatch.groupCount() < 1) { failureReason[0] = "The custom hyper-relation objectName \"" + objectName.toUri() + "\" does not match the nameRegex \"" + nameRegex + "\""; return false; } String nameMatchStr = expand(nameMatch, nameExpansion); if (matchesRelation(new Name(nameMatchStr), new Name( keyMatchPrefix), relationType)) return true; else { failureReason[0] = "The custom hyper-relation nameMatch \"" + nameMatchStr + "\" does not match the keyMatchPrefix \"" + keyMatchPrefix + "\" using relation " + relationType; return false; } } } } failureReason[0] = "Unrecognized checkerType: " + checkerType; return false; }
public override bool checkSignatureMatch(ConfigPolicyManager policyManager, Name signatureName, Name objectName, BoostInfoTree rule, String[] failureReason) { return policyManager.checkSignatureMatch(signatureName, objectName, rule, failureReason); }
public abstract bool checkSignatureMatch( ConfigPolicyManager policyManager, Name signatureName, Name objectName, BoostInfoTree rule, String[] failureReason);
/// <summary> /// Create a new BoostInfoTree and insert it as a sub-tree with the given name. /// </summary> /// /// <param name="treeName">The name of the new sub-tree.</param> /// <param name="value">The value associated with the new sub-tree.</param> /// <returns>The created sub-tree.</returns> public BoostInfoTree createSubtree(String treeName, String value_ren) { BoostInfoTree newTree = new BoostInfoTree(value_ren, this); addSubtree(treeName, newTree); return newTree; }