From 549305799aa8cb653d55c27346d231a209f4518c Mon Sep 17 00:00:00 2001 From: "ARTECH\\sgrampone" Date: Tue, 2 Feb 2021 18:15:58 -0300 Subject: [PATCH] Fix XmlSignature search ID --- .../GeneXusXmlSignature.csproj | 3 + .../Utils/SignatureUtils.cs | 92 ++++++++++++++++--- 2 files changed, 82 insertions(+), 13 deletions(-) diff --git a/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj b/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj index f8e0531..353fc74 100644 --- a/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj +++ b/dotnet/dotnetframework/GeneXusXmlSignature/GeneXusXmlSignature.csproj @@ -37,6 +37,9 @@ prompt 4 + + + diff --git a/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureUtils.cs b/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureUtils.cs index f6769cd..687f8f7 100644 --- a/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureUtils.cs +++ b/dotnet/dotnetframework/GeneXusXmlSignature/Utils/SignatureUtils.cs @@ -150,7 +150,38 @@ internal static bool validateExtensionSchema(string path) } - internal static XmlNode getNodeFromID(XmlDocument doc, string id, string xPath, Error error) + /* internal static XmlNode getNodeFromID(XmlDocument doc, string id, string xPath, Error error) + { + if (id == null || SecurityUtils.compareStrings(id, "")) + { + error.setError("SU010", "Error, id data is empty"); + return null; + } + string idToFind = xPath.Substring(1); + XmlNode rootNode = doc.DocumentElement; + XmlNodeList allNodes = rootNode.ChildNodes; + foreach (XmlNode node in allNodes) + { + + XmlAttributeCollection attributes = node.Attributes; + if (attributes != null) + { + foreach (XmlAttribute attribute in node.Attributes) + { + if (SecurityUtils.compareStrings(attribute.Name, id) && SecurityUtils.compareStrings(attribute.Value, idToFind)) + { + return node; + } + } + } + + + } + error.setError("SU009", "Could not found element attribute " + id + " with id: " + idToFind); + return null; + }*/ + + internal static XmlNode getNodeFromID(XmlDocument doc, String id, String xPath, Error error) { if (id == null || SecurityUtils.compareStrings(id, "")) { @@ -158,29 +189,64 @@ internal static XmlNode getNodeFromID(XmlDocument doc, string id, string xPath, return null; } string idToFind = xPath.Substring(1); - XmlNode rootNode = doc.DocumentElement; - XmlNodeList allNodes = rootNode.ChildNodes; - foreach (XmlNode node in allNodes) + XmlNode root = doc.DocumentElement; + XmlNodeList allNodes = root.ChildNodes; + + XmlNode n = RecursivegetNodeFromID(allNodes, id, idToFind); + if (n == null) { + error.setError("SU009", "Could not find element with id " + idToFind); + } + return n; - XmlAttributeCollection attributes = node.Attributes; - if (attributes != null) + } + + private static XmlNode FindAttribute(XmlNode node, String id, String idToFind) + { + XmlAttributeCollection attributes = node.Attributes; + if (attributes != null) + { + foreach (XmlAttribute attribute in node.Attributes) { - foreach (XmlAttribute attribute in node.Attributes) + if (SecurityUtils.compareStrings(attribute.Name, id) && SecurityUtils.compareStrings(attribute.Value, idToFind)) { - if (SecurityUtils.compareStrings(attribute.Name, id) && SecurityUtils.compareStrings(attribute.Value, idToFind)) + return node; + } + } + } + return null; + } + + private static XmlNode RecursivegetNodeFromID(XmlNodeList list, String id, String idToFind) + { + if (list.Count == 0) + { + return null; + } + else + { + for (int i = 0; i < list.Count; i++) + { + XmlNode node = FindAttribute(list.Item(i), id, idToFind); + if (node == null) + { + XmlNode n1 = RecursivegetNodeFromID(list.Item(i).ChildNodes, id, idToFind); + if (n1 != null) { - return node; + return n1; } } + else + { + return node; + } } - - + return null; } - error.setError("SU009", "Could not found element attribute " + id + " with id: " + idToFind); - return null; } + + internal static string getIDNodeValue(XmlDocument doc) { doc.PreserveWhitespace = true;