internal static XmlNodeList AllDescendantNodes(XmlNode node, bool includeComments)
        {
            CanonicalXmlNodeList canonicalXmlNodeList1 = new CanonicalXmlNodeList();
            CanonicalXmlNodeList canonicalXmlNodeList2 = new CanonicalXmlNodeList();
            CanonicalXmlNodeList canonicalXmlNodeList3 = new CanonicalXmlNodeList();
            CanonicalXmlNodeList canonicalXmlNodeList4 = new CanonicalXmlNodeList();
            int index = 0;

            canonicalXmlNodeList2.Add((object)node);
            do
            {
                XmlNode     xmlNode1   = canonicalXmlNodeList2[index];
                XmlNodeList childNodes = xmlNode1.ChildNodes;
                if (childNodes != null)
                {
                    foreach (XmlNode xmlNode2 in childNodes)
                    {
                        if (includeComments || !(xmlNode2 is XmlComment))
                        {
                            canonicalXmlNodeList2.Add((object)xmlNode2);
                        }
                    }
                }
                if (xmlNode1.Attributes != null)
                {
                    foreach (XmlNode attribute in (XmlNamedNodeMap)xmlNode1.Attributes)
                    {
                        if (attribute.LocalName == "xmlns" || attribute.Prefix == "xmlns")
                        {
                            canonicalXmlNodeList4.Add((object)attribute);
                        }
                        else
                        {
                            canonicalXmlNodeList3.Add((object)attribute);
                        }
                    }
                }
                ++index;
            }while (index < canonicalXmlNodeList2.Count);
            foreach (XmlNode xmlNode in (XmlNodeList)canonicalXmlNodeList2)
            {
                canonicalXmlNodeList1.Add((object)xmlNode);
            }
            foreach (XmlNode xmlNode in (XmlNodeList)canonicalXmlNodeList3)
            {
                canonicalXmlNodeList1.Add((object)xmlNode);
            }
            foreach (XmlNode xmlNode in (XmlNodeList)canonicalXmlNodeList4)
            {
                canonicalXmlNodeList1.Add((object)xmlNode);
            }
            return((XmlNodeList)canonicalXmlNodeList1);
        }
Exemple #2
0
        private static void MarkInclusionStateForNodes(
            XmlNodeList nodeList,
            XmlDocument inputRoot,
            XmlDocument root)
        {
            CanonicalXmlNodeList canonicalXmlNodeList1 = new CanonicalXmlNodeList();
            CanonicalXmlNodeList canonicalXmlNodeList2 = new CanonicalXmlNodeList();

            canonicalXmlNodeList1.Add(inputRoot);
            canonicalXmlNodeList2.Add(root);
            int index1 = 0;

            do
            {
                XmlNode     xmlNode1    = canonicalXmlNodeList1[index1] ?? throw new InvalidOperationException();
                XmlNode     xmlNode2    = canonicalXmlNodeList2[index1] ?? throw new InvalidOperationException();
                XmlNodeList childNodes1 = xmlNode1.ChildNodes;
                XmlNodeList childNodes2 = xmlNode2.ChildNodes;
                for (int index2 = 0; index2 < childNodes1.Count; ++index2)
                {
                    canonicalXmlNodeList1.Add(childNodes1[index2]);
                    canonicalXmlNodeList2.Add(childNodes2[index2]);
                    if (Exml.NodeInList(childNodes1[index2], nodeList))
                    {
                        MarkNodeAsIncluded(childNodes2[index2]);
                    }
                    XmlAttributeCollection attributes = childNodes1[index2]?.Attributes;
                    if (attributes == null)
                    {
                        continue;
                    }

                    for (int index3 = 0; index3 < attributes.Count; ++index3)
                    {
                        if (Exml.NodeInList(attributes[index3], nodeList))
                        {
                            MarkNodeAsIncluded(childNodes2[index2]?.Attributes?.Item(index3));
                        }
                    }
                }
                ++index1;
            }while (index1 < canonicalXmlNodeList1.Count);
        }
Exemple #3
0
        private static void MarkInclusionStateForNodes(
            XmlNodeList nodeList,
            XmlDocument inputRoot,
            XmlDocument root)
        {
            CanonicalXmlNodeList canonicalXmlNodeList1 = new CanonicalXmlNodeList();
            CanonicalXmlNodeList canonicalXmlNodeList2 = new CanonicalXmlNodeList();

            canonicalXmlNodeList1.Add((object)inputRoot);
            canonicalXmlNodeList2.Add((object)root);
            int index1 = 0;

            do
            {
                XmlNode     xmlNode1    = canonicalXmlNodeList1[index1];
                XmlNode     xmlNode2    = canonicalXmlNodeList2[index1];
                XmlNodeList childNodes1 = xmlNode1.ChildNodes;
                XmlNodeList childNodes2 = xmlNode2.ChildNodes;
                for (int index2 = 0; index2 < childNodes1.Count; ++index2)
                {
                    canonicalXmlNodeList1.Add((object)childNodes1[index2]);
                    canonicalXmlNodeList2.Add((object)childNodes2[index2]);
                    if (Exml.NodeInList(childNodes1[index2], nodeList))
                    {
                        ExcCanonicalXml.MarkNodeAsIncluded(childNodes2[index2]);
                    }
                    XmlAttributeCollection attributes = childNodes1[index2].Attributes;
                    if (attributes != null)
                    {
                        for (int index3 = 0; index3 < attributes.Count; ++index3)
                        {
                            if (Exml.NodeInList((XmlNode)attributes[index3], nodeList))
                            {
                                ExcCanonicalXml.MarkNodeAsIncluded(childNodes2[index2].Attributes.Item(index3));
                            }
                        }
                    }
                }
                ++index1;
            }while (index1 < canonicalXmlNodeList1.Count);
        }
Exemple #4
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.Xml.DataObject" /> class with the specified identification, MIME type, encoding, and data.</summary>
 /// <param name="id">The identification to initialize the new instance of <see cref="T:System.Security.Cryptography.Xml.DataObject" /> with. </param>
 /// <param name="mimeType">The MIME type of the data used to initialize the new instance of <see cref="T:System.Security.Cryptography.Xml.DataObject" />. </param>
 /// <param name="encoding">The encoding of the data used to initialize the new instance of <see cref="T:System.Security.Cryptography.Xml.DataObject" />. </param>
 /// <param name="data">The data to initialize the new instance of <see cref="T:System.Security.Cryptography.Xml.DataObject" /> with. </param>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="data" /> parameter is <see langword="null" />. </exception>
 public DataObject(string id, string mimeType, string encoding, XmlElement data)
 {
     if (data == null)
     {
         throw new ArgumentNullException(nameof(data));
     }
     m_id       = id;
     m_mimeType = mimeType;
     m_encoding = encoding;
     m_elData   = new CanonicalXmlNodeList();
     m_elData.Add((object)data);
     m_cachedXml = (XmlElement)null;
 }
Exemple #5
0
 /// <summary>Loads a <see cref="T:System.Security.Cryptography.Xml.DataObject" /> state from an XML element.</summary>
 /// <param name="value">The XML element to load the <see cref="T:System.Security.Cryptography.Xml.DataObject" /> state from. </param>
 /// <exception cref="T:System.ArgumentNullException">The value from the XML element is <see langword="null" />.</exception>
 public void LoadXml(XmlElement value)
 {
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     m_id       = Exml.GetAttribute(value, "Id", "http://www.w3.org/2000/09/xmldsig#");
     m_mimeType = Exml.GetAttribute(value, "MimeType", "http://www.w3.org/2000/09/xmldsig#");
     m_encoding = Exml.GetAttribute(value, "Encoding", "http://www.w3.org/2000/09/xmldsig#");
     foreach (XmlNode childNode in value.ChildNodes)
     {
         m_elData.Add((object)childNode);
     }
     m_cachedXml = value;
 }
Exemple #6
0
        public static CanonicalXmlNodeList GetPropagatedAttributes(XmlElement elem)
        {
            if (elem == null)
            {
                return((CanonicalXmlNodeList)null);
            }
            CanonicalXmlNodeList canonicalXmlNodeList = new CanonicalXmlNodeList();
            XmlNode xmlNode = (XmlNode)elem;

            if (xmlNode == null)
            {
                return((CanonicalXmlNodeList)null);
            }
            bool flag = true;

            while (xmlNode != null)
            {
                XmlElement element = xmlNode as XmlElement;
                if (element == null)
                {
                    xmlNode = xmlNode.ParentNode;
                }
                else
                {
                    if (!IsCommittedNamespace(element, element.Prefix, element.NamespaceURI) && !IsRedundantNamespace(element, element.Prefix, element.NamespaceURI))
                    {
                        string       name      = element.Prefix.Length > 0 ? "xmlns:" + element.Prefix : "xmlns";
                        XmlAttribute attribute = elem.OwnerDocument.CreateAttribute(name);
                        attribute.Value = element.NamespaceURI;
                        canonicalXmlNodeList.Add((object)attribute);
                    }
                    if (element.HasAttributes)
                    {
                        foreach (XmlAttribute attribute1 in (XmlNamedNodeMap)element.Attributes)
                        {
                            if (flag && attribute1.LocalName == "xmlns")
                            {
                                XmlAttribute attribute2 = elem.OwnerDocument.CreateAttribute("xmlns");
                                attribute2.Value = attribute1.Value;
                                canonicalXmlNodeList.Add((object)attribute2);
                                flag = false;
                            }
                            else if (attribute1.Prefix == "xmlns" || attribute1.Prefix == "xml")
                            {
                                canonicalXmlNodeList.Add((object)attribute1);
                            }
                            else if (attribute1.NamespaceURI.Length > 0 &&
                                     !IsCommittedNamespace(element, attribute1.Prefix, attribute1.NamespaceURI) &&
                                     !IsRedundantNamespace(element, attribute1.Prefix, attribute1.NamespaceURI))
                            {
                                string       name       = attribute1.Prefix.Length > 0 ? "xmlns:" + attribute1.Prefix : "xmlns";
                                XmlAttribute attribute2 = elem.OwnerDocument.CreateAttribute(name);
                                attribute2.Value = attribute1.NamespaceURI;
                                canonicalXmlNodeList.Add((object)attribute2);
                            }
                        }
                    }
                    xmlNode = xmlNode.ParentNode;
                }
            }
            return(canonicalXmlNodeList);
        }
        /// <summary>Returns the output of the current <see cref="T:System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform" /> object.</summary>
        /// <returns>The output of the current <see cref="T:System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform" /> object.</returns>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">The containing XML document is <see langword="null" />.</exception>
        public override object GetOutput()
        {
            if (_containingDocument == null)
            {
                throw new CryptographicException("Cryptography error: XML enveloped signature requires context");
            }
            if (_inputNodeList != null)
            {
                if (_signaturePosition == 0)
                {
                    return((object)_inputNodeList);
                }
                XmlNodeList xmlNodeList = _containingDocument.SelectNodes("//dsig:Signature", _nsm);
                if (xmlNodeList == null)
                {
                    return((object)_inputNodeList);
                }
                CanonicalXmlNodeList canonicalXmlNodeList = new CanonicalXmlNodeList();
                foreach (XmlNode inputNode in _inputNodeList)
                {
                    if (inputNode != null)
                    {
                        if (!IsXmlNamespaceNode(inputNode))
                        {
                            if (!IsNamespaceNode(inputNode))
                            {
                                try
                                {
                                    XmlNode xmlNode1 = inputNode.SelectSingleNode("ancestor-or-self::dsig:Signature[1]", _nsm);
                                    int     num      = 0;
                                    foreach (XmlNode xmlNode2 in xmlNodeList)
                                    {
                                        ++num;
                                        if (xmlNode2 == xmlNode1)
                                        {
                                            break;
                                        }
                                    }
                                    if (xmlNode1 != null)
                                    {
                                        if (xmlNode1 != null)
                                        {
                                            if (num == _signaturePosition)
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            continue;
                                        }
                                    }
                                    canonicalXmlNodeList.Add((object)inputNode);
                                    continue;
                                }
                                catch
                                {
                                    continue;
                                }
                            }
                        }
                        canonicalXmlNodeList.Add((object)inputNode);
                    }
                }
                return((object)canonicalXmlNodeList);
            }
            XmlNodeList xmlNodeList1 = _containingDocument.SelectNodes("//dsig:Signature", _nsm);

            if (xmlNodeList1 == null)
            {
                return((object)_containingDocument);
            }
            if (xmlNodeList1.Count < _signaturePosition || _signaturePosition <= 0)
            {
                return((object)_containingDocument);
            }
            xmlNodeList1[_signaturePosition - 1].ParentNode.RemoveChild(xmlNodeList1[_signaturePosition - 1]);
            return((object)_containingDocument);
        }