From 7ede70ad8e444a57fb56a2627cae2b0061d8f22e Mon Sep 17 00:00:00 2001 From: Vladimir Kazakov Date: Sun, 2 Jul 2017 13:31:33 +0300 Subject: [PATCH] XMLDSIG transforms from .NET Core. --- external/api-snapshot | 2 +- .../RSACertificateExtensions.cs | 7 +- mcs/class/System.Security/Makefile | 6 +- .../Mono.Xml/XmlCanonicalizer.cs | 680 ------------------ .../EncryptedReference.cs | 18 +- .../Reference.cs | 229 ------ .../SignedXml.cs | 91 ++- .../Transform.cs | 132 ---- .../TransformChain.cs | 62 -- .../XmlDecryptionTransform.cs | 194 ----- .../XmlDsigBase64Transform.cs | 131 ---- .../XmlDsigC14NTransform.cs | 144 ---- .../XmlDsigC14NWithCommentsTransform.cs | 40 -- .../XmlDsigEnvelopedSignatureTransform.cs | 170 ----- .../XmlDsigExcC14NTransform.cs | 162 ----- .../XmlDsigExcC14NWithCommentsTransform.cs | 49 -- .../XmlDsigNodeList.cs | 65 -- .../XmlDsigXPathTransform.cs | 288 -------- .../XmlDsigXsltTransform.cs | 155 ---- .../XmlLicenseTransform.cs | 100 --- .../XmlSignature.cs | 13 - .../XmlSignatureStreamReader.cs | 131 ---- .../System.Security.dll.sources | 64 +- .../ReferenceTest.cs | 23 +- .../SignedXmlTest.cs | 1 + .../XmlDsigC14NTransformTest.cs | 20 +- .../XmlDsigExcC14NTransformTest.cs | 6 +- mcs/class/System.Security/corefx/SR.cs | 1 + 28 files changed, 139 insertions(+), 2845 deletions(-) delete mode 100644 mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/Reference.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/TransformChain.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDecryptionTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigBase64Transform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NWithCommentsTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigNodeList.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXPathTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXsltTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlLicenseTransform.cs delete mode 100644 mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignatureStreamReader.cs diff --git a/external/api-snapshot b/external/api-snapshot index 5acca29bffe..19a53f6a975 160000 --- a/external/api-snapshot +++ b/external/api-snapshot @@ -1 +1 @@ -Subproject commit 5acca29bffe90d312372d744999b5d985113afd9 +Subproject commit 19a53f6a9755c918483221f252e9f7d8b799ce59 diff --git a/mcs/class/System.Core/System.Security.Cryptography.X509Certificates/RSACertificateExtensions.cs b/mcs/class/System.Core/System.Security.Cryptography.X509Certificates/RSACertificateExtensions.cs index 81c303bd091..a61b9f66ca2 100644 --- a/mcs/class/System.Core/System.Security.Cryptography.X509Certificates/RSACertificateExtensions.cs +++ b/mcs/class/System.Core/System.Security.Cryptography.X509Certificates/RSACertificateExtensions.cs @@ -28,7 +28,12 @@ namespace System.Security.Cryptography.X509Certificates { - public static class RSACertificateExtensions +#if SYSTEM_SECURITY_DLL + internal +#else + public +#endif + static class RSACertificateExtensions { public static RSA GetRSAPrivateKey(this X509Certificate2 certificate) { diff --git a/mcs/class/System.Security/Makefile b/mcs/class/System.Security/Makefile index 8602d8ff40a..a1b0b9fe5f0 100644 --- a/mcs/class/System.Security/Makefile +++ b/mcs/class/System.Security/Makefile @@ -9,9 +9,9 @@ endif LIBRARY = System.Security.dll LIB_REFS = secxml/System bare/System.Xml $(MONO_SECURITY) -LIB_MCS_FLAGS = -nowarn:618 \ - -d:SECURITY_DEP \ - -nowarn:414 +LIB_MCS_FLAGS = \ + -nowarn:414,618 \ + -d:SECURITY_DEP,SYSTEM_SECURITY_DLL LOCAL_MCS_FLAGS = diff --git a/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs b/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs deleted file mode 100644 index 8f0ec973539..00000000000 --- a/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs +++ /dev/null @@ -1,680 +0,0 @@ -// -// XmlCanonicalizer.cs - C14N implementation for XML Signature -// http://www.w3.org/TR/xml-c14n -// -// Author: -// Aleksey Sanin (aleksey@aleksey.com) -// -// (C) 2003 Aleksey Sanin (aleksey@aleksey.com) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -using System; -using System.Collections; -using System.IO; -using System.Text; -using System.Xml; - -namespace Mono.Xml { - - internal class XmlCanonicalizer { - - private enum XmlCanonicalizerState - { - BeforeDocElement, - InsideDocElement, - AfterDocElement - } - - // c14n parameters - private bool comments; - private bool exclusive; - string inclusiveNamespacesPrefixList; - - // input/output - private XmlNodeList xnl; - private StringBuilder res; - - // namespaces rendering stack - private XmlCanonicalizerState state; - private ArrayList visibleNamespaces; - private int prevVisibleNamespacesStart; - private int prevVisibleNamespacesEnd; - private Hashtable propagatedNss; - - public XmlCanonicalizer (bool withComments, bool excC14N, Hashtable propagatedNamespaces) - { - res = new StringBuilder (); - comments = withComments; - exclusive = excC14N; - propagatedNss = propagatedNamespaces; - } - - void Initialize () - { - state = XmlCanonicalizerState.BeforeDocElement; - visibleNamespaces = new ArrayList (); - prevVisibleNamespacesStart = 0; - prevVisibleNamespacesEnd = 0; - res.Length = 0; - } - - public Stream Canonicalize (XmlDocument doc) - { - if (doc == null) - throw new ArgumentNullException ("doc"); - Initialize (); - - FillMissingPrefixes (doc, new XmlNamespaceManager (doc.NameTable), new ArrayList ()); - WriteDocumentNode (doc); - - UTF8Encoding utf8 = new UTF8Encoding (); - byte[] data = utf8.GetBytes (res.ToString ()); - return new MemoryStream (data); - } - - public Stream Canonicalize (XmlNodeList nodes) - { - xnl = nodes; - if (nodes == null || nodes.Count < 1) - return new MemoryStream (); - XmlNode n = nodes [0]; - return Canonicalize (n.NodeType == XmlNodeType.Document ? n as XmlDocument : n.OwnerDocument); - } - - // See xml-enc-c14n specification - public string InclusiveNamespacesPrefixList { - get { return inclusiveNamespacesPrefixList; } - set { inclusiveNamespacesPrefixList = value; } - } - - XmlAttribute CreateXmlns (XmlNode n) - { - XmlAttribute a = n.Prefix.Length == 0 ? - n.OwnerDocument.CreateAttribute ("xmlns", "http://www.w3.org/2000/xmlns/") : - n.OwnerDocument.CreateAttribute ("xmlns", n.Prefix, "http://www.w3.org/2000/xmlns/"); - a.Value = n.NamespaceURI; - return a; - } - - // Note that this must be done *before* filtering nodes out - // by context node list. - private void FillMissingPrefixes (XmlNode n, XmlNamespaceManager nsmgr, ArrayList tmpList) - { - if (n.Prefix.Length == 0 && propagatedNss != null) { - foreach (DictionaryEntry de in propagatedNss) - if ((string) de.Value == n.NamespaceURI) { - n.Prefix = (string) de.Key; - break; - } - } - - if (n.NodeType == XmlNodeType.Element && ((XmlElement) n).HasAttributes) { - foreach (XmlAttribute a in n.Attributes) - if (a.NamespaceURI == "http://www.w3.org/2000/xmlns/") - nsmgr.AddNamespace (a.Prefix.Length == 0 ? String.Empty : a.LocalName, a.Value); - nsmgr.PushScope (); - } - - if (n.NamespaceURI.Length > 0 && nsmgr.LookupPrefix (n.NamespaceURI) == null) - tmpList.Add (CreateXmlns (n)); - - if (n.NodeType == XmlNodeType.Element && ((XmlElement) n).HasAttributes) { - foreach (XmlAttribute a in n.Attributes) - if (a.NamespaceURI.Length > 0 && nsmgr.LookupNamespace (a.Prefix) == null) - tmpList.Add (CreateXmlns (a)); - } - - foreach (XmlAttribute a in tmpList) - ((XmlElement) n).SetAttributeNode (a); - tmpList.Clear (); - - if (n.HasChildNodes) { - for (XmlNode c = n.FirstChild; c != null; c = c.NextSibling) - if (c.NodeType == XmlNodeType.Element) - FillMissingPrefixes (c, nsmgr, tmpList); - } - nsmgr.PopScope (); - } - - private void WriteNode (XmlNode node) - { - // Console.WriteLine ("C14N Debug: node=" + node.Name); - - bool visible = IsNodeVisible (node); - switch (node.NodeType) { - case XmlNodeType.Document: - case XmlNodeType.DocumentFragment: - WriteDocumentNode (node); - break; - case XmlNodeType.Element: - WriteElementNode (node, visible); - break; - case XmlNodeType.CDATA: - case XmlNodeType.SignificantWhitespace: - case XmlNodeType.Text: - // CDATA sections are processed as text nodes - WriteTextNode (node, visible); - break; - case XmlNodeType.Whitespace: - if (state == XmlCanonicalizerState.InsideDocElement) - WriteTextNode (node, visible); - break; - case XmlNodeType.Comment: - WriteCommentNode (node, visible); - break; - case XmlNodeType.ProcessingInstruction: - WriteProcessingInstructionNode (node, visible); - break; - case XmlNodeType.EntityReference: - for (int i = 0; i < node.ChildNodes.Count; i++) - WriteNode (node.ChildNodes [i]); - break; - case XmlNodeType.Attribute: - throw new XmlException ("Attribute node is impossible here", null); - case XmlNodeType.EndElement: - throw new XmlException ("EndElement node is impossible here", null); - case XmlNodeType.EndEntity: - throw new XmlException ("EndEntity node is impossible here", null); - case XmlNodeType.DocumentType: - case XmlNodeType.Entity: - case XmlNodeType.Notation: - case XmlNodeType.XmlDeclaration: - // just do nothing - break; - } - } - - private void WriteDocumentNode (XmlNode node) - { - state = XmlCanonicalizerState.BeforeDocElement; - for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) - WriteNode (child); - } - - // Element Nodes - // If the element is not in the node-set, then the result is obtained - // by processing the namespace axis, then the attribute axis, then - // processing the child nodes of the element that are in the node-set - // (in document order). If the element is inthe node-set, then the result - // is an open angle bracket (<), the element QName, the result of - // processing the namespace axis, the result of processing the attribute - // axis, a close angle bracket (>), the result of processing the child - // nodes of the element that are in the node-set (in document order), an - // open angle bracket, a forward slash (/), the element QName, and a close - // angle bracket. - private void WriteElementNode (XmlNode node, bool visible) - { - // Console.WriteLine ("Debug: element node"); - - // remember current state - int savedPrevVisibleNamespacesStart = prevVisibleNamespacesStart; - int savedPrevVisibleNamespacesEnd = prevVisibleNamespacesEnd; - int savedVisibleNamespacesSize = visibleNamespaces.Count; - XmlCanonicalizerState s = state; - if (visible && state == XmlCanonicalizerState.BeforeDocElement) - state = XmlCanonicalizerState.InsideDocElement; - - // write start tag - if (visible) { - res.Append ("<"); - res.Append (node.Name); - } - - // this is odd but you can select namespaces - // and attributes even if node itself is not visible - WriteNamespacesAxis (node, visible); - WriteAttributesAxis (node); - - if (visible) - res.Append (">"); - - // write children - for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) - WriteNode (child); - - // write end tag - if (visible) { - res.Append (""); - } - - // restore state - if (visible && s == XmlCanonicalizerState.BeforeDocElement) - state = XmlCanonicalizerState.AfterDocElement; - prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart; - prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd; - if (visibleNamespaces.Count > savedVisibleNamespacesSize) { - visibleNamespaces.RemoveRange (savedVisibleNamespacesSize, - visibleNamespaces.Count - savedVisibleNamespacesSize); - } - } - - // Namespace Axis - // Consider a list L containing only namespace nodes in the - // axis and in the node-set in lexicographic order (ascending). To begin - // processing L, if the first node is not the default namespace node (a node - // with no namespace URI and no local name), then generate a space followed - // by xmlns="" if and only if the following conditions are met: - // - the element E that owns the axis is in the node-set - // - The nearest ancestor element of E in the node-set has a default - // namespace node in the node-set (default namespace nodes always - // have non-empty values in XPath) - // The latter condition eliminates unnecessary occurrences of xmlns="" in - // the canonical form since an element only receives an xmlns="" if its - // default namespace is empty and if it has an immediate parent in the - // canonical form that has a non-empty default namespace. To finish - // processing L, simply process every namespace node in L, except omit - // namespace node with local name xml, which defines the xml prefix, - // if its string value is http://www.w3.org/XML/1998/namespace. - private void WriteNamespacesAxis (XmlNode node, bool visible) - { - // Console.WriteLine ("Debug: namespaces"); - - XmlDocument doc = node.OwnerDocument; - bool has_empty_namespace = false; - ArrayList list = new ArrayList (); - for (XmlNode cur = node; cur != null && cur != doc; cur = cur.ParentNode) { - foreach (XmlAttribute attribute in cur.Attributes) { - if (!IsNamespaceNode (attribute)) - continue; - - // get namespace prefix - string prefix = string.Empty; - if (attribute.Prefix == "xmlns") - prefix = attribute.LocalName; - - // check if it is "xml" namespace - if (prefix == "xml" && attribute.Value == "http://www.w3.org/XML/1998/namespace") - continue; - - // make sure that this is an active namespace - // for our node - string ns = node.GetNamespaceOfPrefix (prefix); - if (ns != attribute.Value) - continue; - - // check that it is selected with XPath - if (!IsNodeVisible (attribute)) - continue; - - // check that we have not rendered it yet - bool rendered = IsNamespaceRendered (prefix, attribute.Value); - - // For exc-c14n, only visibly utilized - // namespaces are written. - if (exclusive && !IsVisiblyUtilized (node as XmlElement, attribute)) - continue; - - // add to the visible namespaces stack - if (visible) - visibleNamespaces.Add (attribute); - - if (!rendered) - list.Add (attribute); - - if (prefix == string.Empty) - has_empty_namespace = true; - } - } - - // add empty namespace if needed - if (visible && !has_empty_namespace && !IsNamespaceRendered (string.Empty, string.Empty) && node.NamespaceURI == String.Empty) - res.Append (" xmlns=\"\""); - - list.Sort (new XmlDsigC14NTransformNamespacesComparer ()); - foreach (object obj in list) { - XmlNode attribute = (obj as XmlNode); - if (attribute != null) { - res.Append (" "); - res.Append (attribute.Name); - res.Append ("=\""); - res.Append (attribute.Value); - res.Append ("\""); - } - } - - // move the rendered namespaces stack - if (visible) { - prevVisibleNamespacesStart = prevVisibleNamespacesEnd; - prevVisibleNamespacesEnd = visibleNamespaces.Count; - } - } - - // Attribute Axis - // In lexicographic order (ascending), process each node that - // is in the element's attribute axis and in the node-set. - // - // The processing of an element node E MUST be modified slightly - // when an XPath node-set is given as input and the element's - // parent is omitted from the node-set. - private void WriteAttributesAxis (XmlNode node) - { - // Console.WriteLine ("Debug: attributes"); - - ArrayList list = new ArrayList (); - foreach (XmlNode attribute in node.Attributes) { - if (!IsNamespaceNode (attribute) && IsNodeVisible (attribute)) - list.Add (attribute); - } - - // Add attributes from "xml" namespace for "inclusive" c14n only: - // - // The method for processing the attribute axis of an element E - // in the node-set is enhanced. All element nodes along E's - // ancestor axis are examined for nearest occurrences of - // attributes in the xml namespace, such as xml:lang and - // xml:space (whether or not they are in the node-set). - // From this list of attributes, remove any that are in E's - // attribute axis (whether or not they are in the node-set). - // Then, lexicographically merge this attribute list with the - // nodes of E's attribute axis that are in the node-set. The - // result of visiting the attribute axis is computed by - // processing the attribute nodes in this merged attribute list. - if (!exclusive && node.ParentNode != null && node.ParentNode.ParentNode != null && !IsNodeVisible (node.ParentNode.ParentNode)) { - // if we have whole document then the node.ParentNode.ParentNode - // is always visible - for (XmlNode cur = node.ParentNode; cur != null; cur = cur.ParentNode) { - if (cur.Attributes == null) - continue; - foreach (XmlNode attribute in cur.Attributes) { - // we are looking for "xml:*" attributes - if (attribute.Prefix != "xml") - continue; - - // exclude ones that are in the node's attributes axis - if (node.Attributes.GetNamedItem (attribute.LocalName, attribute.NamespaceURI) != null) - continue; - - // finally check that we don't have the same attribute in our list - bool found = false; - foreach (object obj in list) { - XmlNode n = (obj as XmlNode); - if (n.Prefix == "xml" && n.LocalName == attribute.LocalName) { - found = true; - break; - } - } - - if (found) - continue; - - // now we can add this attribute to our list - list.Add (attribute); - } - } - } - - // sort namespaces and write results - list.Sort (new XmlDsigC14NTransformAttributesComparer ()); - foreach (object obj in list) { - XmlNode attribute = (obj as XmlNode); - if (attribute != null) { - res.Append (" "); - res.Append (attribute.Name); - res.Append ("=\""); - res.Append (NormalizeString (attribute.Value, XmlNodeType.Attribute)); - res.Append ("\""); - } - } - } - - // Text Nodes - // the string value, except all ampersands are replaced - // by &, all open angle brackets (<) are replaced by <, all closing - // angle brackets (>) are replaced by >, and all #xD characters are - // replaced by . - private void WriteTextNode (XmlNode node, bool visible) - { - // Console.WriteLine ("Debug: text node"); - if (visible) - res.Append (NormalizeString (node.Value, node.NodeType)); -// res.Append (NormalizeString (node.Value, XmlNodeType.Text)); - } - - // Comment Nodes - // Nothing if generating canonical XML without comments. For - // canonical XML with comments, generate the opening comment - // symbol (). Also, a trailing #xA is rendered - // after the closing comment symbol for comment children of the - // root node with a lesser document order than the document - // element, and a leading #xA is rendered before the opening - // comment symbol of comment children of the root node with a - // greater document order than the document element. (Comment - // children of the root node represent comments outside of the - // top-level document element and outside of the document type - // declaration). - private void WriteCommentNode (XmlNode node, bool visible) - { - // Console.WriteLine ("Debug: comment node"); - if (visible && comments) { - if (state == XmlCanonicalizerState.AfterDocElement) - res.Append ("\x0A\x0A"); - else - res.Append ("-->"); - } - } - - // Processing Instruction (PI) Nodes- - // The opening PI symbol (). If the string value is empty, - // then the leading space is not added. Also, a trailing #xA is - // rendered after the closing PI symbol for PI children of the - // root node with a lesser document order than the document - // element, and a leading #xA is rendered before the opening PI - // symbol of PI children of the root node with a greater document - // order than the document element. - private void WriteProcessingInstructionNode (XmlNode node, bool visible) - { - // Console.WriteLine ("Debug: PI node"); - - if (visible) { - if (state == XmlCanonicalizerState.AfterDocElement) - res.Append ("\x0A 0) { - res.Append (" "); - res.Append (NormalizeString (node.Value, XmlNodeType.ProcessingInstruction)); - } - - if (state == XmlCanonicalizerState.BeforeDocElement) - res.Append ("?>\x0A"); - else - res.Append ("?>"); - } - } - - // determines whether the node is in the node-set or not. - private bool IsNodeVisible (XmlNode node) - { - // if node list is empty then we process whole document - if (xnl == null) - return true; - - // walk thru the list - foreach (XmlNode xn in xnl) { - if (node.Equals (xn)) - return true; - } - - return false; - } - - // This method assumes that the namespace node is *not* - // rendered yet. - private bool IsVisiblyUtilized (XmlElement owner, XmlAttribute ns) - { - if (owner == null) - return false; - - string prefix = ns.LocalName == "xmlns" ? String.Empty : ns.LocalName; - if (owner.Prefix == prefix && owner.NamespaceURI == ns.Value) - return true; - if (!owner.HasAttributes) - return false; - foreach (XmlAttribute a in owner.Attributes) { - if (a.Prefix == String.Empty) - continue; - if (a.Prefix != prefix || a.NamespaceURI != ns.Value) - continue; - if (IsNodeVisible (a)) - return true; - } - return false; - } - - private bool IsNamespaceRendered (string prefix, string uri) - { - // if the default namespace xmlns="" is not re-defined yet - // then we do not want to print it out - bool IsEmptyNs = prefix == string.Empty && uri == string.Empty; - int start = (IsEmptyNs) ? 0 : prevVisibleNamespacesStart; - for (int i = visibleNamespaces.Count - 1; i >= start; i--) { - XmlNode node = (visibleNamespaces[i] as XmlNode); - if (node != null) { - // get namespace prefix - string p = string.Empty; - if (node.Prefix == "xmlns") - p = node.LocalName; - if (p == prefix) - return node.Value == uri; - } - } - - return IsEmptyNs; - } - - private bool IsNamespaceNode (XmlNode node) - { - if (node == null || node.NodeType != XmlNodeType.Attribute) - return false; - return node.NamespaceURI == "http://www.w3.org/2000/xmlns/"; - } - - private bool IsTextNode (XmlNodeType type) - { - switch (type) { - case XmlNodeType.Text: - case XmlNodeType.CDATA: - case XmlNodeType.SignificantWhitespace: - case XmlNodeType.Whitespace: - return true; - } - return false; - } - - private string NormalizeString (string input, XmlNodeType type) - { - StringBuilder sb = new StringBuilder (); - for (int i = 0; i < input.Length; i++) { - char ch = input[i]; - if (ch == '<' && (type == XmlNodeType.Attribute || IsTextNode (type))) - sb.Append ("<"); - else if (ch == '>' && IsTextNode (type)) - sb.Append (">"); - else if (ch == '&' && (type == XmlNodeType.Attribute || IsTextNode (type))) - sb.Append ("&"); - else if (ch == '\"' && type == XmlNodeType.Attribute) - sb.Append ("""); - else if (ch == '\x09' && type == XmlNodeType.Attribute) - sb.Append (" "); - else if (ch == '\x0A' && type == XmlNodeType.Attribute) - sb.Append (" "); - else if (ch == '\x0D') - sb.Append (" "); - else - sb.Append (ch); - } - - return sb.ToString (); - } - } - - internal class XmlDsigC14NTransformAttributesComparer : IComparer - { - public int Compare (object x, object y) - { - XmlNode n1 = (x as XmlNode); - XmlNode n2 = (y as XmlNode); - - // simple cases - if (n1 == n2) - return 0; - else if (n1 == null) - return -1; - else if (n2 == null) - return 1; - else if (n1.Prefix == n2.Prefix) - return string.CompareOrdinal (n1.LocalName, n2.LocalName); - - // Attributes in the default namespace are first - // because the default namespace is not applied to - // unqualified attributes - if (n1.Prefix == string.Empty) - return -1; - else if (n2.Prefix == string.Empty) - return 1; - - int ret = string.Compare (n1.NamespaceURI, n2.NamespaceURI); - if (ret == 0) - ret = string.Compare (n1.LocalName, n2.LocalName); - return ret; - } - } - - internal class XmlDsigC14NTransformNamespacesComparer : IComparer - { - public int Compare (object x, object y) - { - XmlNode n1 = (x as XmlNode); - XmlNode n2 = (y as XmlNode); - - // simple cases - if (n1 == n2) - return 0; - else if (n1 == null) - return -1; - else if (n2 == null) - return 1; - else if (n1.Prefix == string.Empty) - return -1; - else if (n2.Prefix == string.Empty) - return 1; - - return string.Compare (n1.LocalName, n2.LocalName); - } - } -} - diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs index e748523cbc4..d6ecbe63afd 100644 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs +++ b/mcs/class/System.Security/System.Security.Cryptography.Xml/EncryptedReference.cs @@ -134,31 +134,31 @@ namespace System.Security.Cryptography.Xml { foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) { Transform t = null; switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) { - case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform: + case SignedXml.XmlDsigBase64TransformUrl: t = new XmlDsigBase64Transform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform: + case SignedXml.XmlDsigC14NTransformUrl: t = new XmlDsigC14NTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform: + case SignedXml.XmlDsigC14NWithCommentsTransformUrl: t = new XmlDsigC14NWithCommentsTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform: + case SignedXml.XmlDsigEnvelopedSignatureTransformUrl: t = new XmlDsigEnvelopedSignatureTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform: + case SignedXml.XmlDsigXPathTransformUrl: t = new XmlDsigXPathTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform: + case SignedXml.XmlDsigXsltTransformUrl: t = new XmlDsigXsltTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform: + case SignedXml.XmlDsigExcC14NTransformUrl: t = new XmlDsigExcC14NTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NWithCommentsTransform: + case SignedXml.XmlDsigExcC14NWithCommentsTransformUrl: t = new XmlDsigExcC14NWithCommentsTransform (); break; - case XmlSignature.AlgorithmNamespaces.XmlDecryptionTransform: + case SignedXml.XmlDecryptionTransformUrl: t = new XmlDecryptionTransform (); break; default: diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/Reference.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/Reference.cs deleted file mode 100644 index 2376c4e45b1..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/Reference.cs +++ /dev/null @@ -1,229 +0,0 @@ -// -// Reference.cs - Reference implementation for XML Signature -// -// Author: -// Sebastien Pouliot -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.IO; -using System.Runtime.InteropServices; -using System.Xml; - -namespace System.Security.Cryptography.Xml { - - // http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/Overview.html#sec-Reference - public class Reference { - - private TransformChain chain; - private string digestMethod; - private byte[] digestValue; - private string id; - private string uri; - private string type; - private Stream stream; - private XmlElement element; - - public Reference () - { - chain = new TransformChain (); - digestMethod = XmlSignature.NamespaceURI + "sha1"; - } - - [MonoTODO ("There is no description about how it is used.")] - public Reference (Stream stream) : this () - { - this.stream = stream; - } - - public Reference (string uri) : this () - { - this.uri = uri; - } - - // default to SHA1 - public string DigestMethod { - get { return digestMethod; } - set { - element = null; - digestMethod = value; - } - } - - public byte[] DigestValue { - get { return digestValue; } - set { - element = null; - digestValue = value; - } - } - - public string Id { - get { return id; } - set { - element = null; - id = value; - } - } - - public TransformChain TransformChain { - get { return chain; } - [ComVisible (false)] - set { chain = value; } - } - - public string Type { - get { return type; } - set { - element = null; - type = value; - } - } - - public string Uri { - get { return uri; } - set { - element = null; - uri = value; - } - } - - public void AddTransform (Transform transform) - { - chain.Add (transform); - } - - public XmlElement GetXml () - { - if (element != null) - return element; - - if (digestMethod == null) - throw new CryptographicException ("DigestMethod"); - if (digestValue == null) - throw new NullReferenceException ("DigestValue"); - - XmlDocument document = new XmlDocument (); - XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Reference, XmlSignature.NamespaceURI); - if (id != null) - xel.SetAttribute (XmlSignature.AttributeNames.Id, id); - if (uri != null) - xel.SetAttribute (XmlSignature.AttributeNames.URI, uri); - if (type != null) - xel.SetAttribute (XmlSignature.AttributeNames.Type, type); - - if (chain.Count > 0) { - XmlElement ts = document.CreateElement (XmlSignature.ElementNames.Transforms, XmlSignature.NamespaceURI); - foreach (Transform t in chain) { - XmlNode xn = t.GetXml (); - XmlNode newNode = document.ImportNode (xn, true); - ts.AppendChild (newNode); - } - xel.AppendChild (ts); - } - - XmlElement dm = document.CreateElement (XmlSignature.ElementNames.DigestMethod, XmlSignature.NamespaceURI); - dm.SetAttribute (XmlSignature.AttributeNames.Algorithm, digestMethod); - xel.AppendChild (dm); - - XmlElement dv = document.CreateElement (XmlSignature.ElementNames.DigestValue, XmlSignature.NamespaceURI); - dv.InnerText = Convert.ToBase64String (digestValue); - xel.AppendChild (dv); - - return xel; - } - - // note: we do NOT return null -on purpose- if attribute isn't found - private string GetAttribute (XmlElement xel, string attribute) - { - XmlAttribute xa = xel.Attributes [attribute]; - return ((xa != null) ? xa.InnerText : null); - } - - public void LoadXml (XmlElement value) - { - if (value == null) - throw new ArgumentNullException ("value"); - - if ((value.LocalName != XmlSignature.ElementNames.Reference) || (value.NamespaceURI != XmlSignature.NamespaceURI)) - throw new CryptographicException (); - - id = GetAttribute (value, XmlSignature.AttributeNames.Id); - uri = GetAttribute (value, XmlSignature.AttributeNames.URI); - type = GetAttribute (value, XmlSignature.AttributeNames.Type); - // Note: order is important for validations - XmlNodeList xnl = value.GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI); - if ((xnl != null) && (xnl.Count > 0)) { - Transform t = null; - foreach (XmlNode xn in xnl) { - string a = GetAttribute ((XmlElement)xn, XmlSignature.AttributeNames.Algorithm); -/* This code is useful for debugging in VS.NET because using CryptoConfig - (from MS mscorlib) would throw InvalidCastException because it's - Transform would come from MS System.Security.dll not Mono's. - switch (a) { - case "http://www.w3.org/2000/09/xmldsig#base64": - t = new XmlDsigBase64Transform (); - break; - case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315": - t = new XmlDsigC14NTransform (); - break; - case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments": - t = new XmlDsigC14NWithCommentsTransform (); - break; - case "http://www.w3.org/2000/09/xmldsig#enveloped-signature": - t = new XmlDsigEnvelopedSignatureTransform (); - break; - case "http://www.w3.org/TR/1999/REC-xpath-19991116": - t = new XmlDsigXPathTransform (); - break; - case "http://www.w3.org/TR/1999/REC-xslt-19991116": - t = new XmlDsigXsltTransform (); - break; - case "http://www.w3.org/2002/07/decrypt#XML": - t = new XmlDecryptionTransform (); - break; - default: - throw new NotSupportedException (); - } -*/ - t = (Transform) CryptoConfig.CreateFromName (a); - if (t == null) - throw new CryptographicException ("Unknown transform {0}.", a); - - if (xn.ChildNodes.Count > 0) { - t.LoadInnerXml (xn.ChildNodes); - } - AddTransform (t); - } - } - // get DigestMethod - DigestMethod = XmlSignature.GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.DigestMethod); - // get DigestValue - XmlElement dig = XmlSignature.GetChildElement (value, XmlSignature.ElementNames.DigestValue, XmlSignature.NamespaceURI); - if (dig != null) - DigestValue = Convert.FromBase64String (dig.InnerText); - element = value; - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs index 2ebec980947..84d13e83c14 100644 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs +++ b/mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs @@ -43,26 +43,36 @@ using System.Security.Cryptography.X509Certificates; namespace System.Security.Cryptography.Xml { public class SignedXml { - - public const string XmlDsigCanonicalizationUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"; - public const string XmlDsigCanonicalizationWithCommentsUrl = XmlDsigCanonicalizationUrl + "#WithComments"; - public const string XmlDsigDSAUrl = XmlDsigNamespaceUrl + "dsa-sha1"; - public const string XmlDsigHMACSHA1Url = XmlDsigNamespaceUrl + "hmac-sha1"; - public const string XmlDsigMinimalCanonicalizationUrl = XmlDsigNamespaceUrl + "minimal"; - public const string XmlDsigNamespaceUrl = "http://www.w3.org/2000/09/xmldsig#"; - public const string XmlDsigRSASHA1Url = XmlDsigNamespaceUrl + "rsa-sha1"; - public const string XmlDsigSHA1Url = XmlDsigNamespaceUrl + "sha1"; - - public const string XmlDecryptionTransformUrl = "http://www.w3.org/2002/07/decrypt#XML"; - public const string XmlDsigBase64TransformUrl = XmlDsigNamespaceUrl + "base64"; - public const string XmlDsigC14NTransformUrl = XmlDsigCanonicalizationUrl; - public const string XmlDsigC14NWithCommentsTransformUrl = XmlDsigCanonicalizationWithCommentsUrl; - public const string XmlDsigEnvelopedSignatureTransformUrl = XmlDsigNamespaceUrl + "enveloped-signature"; - public const string XmlDsigExcC14NTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#"; - public const string XmlDsigExcC14NWithCommentsTransformUrl = XmlDsigExcC14NTransformUrl + "WithComments"; - public const string XmlDsigXPathTransformUrl = "http://www.w3.org/TR/1999/REC-xpath-19991116"; - public const string XmlDsigXsltTransformUrl = "http://www.w3.org/TR/1999/REC-xslt-19991116"; - public const string XmlLicenseTransformUrl = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform"; + public const string XmlDsigNamespaceUrl = "http://www.w3.org/2000/09/xmldsig#"; + public const string XmlDsigMinimalCanonicalizationUrl = "http://www.w3.org/2000/09/xmldsig#minimal"; + public const string XmlDsigCanonicalizationUrl = XmlDsigC14NTransformUrl; + public const string XmlDsigCanonicalizationWithCommentsUrl = XmlDsigC14NWithCommentsTransformUrl; + + public const string XmlDsigSHA1Url = "http://www.w3.org/2000/09/xmldsig#sha1"; + public const string XmlDsigDSAUrl = "http://www.w3.org/2000/09/xmldsig#dsa-sha1"; + public const string XmlDsigRSASHA1Url = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"; + public const string XmlDsigHMACSHA1Url = "http://www.w3.org/2000/09/xmldsig#hmac-sha1"; + + public const string XmlDsigSHA256Url = "http://www.w3.org/2001/04/xmlenc#sha256"; + public const string XmlDsigRSASHA256Url = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"; + + // Yes, SHA384 is in the xmldsig-more namespace even though all the other SHA variants are in xmlenc. That's the standard. + public const string XmlDsigSHA384Url = "http://www.w3.org/2001/04/xmldsig-more#sha384"; + public const string XmlDsigRSASHA384Url = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"; + + public const string XmlDsigSHA512Url = "http://www.w3.org/2001/04/xmlenc#sha512"; + public const string XmlDsigRSASHA512Url = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"; + + public const string XmlDsigC14NTransformUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"; + public const string XmlDsigC14NWithCommentsTransformUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"; + public const string XmlDsigExcC14NTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#"; + public const string XmlDsigExcC14NWithCommentsTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"; + public const string XmlDsigBase64TransformUrl = "http://www.w3.org/2000/09/xmldsig#base64"; + public const string XmlDsigXPathTransformUrl = "http://www.w3.org/TR/1999/REC-xpath-19991116"; + public const string XmlDsigXsltTransformUrl = "http://www.w3.org/TR/1999/REC-xslt-19991116"; + public const string XmlDsigEnvelopedSignatureTransformUrl = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"; + public const string XmlDecryptionTransformUrl = "http://www.w3.org/2002/07/decrypt#XML"; + public const string XmlLicenseTransformUrl = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform"; private EncryptedXml encryptedXml; @@ -74,7 +84,9 @@ namespace System.Security.Cryptography.Xml { private XmlElement signatureElement; private Hashtable hashes; // FIXME: enable it after CAS implementation - private XmlResolver xmlResolver = new XmlUrlResolver (); + internal XmlResolver _xmlResolver = new XmlUrlResolver (); + private bool _bResolverSet = true; + internal XmlElement _context; private ArrayList manifests; private IEnumerator _x509Enumerator; @@ -85,6 +97,7 @@ namespace System.Security.Cryptography.Xml { m_signature = new Signature (); m_signature.SignedInfo = new SignedInfo (); hashes = new Hashtable (2); // 98% SHA1 for now + _context = null; } public SignedXml (XmlDocument document) : this () @@ -92,6 +105,7 @@ namespace System.Security.Cryptography.Xml { if (document == null) throw new ArgumentNullException ("document"); envdoc = document; + _context = document.DocumentElement; } public SignedXml (XmlElement elem) : this () @@ -99,6 +113,7 @@ namespace System.Security.Cryptography.Xml { if (elem == null) throw new ArgumentNullException ("elem"); envdoc = new XmlDocument (); + _context = elem; envdoc.LoadXml (elem.OuterXml); } @@ -148,6 +163,22 @@ namespace System.Security.Cryptography.Xml { set { m_strSigningKeyName = value; } } + public XmlResolver Resolver + { + // This property only has a setter. The rationale for this is that we don't have a good value + // to return when it has not been explicitely set, as we are using XmlSecureResolver by default + set + { + _xmlResolver = value; + _bResolverSet = true; + } + } + + internal bool ResolverSet + { + get { return _bResolverSet; } + } + public void AddObject (DataObject dataObject) { m_signature.AddObject (dataObject); @@ -221,9 +252,9 @@ namespace System.Security.Cryptography.Xml { FixupNamespaceNodes (xel, doc.DocumentElement, false); } } - else if (xmlResolver != null) { + else if (_xmlResolver != null) { // TODO: need testing - Stream s = (Stream) xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream)); + Stream s = (Stream) _xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream)); doc.Load (s); } @@ -281,12 +312,12 @@ namespace System.Security.Cryptography.Xml { else if (r.Uri [0] == '#') { objectName = r.Uri.Substring (1); } - else if (xmlResolver != null) { + else if (_xmlResolver != null) { // TODO: test but doc says that Resolver = null -> no access try { // no way to know if valid without throwing an exception Uri uri = new Uri (r.Uri); - s = (Stream) xmlResolver.GetEntity (uri, null, typeof (Stream)); + s = (Stream) _xmlResolver.GetEntity (uri, null, typeof (Stream)); } catch { // may still be a local file (and maybe not xml) @@ -763,6 +794,11 @@ namespace System.Security.Cryptography.Xml { signatureElement = value; m_signature.LoadXml (value); + + if (_context == null) { + _context = value; + } + // Need to give the EncryptedXml object to the // XmlDecryptionTransform to give it a fighting // chance at decrypting the document. @@ -773,10 +809,5 @@ namespace System.Security.Cryptography.Xml { } } } - - [ComVisible (false)] - public XmlResolver Resolver { - set { xmlResolver = value; } - } } } diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs deleted file mode 100644 index 80c8923e99d..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs +++ /dev/null @@ -1,132 +0,0 @@ -// -// Transform.cs - Transform implementation for XML Signature -// -// Author: -// Sebastien Pouliot -// Atsushi Enomoto -// Tim Coleman -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// Copyright (C) Tim Coleman, 2004 -// Copyright (C) 2004-2006 Novell Inc. (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections; -using System.IO; -using System.Runtime.InteropServices; -using System.Security; -using System.Security.Policy; -using System.Xml; - -namespace System.Security.Cryptography.Xml { - - public abstract class Transform { - - private string algo; - private XmlResolver xmlResolver; - private Hashtable propagated_namespaces = new Hashtable (); - - protected Transform () - { - if (SecurityManager.SecurityEnabled) { - xmlResolver = new XmlSecureResolver (new XmlUrlResolver (), (Evidence) new Evidence ()); - } else { - xmlResolver = new XmlUrlResolver (); - } - } - - #region Properties - - public string Algorithm { - get { return algo; } - set { algo = value; } - } - - public abstract Type[] InputTypes { - get; - } - - public abstract Type[] OutputTypes { - get; - } - - [ComVisible(false)] - public XmlResolver Resolver { - set { xmlResolver = value; } - } - - [MonoTODO] - [ComVisible (false)] - public XmlElement Context { - get { throw new NotImplementedException (); } - set { throw new NotImplementedException (); } - } - - [ComVisible (false)] - public Hashtable PropagatedNamespaces { - get { return propagated_namespaces; } - } - - #endregion // Properties - - #region Methods - [ComVisible (false)] - public virtual byte[] GetDigestedOutput (HashAlgorithm hash) - { - // no null check, MS throws a NullReferenceException here - return hash.ComputeHash ((Stream) GetOutput (typeof (Stream))); - } - - protected abstract XmlNodeList GetInnerXml (); - - public abstract object GetOutput (); - - public abstract object GetOutput (Type type); - - public XmlElement GetXml () - { - XmlDocument document = new XmlDocument (); - document.XmlResolver = GetResolver (); - XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI); - xel.SetAttribute (XmlSignature.AttributeNames.Algorithm, algo); - XmlNodeList xnl = this.GetInnerXml (); - if (xnl != null) { - foreach (XmlNode xn in xnl) { - XmlNode importedNode = document.ImportNode (xn, true); - xel.AppendChild (importedNode); - } - } - return xel; - } - - public abstract void LoadInnerXml (XmlNodeList nodeList); - - public abstract void LoadInput (object obj); - - internal XmlResolver GetResolver () - { - return xmlResolver; - } - - #endregion // Methods - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/TransformChain.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/TransformChain.cs deleted file mode 100644 index 523b34802ee..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/TransformChain.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// TransformChain.cs - TransformChain implementation for XML Signature -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections; - -namespace System.Security.Cryptography.Xml { - - public class TransformChain { - - private ArrayList chain; - - public TransformChain() - { - chain = new ArrayList (); - } - - public int Count { - get { return chain.Count; } - } - - public Transform this [int index] { - get { return (Transform) chain [index]; } - } - - public void Add (Transform transform) - { - chain.Add (transform); - } - - public IEnumerator GetEnumerator () - { - return chain.GetEnumerator (); - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDecryptionTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDecryptionTransform.cs deleted file mode 100644 index 154061b1949..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDecryptionTransform.cs +++ /dev/null @@ -1,194 +0,0 @@ -// -// XmlDecryptionTransform.cs - XmlDecryptionTransform implementation for XML Encryption -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2004 - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - - -using System.Collections; -using System.IO; -using System.Xml; - -namespace System.Security.Cryptography.Xml { - - public class XmlDecryptionTransform : Transform { - - #region Fields - - EncryptedXml encryptedXml; - Type[] inputTypes; - Type[] outputTypes; - object inputObj; - ArrayList exceptUris; - - const string NamespaceUri = "http://www.w3.org/2002/07/decrypt#"; - - #endregion // Fields - - #region Constructors - - public XmlDecryptionTransform () - { - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDecryptionTransform; - encryptedXml = new EncryptedXml (); - exceptUris = new ArrayList (); - } - - #endregion // Constructors - - #region Properties - - public EncryptedXml EncryptedXml { - get { return encryptedXml; } - set { encryptedXml = value; } - } - - public override Type[] InputTypes { - get { - if (inputTypes == null) - inputTypes = new Type [2] {typeof (System.IO.Stream), typeof (System.Xml.XmlDocument)}; - - return inputTypes; - } - } - - public override Type[] OutputTypes { - get { - if (outputTypes == null) - outputTypes = new Type [1] {typeof (System.Xml.XmlDocument)}; - - return outputTypes; - } - } - - #endregion // Properties - - #region Methods - - public void AddExceptUri (string uri) - { - exceptUris.Add (uri); - } - - private void ClearExceptUris () - { - exceptUris.Clear (); - } - - [MonoTODO ("Verify")] - protected override XmlNodeList GetInnerXml () - { - XmlDocument doc = new XmlDocument (); - doc.AppendChild (doc.CreateElement ("DecryptionTransform")); - - foreach (object o in exceptUris) { - XmlElement element = doc.CreateElement ("Except", NamespaceUri); - element.Attributes.Append (doc.CreateAttribute ("URI", NamespaceUri)); - element.Attributes ["URI", NamespaceUri].Value = (string) o; - doc.DocumentElement.AppendChild (element); - } - - return doc.GetElementsByTagName ("Except", NamespaceUri); - } - - [MonoTODO ("Verify processing of ExceptURIs")] - public override object GetOutput () - { - XmlDocument document; - if (inputObj is Stream) { - document = new XmlDocument (); - document.PreserveWhitespace = true; - document.XmlResolver = GetResolver (); - document.Load (new XmlSignatureStreamReader ( - new StreamReader (inputObj as Stream))); - } - else if (inputObj is XmlDocument) { - document = inputObj as XmlDocument; - } - else - throw new NullReferenceException (); - - XmlNodeList nodes = document.GetElementsByTagName ("EncryptedData", EncryptedXml.XmlEncNamespaceUrl); - foreach (XmlNode node in nodes) { - if (node == document.DocumentElement && exceptUris.Contains ("#xpointer(/)")) - break; - - // Need to exclude based on ExceptURI. Only accept #id references. - foreach (string uri in exceptUris) - if (IsTargetElement ((XmlElement) node, uri.Substring (1))) - break; - - EncryptedData encryptedData = new EncryptedData (); - encryptedData.LoadXml ((XmlElement) node); - SymmetricAlgorithm symAlg = EncryptedXml.GetDecryptionKey (encryptedData, encryptedData.EncryptionMethod.KeyAlgorithm); - EncryptedXml.ReplaceData ((XmlElement) node, EncryptedXml.DecryptData (encryptedData, symAlg)); - } - - return document; - } - - public override object GetOutput (Type type) - { - if (type == typeof (Stream)) - return GetOutput (); - throw new ArgumentException ("type"); - } - - [MonoTODO ("verify")] - protected virtual bool IsTargetElement (XmlElement inputElement, string idValue) - { - if ((inputElement == null) || (idValue == null)) - return false; - return (inputElement.Attributes ["id"].Value == idValue); - } - - [MonoTODO ("This doesn't seem to work in .NET")] - public override void LoadInnerXml (XmlNodeList nodeList) - { - if (nodeList == null) - throw new NullReferenceException (); - - ClearExceptUris (); - foreach (XmlNode node in nodeList) { - XmlElement element = node as XmlElement; - if (element.NamespaceURI.Equals (NamespaceUri) && element.LocalName.Equals ("Except")) { - string uri = element.Attributes ["URI", NamespaceUri].Value; - if (!uri.StartsWith ("#")) - throw new CryptographicException ("A Uri attribute is required for a CipherReference element."); - AddExceptUri (uri); - } - } - } - - public override void LoadInput (object obj) - { - inputObj = obj; - } - - #endregion // Methods - } -} - diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigBase64Transform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigBase64Transform.cs deleted file mode 100644 index 389c4ba9528..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigBase64Transform.cs +++ /dev/null @@ -1,131 +0,0 @@ -// -// XmlDsigBase64Transform.cs - Base64 Transform implementation for XML Signature -// -// Author: -// Sebastien Pouliot -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell (http://www.novell.com) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.IO; -using System.Security.Cryptography; -using System.Text; -using System.Xml; - -namespace System.Security.Cryptography.Xml { - - // http://www.w3.org/2000/09/xmldsig#base64 - public class XmlDsigBase64Transform : Transform { - - private CryptoStream cs; - private Type[] input; - private Type[] output; - - public XmlDsigBase64Transform () - { - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform; - } - - public override Type[] InputTypes { - get { - if (input == null) { - input = new Type [3]; - input[0] = typeof (System.IO.Stream); - input[1] = typeof (System.Xml.XmlDocument); - input[2] = typeof (System.Xml.XmlNodeList); - } - return input; - } - } - - public override Type[] OutputTypes { - get { - if (output == null) { - output = new Type [1]; - output[0] = typeof (System.IO.Stream); - } - return output; - } - } - - protected override XmlNodeList GetInnerXml () - { - return null; // THIS IS DOCUMENTED AS SUCH - } - - public override object GetOutput () - { - return (object) cs; - } - - public override object GetOutput (Type type) - { - if (type != typeof (System.IO.Stream)) - throw new ArgumentException ("type"); - return GetOutput (); - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - // documented as not changing the state of the transform - } - - public override void LoadInput (object obj) - { - XmlNodeList xnl = null; - Stream stream = null; - - if (obj is Stream) - stream = (obj as Stream); - else if (obj is XmlDocument) - xnl = (obj as XmlDocument).SelectNodes ("//."); - else if (obj is XmlNodeList) - xnl = (XmlNodeList) obj; - - if (xnl != null) { - stream = new MemoryStream (); - StreamWriter sw = new StreamWriter (stream); - foreach (XmlNode xn in xnl) { - switch (xn.NodeType) { - case XmlNodeType.Attribute: - case XmlNodeType.Text: - case XmlNodeType.CDATA: - case XmlNodeType.SignificantWhitespace: - case XmlNodeType.Whitespace: - sw.Write (xn.Value); - break; - } - } - sw.Flush (); - // ready to be re-used - stream.Position = 0; - } - - if (stream != null) - cs = new CryptoStream (stream, new FromBase64Transform (), CryptoStreamMode.Read); - // note: there is no default are other types won't throw an exception - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs deleted file mode 100644 index acbf322dc5e..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs +++ /dev/null @@ -1,144 +0,0 @@ -// -// XmlDsigC14NTransform.cs - C14N Transform implementation for XML Signature -// http://www.w3.org/TR/xml-c14n -// -// Authors: -// Sebastien Pouliot -// Aleksey Sanin (aleksey@aleksey.com) -// Tim Coleman (tim@timcoleman.com) -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2003 Aleksey Sanin (aleksey@aleksey.com) -// Copyright (C) Tim Coleman, 2004 -// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Xml; - -using Mono.Xml; - -namespace System.Security.Cryptography.Xml { - - public class XmlDsigC14NTransform : Transform { - private Type[] input; - private Type[] output; - private XmlCanonicalizer canonicalizer; - private Stream s; - - public XmlDsigC14NTransform () : this (false) - { - } - - public XmlDsigC14NTransform (bool includeComments) - { - if (includeComments) - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform; - else - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform; - canonicalizer = new XmlCanonicalizer (includeComments, false, PropagatedNamespaces); - } - - public override Type[] InputTypes { - get { - if (input == null) { - input = new Type [3]; - input[0] = typeof (System.IO.Stream); - input[1] = typeof (System.Xml.XmlDocument); - input[2] = typeof (System.Xml.XmlNodeList); - } - return input; - } - } - - public override Type[] OutputTypes { - get { - if (output == null) { - output = new Type [1]; - output[0] = typeof (System.IO.Stream); - } - return output; - } - } - - protected override XmlNodeList GetInnerXml () - { - return null; // THIS IS DOCUMENTED AS SUCH - } - - [ComVisible (false)] - public override byte[] GetDigestedOutput (HashAlgorithm hash) - { - // no null check, MS throws a NullReferenceException here - return hash.ComputeHash ((Stream) GetOutput ()); - } - - public override object GetOutput () - { - return (object) s; - } - - public override object GetOutput (Type type) - { - if (type == typeof (Stream)) - return GetOutput (); - throw new ArgumentException ("type"); - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - // documented as not changing the state of the transform - } - - public override void LoadInput (object obj) - { - // possible input: Stream, XmlDocument, and XmlNodeList - Stream stream = (obj as Stream); - if (stream != null) { - XmlDocument doc = new XmlDocument (); - doc.PreserveWhitespace = true; // REALLY IMPORTANT - doc.XmlResolver = GetResolver (); - doc.Load (new XmlSignatureStreamReader (new StreamReader (stream))); -// doc.Load ((Stream) obj); - s = canonicalizer.Canonicalize (doc); - return; - } - - XmlDocument xd = (obj as XmlDocument); - if (xd != null) { - s = canonicalizer.Canonicalize (xd); - return; - } - - XmlNodeList nl = (obj as XmlNodeList); - if (nl != null) { - s = canonicalizer.Canonicalize (nl); - } - else - throw new ArgumentException ("obj"); - } - } -} - diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransform.cs deleted file mode 100644 index 7d74479087d..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransform.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// XmlDsigC14NWithCommentsTransform.cs - -// C14N with comments Transform implementation for XML Signature -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -namespace System.Security.Cryptography.Xml { - - public class XmlDsigC14NWithCommentsTransform : XmlDsigC14NTransform { - - public XmlDsigC14NWithCommentsTransform() : base (true) - { - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs deleted file mode 100644 index 80f3c0db0c3..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs +++ /dev/null @@ -1,170 +0,0 @@ -// -// XmlDsigEnvelopedSignatureTransform.cs - -// Enveloped Signature Transform implementation for XML Signature -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// Atsushi Enomoto (atsushi@ximian.com) -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections; -using System.IO; -using System.Xml; - -namespace System.Security.Cryptography.Xml { - - public class XmlDsigEnvelopedSignatureTransform : Transform { - - private Type[] input; - private Type[] output; - private bool comments; - private object inputObj; - - public XmlDsigEnvelopedSignatureTransform () - : this (false) - { - } - - public XmlDsigEnvelopedSignatureTransform (bool includeComments) - { - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform; - comments = includeComments; - } - - public override Type[] InputTypes { - get { - if (input == null) { - input = new Type [3]; - input[0] = typeof (System.IO.Stream); - input[1] = typeof (System.Xml.XmlDocument); - input[2] = typeof (System.Xml.XmlNodeList); - } - return input; - } - } - - public override Type[] OutputTypes { - get { - if (output == null) { - output = new Type [2]; - output [0] = typeof (System.Xml.XmlDocument); - output [1] = typeof (System.Xml.XmlNodeList); - } - return output; - } - } - - protected override XmlNodeList GetInnerXml () - { - return null; // THIS IS DOCUMENTED AS SUCH - } - - // NOTE: This method never supports the requirements written - // in xmldsig spec that says its input is canonicalized before - // transforming. This method just removes Signature element. - // Canonicalization is done in SignedXml. - public override object GetOutput () - { - XmlDocument doc = null; - - // possible input: Stream, XmlDocument, and XmlNodeList - if (inputObj is Stream) { - doc = new XmlDocument (); - doc.PreserveWhitespace = true; - doc.XmlResolver = GetResolver (); - doc.Load (new XmlSignatureStreamReader ( - new StreamReader (inputObj as Stream))); - return GetOutputFromNode (doc, GetNamespaceManager (doc), true); - } - else if (inputObj is XmlDocument) { - doc = inputObj as XmlDocument; - return GetOutputFromNode (doc, GetNamespaceManager (doc), true); - } - else if (inputObj is XmlNodeList) { - ArrayList al = new ArrayList (); - XmlNodeList nl = (XmlNodeList) inputObj; - if (nl.Count > 0) { - XmlNamespaceManager m = GetNamespaceManager (nl.Item (0)); - ArrayList tmp = new ArrayList (); - foreach (XmlNode n in nl) - tmp.Add (n); - foreach (XmlNode n in tmp) - if (n.SelectNodes ("ancestor-or-self::dsig:Signature", m).Count == 0) - al.Add (GetOutputFromNode (n, m, false)); - } - return new XmlDsigNodeList (al); - } - // Note that it is unexpected behavior with related to InputTypes (MS.NET accepts XmlElement) - else if (inputObj is XmlElement) { - XmlElement el = inputObj as XmlElement; - XmlNamespaceManager m = GetNamespaceManager (el); - if (el.SelectNodes ("ancestor-or-self::dsig:Signature", m).Count == 0) - return GetOutputFromNode (el, m, true); - } - - throw new NullReferenceException (); - } - - private XmlNamespaceManager GetNamespaceManager (XmlNode n) - { - XmlDocument doc = ((n is XmlDocument) ? (n as XmlDocument) : n.OwnerDocument); - XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable); - nsmgr.AddNamespace ("dsig", XmlSignature.NamespaceURI); - return nsmgr; - } - - private XmlNode GetOutputFromNode (XmlNode input, XmlNamespaceManager nsmgr, bool remove) - { - if (remove) { - XmlNodeList nl = input.SelectNodes ("descendant-or-self::dsig:Signature", nsmgr); - ArrayList al = new ArrayList (); - foreach (XmlNode n in nl) - al.Add (n); - foreach (XmlNode n in al) - n.ParentNode.RemoveChild (n); - } - return input; - } - - public override object GetOutput (Type type) - { - if (type == typeof (Stream)) - return GetOutput (); - throw new ArgumentException ("type"); - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - // NO CHANGE - } - - public override void LoadInput (object obj) - { - inputObj = obj; - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs deleted file mode 100644 index b7249577e3b..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs +++ /dev/null @@ -1,162 +0,0 @@ -// -// XmlDsigExcC14NTransform.cs - ExcC14N Transform implementation for XML Signature -// http://www.w3.org/TR/xml-c14n -// -// Authors: -// Sebastien Pouliot -// Aleksey Sanin (aleksey@aleksey.com) -// Tim Coleman (tim@timcoleman.com) -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2003 Aleksey Sanin (aleksey@aleksey.com) -// Copyright (C) Tim Coleman, 2004 -// Copyright (C) 2004-2005 Novell Inc. (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Xml; - -using Mono.Xml; - -namespace System.Security.Cryptography.Xml { - - public class XmlDsigExcC14NTransform : Transform { - private Type[] input; - private Type[] output; - private XmlCanonicalizer canonicalizer; - private Stream s; - private string inclusiveNamespacesPrefixList; - - public XmlDsigExcC14NTransform () - : this (false, null) - { - } - - public XmlDsigExcC14NTransform (bool includeComments) - : this (includeComments, null) - { - } - - public XmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList) - : this (false, inclusiveNamespacesPrefixList) - { - } - - public XmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList) - { - if (includeComments) - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NWithCommentsTransform; - else - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform; - this.inclusiveNamespacesPrefixList = inclusiveNamespacesPrefixList; - canonicalizer = new XmlCanonicalizer (includeComments, true, PropagatedNamespaces); - } - - public string InclusiveNamespacesPrefixList { - get { return inclusiveNamespacesPrefixList; } - set { inclusiveNamespacesPrefixList = value; } - } - - public override Type[] InputTypes { - get { - if (input == null) { - input = new Type [3]; - input[0] = typeof (System.IO.Stream); - input[1] = typeof (System.Xml.XmlDocument); - input[2] = typeof (System.Xml.XmlNodeList); - } - return input; - } - } - - public override Type[] OutputTypes { - get { - if (output == null) { - output = new Type [1]; - output[0] = typeof (System.IO.Stream); - } - return output; - } - } - - protected override XmlNodeList GetInnerXml () - { - return null; // THIS IS DOCUMENTED AS SUCH - } - - public override byte[] GetDigestedOutput (HashAlgorithm hash) - { - // no null check, MS throws a NullReferenceException here - return hash.ComputeHash ((Stream) GetOutput ()); - } - - public override object GetOutput () - { - return (object) s; - } - - public override object GetOutput (Type type) - { - if (type == typeof (Stream)) - return GetOutput (); - throw new ArgumentException ("type"); - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - // documented as not changing the state of the transform - } - - public override void LoadInput (object obj) - { - canonicalizer.InclusiveNamespacesPrefixList = InclusiveNamespacesPrefixList; - // possible input: Stream, XmlDocument, and XmlNodeList - Stream stream = (obj as Stream); - if (stream != null) { - XmlDocument doc = new XmlDocument (); - doc.PreserveWhitespace = true; // REALLY IMPORTANT - doc.XmlResolver = GetResolver (); - doc.Load (new XmlSignatureStreamReader (new StreamReader (stream))); -// doc.Load ((Stream) obj); - s = canonicalizer.Canonicalize (doc); - return; - } - - XmlDocument xd = (obj as XmlDocument); - if (xd != null) { - s = canonicalizer.Canonicalize (xd); - return; - } - - XmlNodeList nl = (obj as XmlNodeList); - if (nl != null) { - s = canonicalizer.Canonicalize (nl); - } - else - throw new ArgumentException ("obj"); - } - } -} - diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NWithCommentsTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NWithCommentsTransform.cs deleted file mode 100644 index db049afa883..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NWithCommentsTransform.cs +++ /dev/null @@ -1,49 +0,0 @@ -// -// XmlDsigExcC14NWithCommentsTransform.cs - XmlDsigExcC14NWithCommentsTransform implementation for XML Encryption -// -// Author: -// Tim Coleman (tim@timcoleman.com) -// -// Copyright (C) Tim Coleman, 2004 - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - - -namespace System.Security.Cryptography.Xml { - public class XmlDsigExcC14NWithCommentsTransform : XmlDsigExcC14NTransform { - - #region Constructors - - public XmlDsigExcC14NWithCommentsTransform () - : base (true) - { - } - - public XmlDsigExcC14NWithCommentsTransform (string inclusiveNamespacesPrefixList) - : base (true, inclusiveNamespacesPrefixList) - { - } - - #endregion // Constructors - } -} - diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigNodeList.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigNodeList.cs deleted file mode 100644 index ec59a19befc..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigNodeList.cs +++ /dev/null @@ -1,65 +0,0 @@ -// -// XmlDsigNodeList.cs - derived node list class for dsig -// -// Author: -// Atsushi Enomoto -// -// (C)2004 Novell Inc. -// -// This class is mostly copied from System.Xml/XmlNodeArrayList.cs -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections; -using System.Xml; - -namespace System.Security.Cryptography.Xml -{ - // Copied from XmlNodeArrayList.cs - internal class XmlDsigNodeList : XmlNodeList - { - ArrayList _rgNodes; - - public XmlDsigNodeList (ArrayList rgNodes) - { - _rgNodes = rgNodes; - } - - public override int Count { get { return _rgNodes.Count; } } - - public override IEnumerator GetEnumerator () - { - return _rgNodes.GetEnumerator (); - } - - public override XmlNode Item (int index) - { - // Return null if index is out of range. by DOM design. - if (index < 0 || _rgNodes.Count <= index) - return null; - - return (XmlNode) _rgNodes [index]; - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXPathTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXPathTransform.cs deleted file mode 100644 index 6b6f04e6277..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXPathTransform.cs +++ /dev/null @@ -1,288 +0,0 @@ -// -// XmlDsigXPathTransform.cs - -// XmlDsigXPathTransform implementation for XML Signature -// http://www.w3.org/TR/1999/REC-xpath-19991116 -// -// Author: -// Sebastien Pouliot -// Atsushi Enomoto -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Collections; -using System.IO; -using System.Text; -using System.Xml; -using System.Xml.XPath; -using System.Xml.Xsl; - -namespace System.Security.Cryptography.Xml -{ - - // www.w3.org/TR/xmldsig-core/ - // see Section 6.6.3 of the XMLDSIG specification - public class XmlDsigXPathTransform : Transform - { - - private Type [] input; - private Type [] output; - private XmlNodeList xpath; - private XmlDocument doc; - private XsltContext ctx; - - public XmlDsigXPathTransform () - { - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform; - } - - public override Type [] InputTypes { - get { - if (input == null) { - input = new Type [3]; - input [0] = typeof (System.IO.Stream); - input [1] = typeof (System.Xml.XmlDocument); - input [2] = typeof (System.Xml.XmlNodeList); - } - return input; - } - } - - public override Type[] OutputTypes { - get { - if (output == null) { - // this way the result is cached if called multiple time - output = new Type [1]; - output [0] = typeof (System.Xml.XmlNodeList); - } - return output; - } - } - - protected override XmlNodeList GetInnerXml () - { - if (xpath == null) { - // default value - XmlDocument xpdoc = new XmlDocument (); - xpdoc.LoadXml (""); - xpath = xpdoc.ChildNodes; - } - return xpath; - } - - [MonoTODO ("Evaluation of extension function here() results in different from MS.NET (is MS.NET really correct??).")] - public override object GetOutput () - { - if ((xpath == null) || (doc == null)) - return new XmlDsigNodeList (new ArrayList ()); - // evaluate every time since input or xpath might have changed. - string x = null; - for (int i = 0; i < xpath.Count; i++) { - switch (xpath [i].NodeType) { - case XmlNodeType.Text: - case XmlNodeType.CDATA: - case XmlNodeType.Element: - x += xpath [i].InnerText; - break; - } - } - - ctx = new XmlDsigXPathContext (doc); - foreach (XmlNode n in xpath) { - XPathNavigator nav = n.CreateNavigator (); - XPathNodeIterator iter = nav.Select ("namespace::*"); - while (iter.MoveNext ()) - if (iter.Current.LocalName != "xml") - ctx.AddNamespace (iter.Current.LocalName, iter.Current.Value); - } - return EvaluateMatch (doc, x); - } - - public override object GetOutput (Type type) - { - if (type != typeof (XmlNodeList)) - throw new ArgumentException ("type"); - return GetOutput (); - } - - private XmlDsigNodeList EvaluateMatch (XmlNode n, string xpath) - { - ArrayList al = new ArrayList (); - // Strictly to say, document node is explicitly - // excluded by W3C spec (context node is initialized - // to the document root and XPath expression is - // "//. | //@* | //namespace::*) - XPathNavigator nav = n.CreateNavigator (); - XPathExpression exp = nav.Compile (xpath); - exp.SetContext (ctx); - EvaluateMatch (n, exp, al); - return new XmlDsigNodeList (al); - } - - private void EvaluateMatch (XmlNode n, XPathExpression exp, ArrayList al) - { - if (NodeMatches (n, exp)) - al.Add (n); - if (n.Attributes != null) - for (int i = 0; i < n.Attributes.Count; i++) - if (NodeMatches (n.Attributes [i], exp)) - al.Add (n.Attributes [i]); - for (int i = 0; i < n.ChildNodes.Count; i++) - EvaluateMatch (n.ChildNodes [i], exp, al); - } - - private bool NodeMatches (XmlNode n, XPathExpression exp) - { - // This looks waste of memory since it creates - // XPathNavigator every time, but even if we use - // XPathNodeIterator.Current, it also clones every time. - object ret = n.CreateNavigator ().Evaluate (exp); - if (ret is bool) - return (bool) ret; - if (ret is double) { - double d = (double) ret; - return !(d == 0.0 || Double.IsNaN (d)); - } - if (ret is string) - return ((string) ret).Length > 0; - if (ret is XPathNodeIterator) { - XPathNodeIterator retiter = (XPathNodeIterator) ret; - return retiter.Count > 0; - } - return false; - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - if (nodeList == null) - throw new CryptographicException ("nodeList"); - xpath = nodeList; - } - - public override void LoadInput (object obj) - { - // possible input: Stream, XmlDocument, and XmlNodeList - if (obj is Stream) { - doc = new XmlDocument (); - doc.PreserveWhitespace = true; - doc.XmlResolver = GetResolver (); - doc.Load (new XmlSignatureStreamReader ( - new StreamReader ((Stream) obj))); - } - else if (obj is XmlDocument) { - doc = (obj as XmlDocument); - } - else if (obj is XmlNodeList) { - doc = new XmlDocument (); - doc.XmlResolver = GetResolver (); - foreach (XmlNode xn in (obj as XmlNodeList)) { - XmlNode importedNode = doc.ImportNode (xn, true); - doc.AppendChild (importedNode); - } - } - } - - // Internal classes to support XPath extension function here() - - internal class XmlDsigXPathContext : XsltContext - { - XmlDsigXPathFunctionHere here; - public XmlDsigXPathContext (XmlNode node) - { - here = new XmlDsigXPathFunctionHere (node); - } - - public override IXsltContextFunction ResolveFunction ( - string prefix, string name, XPathResultType [] argType) - { - // Here MS.NET incorrectly allows arbitrary - // name e.g. "heretic()". - if (name == "here" && - prefix == String.Empty && - argType.Length == 0) - return here; - else - return null; // ???? - } - - public override bool Whitespace { - get { return true; } - } - - public override bool PreserveWhitespace (XPathNavigator node) - { - return true; - } - - public override int CompareDocument (string s1, string s2) - { - return String.Compare (s1, s2); - } - - public override IXsltContextVariable ResolveVariable (string prefix, string name) - { - throw new InvalidOperationException (); - } - } - - internal class XmlDsigXPathFunctionHere : IXsltContextFunction - { - // Static - - static XPathResultType [] types; - static XmlDsigXPathFunctionHere () - { - types = new XPathResultType [0]; - } - - // Instance - - XPathNodeIterator xpathNode; - - public XmlDsigXPathFunctionHere (XmlNode node) - { - xpathNode = node.CreateNavigator ().Select ("."); - } - - public XPathResultType [] ArgTypes { - get { return types; } - } - - public int Maxargs { get { return 0; } } - - public int Minargs { get { return 0; } } - - public XPathResultType ReturnType { - get { return XPathResultType.NodeSet; } - } - - public object Invoke (XsltContext ctx, object [] args, XPathNavigator docContext) - { - if (args.Length != 0) - throw new ArgumentException ("Not allowed arguments for function here().", "args"); - - return xpathNode.Clone (); - } - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXsltTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXsltTransform.cs deleted file mode 100644 index d039bf16730..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXsltTransform.cs +++ /dev/null @@ -1,155 +0,0 @@ -// -// XmlDsigEnvelopedSignatureTransform.cs - -// Enveloped Signature Transform implementation for XML Signature -// http://www.w3.org/TR/1999/REC-xslt-19991116 -// -// Author: -// Sebastien Pouliot (spouliot@motus.com) -// Atsushi Enomoto (atsushi@ximian.com) -// -// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com) -// (C) 2004 Novell Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.IO; -using System.Xml; -using System.Xml.Xsl; - -namespace System.Security.Cryptography.Xml -{ - - public class XmlDsigXsltTransform : Transform - { - - private Type [] input; - private Type [] output; - private bool comments; - private XmlNodeList xnl; - private XmlDocument inputDoc; - - public XmlDsigXsltTransform () : this (false) - { - } - - public XmlDsigXsltTransform (bool includeComments) - { - comments = includeComments; - Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform; - } - - public override Type [] InputTypes { - get { - if (input == null) { - input = new Type [3]; - input [0] = typeof (System.IO.Stream); - input [1] = typeof (System.Xml.XmlDocument); - input [2] = typeof (System.Xml.XmlNodeList); - } - return input; - } - } - - public override Type [] OutputTypes { - get { - if (output == null) { - output = new Type [1]; - output [0] = typeof (System.IO.Stream); - } - return output; - } - } - - protected override XmlNodeList GetInnerXml () - { - return xnl; - } - - public override object GetOutput () - { - if (xnl == null) - throw new ArgumentNullException ("LoadInnerXml before transformation."); - - XmlResolver resolver = GetResolver (); - - XslTransform xsl = new XslTransform (); - XmlDocument doc = new XmlDocument (); - doc.XmlResolver = resolver; - foreach (XmlNode n in xnl) - doc.AppendChild (doc.ImportNode (n, true)); - xsl.Load (doc, resolver); - - if (inputDoc == null) - throw new ArgumentNullException ("LoadInput before transformation."); - - MemoryStream stream = new MemoryStream (); - // only possible output: Stream - xsl.XmlResolver = resolver; - xsl.Transform (inputDoc, null, stream); - - stream.Seek (0, SeekOrigin.Begin); - return stream; - } - - public override object GetOutput (Type type) - { - if (type != typeof (Stream)) - throw new ArgumentException ("type"); - return GetOutput (); - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - if (nodeList == null) - throw new CryptographicException ("nodeList"); - xnl = nodeList; - } - - public override void LoadInput (object obj) - { - // possible input: Stream, XmlDocument, and XmlNodeList - Stream s = (obj as Stream); - if (s != null) { - inputDoc = new XmlDocument (); - inputDoc.XmlResolver = GetResolver (); -// inputDoc.Load (obj as Stream); - inputDoc.Load (new XmlSignatureStreamReader (new StreamReader (s))); - return; - } - - XmlDocument xd = (obj as XmlDocument); - if (xd != null) { - inputDoc = xd; - return; - } - - XmlNodeList nl = (obj as XmlNodeList); - if (nl != null) { - inputDoc = new XmlDocument (); - inputDoc.XmlResolver = GetResolver (); - for (int i = 0; i < nl.Count; i++) - inputDoc.AppendChild (inputDoc.ImportNode (nl [i], true)); - } - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlLicenseTransform.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlLicenseTransform.cs deleted file mode 100644 index 4cc6e172925..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlLicenseTransform.cs +++ /dev/null @@ -1,100 +0,0 @@ -// -// System.Security.Cryptography.Xml.XmlLicenseTransform class -// -// Author: -// Sebastien Pouliot -// -// Copyright (C) 2005 Novell, Inc (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Xml; - -namespace System.Security.Cryptography.Xml { - - public class XmlLicenseTransform : Transform { - - private IRelDecryptor _decryptor; - private Type[] inputTypes; - private Type[] outputTypes; - - public XmlLicenseTransform () - { - Algorithm = XmlSignature.AlgorithmNamespaces.XmlLicenseTransform; - } - - public IRelDecryptor Decryptor { - get { return _decryptor; } - set { _decryptor = value; } - } - - public override Type[] InputTypes { - get { - if (inputTypes == null) - inputTypes = new Type [1] { typeof (XmlDocument) }; - - return inputTypes; - } - } - - public override Type[] OutputTypes { - get { - if (outputTypes == null) - outputTypes = new Type [1] {typeof (XmlDocument)}; - - return outputTypes; - } - } - - [MonoTODO] - protected override XmlNodeList GetInnerXml () - { - return null; - } - - [MonoTODO] - public override object GetOutput () - { - return null; - } - - public override object GetOutput (Type type) - { - if (type != typeof (XmlDocument)) - throw new ArgumentException ("type"); - return GetOutput (); - } - - public override void LoadInnerXml (XmlNodeList nodeList) - { - // documented as not supported - } - - [MonoTODO] - public override void LoadInput (object obj) - { - if (_decryptor == null) - throw new CryptographicException (Locale.GetText ("missing decryptor")); - // TODO: check for element - // TODO: check for element - } - } -} diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs index 50b1924825d..1dc64eac1dc 100644 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs +++ b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs @@ -87,19 +87,6 @@ namespace System.Security.Cryptography.Xml { public AttributeNames () {} } - public class AlgorithmNamespaces { - public const string XmlDsigBase64Transform = "http://www.w3.org/2000/09/xmldsig#base64"; - public const string XmlDsigC14NTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"; - public const string XmlDsigC14NWithCommentsTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"; - public const string XmlDsigEnvelopedSignatureTransform = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"; - public const string XmlDsigXPathTransform = "http://www.w3.org/TR/1999/REC-xpath-19991116"; - public const string XmlDsigXsltTransform = "http://www.w3.org/TR/1999/REC-xslt-19991116"; - public const string XmlDsigExcC14NTransform = "http://www.w3.org/2001/10/xml-exc-c14n#"; - public const string XmlDsigExcC14NWithCommentsTransform = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments"; - public const string XmlDecryptionTransform = "http://www.w3.org/2002/07/decrypt#XML"; - public const string XmlLicenseTransform = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform"; - } - public class Uri { public const string Manifest = "http://www.w3.org/2000/09/xmldsig#Manifest"; } diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignatureStreamReader.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignatureStreamReader.cs deleted file mode 100644 index 43c7de00ef4..00000000000 --- a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignatureStreamReader.cs +++ /dev/null @@ -1,131 +0,0 @@ -// -// XmlSignatureStreamReader.cs: Wrap TextReader and eliminate \r -// -// Author: -// Atsushi Enomoto (atsushi@ximian.com) -// -// (C) 2005 Novell Inc. -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -// -// Use it to distinguish and \r. \r is removed, while is not. -// -// - -using System; -using System.IO; -using System.Runtime.InteropServices; - -namespace System.Security.Cryptography.Xml -{ - internal class XmlSignatureStreamReader : TextReader - { - TextReader source; - int cache = int.MinValue; - - public XmlSignatureStreamReader (TextReader input) - { - source =input; - } - - public override void Close () - { - source.Close (); - } - - public override int Peek () - { - // If source TextReader does not support Peek(), - // it does not support too. Or it just returns EOF. - if (source.Peek () == -1) - return -1; - - if (cache != int.MinValue) - return cache; - cache = source.Read (); - if (cache != '\r') - return cache; - // cache must be '\r' here. - if (source.Peek () != '\n') - return '\r'; - // Now Peek() returns '\n', so clear cache. - cache = int.MinValue; - return '\n'; - } - - public override int Read () - { - if (cache != int.MinValue) { - int ret = cache; - cache = int.MinValue; - return ret; - } - int i = source.Read (); - if (i != '\r') - return i; - // read one more char (after '\r') - cache = source.Read (); - if (cache != '\n') - return '\r'; - cache = int.MinValue; - return '\n'; - } - - public override int ReadBlock ( - [In, Out] char [] buffer, int index, int count) - { - char [] tmp = new char [count]; - source.ReadBlock (tmp, 0, count); - int j = index; - for (int i = 0; i < count; j++) { - if (tmp [i] == '\r') { - if (++i < tmp.Length && tmp [i] == '\n') - buffer [j] = tmp [i++]; - else - buffer [j] = '\r'; - } - else - buffer [j] = tmp [i]; - } - while (j < count) { - int d = Read (); - if (d < 0) - break; - buffer [j++] = (char) d; - } - return j; - } - - // I have no idea what to do here, but I don't think it - // makes sense. - public override string ReadLine () - { - return source.ReadLine (); - } - - public override string ReadToEnd () - { - return source.ReadToEnd ().Replace ("\r\n", "\n"); - } - } -} diff --git a/mcs/class/System.Security/System.Security.dll.sources b/mcs/class/System.Security/System.Security.dll.sources index 0beec42df40..b7e3fe65d34 100644 --- a/mcs/class/System.Security/System.Security.dll.sources +++ b/mcs/class/System.Security/System.Security.dll.sources @@ -4,7 +4,6 @@ corefx/SR.cs ../../build/common/Locale.cs Mono.Security.Cryptography/ManagedProtection.cs Mono.Security.Cryptography/NativeDapiProtection.cs -Mono.Xml/XmlCanonicalizer.cs System.Security.Cryptography/CryptographicAttribute.cs System.Security.Cryptography/CryptographicAttributeCollection.cs System.Security.Cryptography/CryptographicAttributeEnumerator.cs @@ -41,13 +40,34 @@ System.Security.Cryptography.Pkcs/SubjectIdentifier.cs System.Security.Cryptography.Pkcs/SubjectIdentifierOrKey.cs System.Security.Cryptography.Pkcs/SubjectIdentifierOrKeyType.cs System.Security.Cryptography.Pkcs/SubjectIdentifierType.cs +../System.Core/System.Security.Cryptography.X509Certificates/RSACertificateExtensions.cs System.Security.Cryptography.X509Certificates/X509Certificate2UI.cs System.Security.Cryptography.X509Certificates/X509SelectionFlag.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/AncestralNamespaceContextManager.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/AttributeSortOrder.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/C14NAncestralNamespaceContextManager.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalizationDispatcher.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXml.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlAttribute.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlCDataSection.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlComment.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlDocument.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlElement.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlEntityReference.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlNodeList.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlProcessingInstruction.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlSignificantWhitespace.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlText.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXmlWhitespace.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CertUsageType.cs System.Security.Cryptography.Xml/CipherData.cs System.Security.Cryptography.Xml/CipherReference.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CryptoHelpers.cs System.Security.Cryptography.Xml/DataObject.cs System.Security.Cryptography.Xml/DataReference.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DocPosition.cs System.Security.Cryptography.Xml/DSAKeyValue.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/DSASignatureDescription.cs System.Security.Cryptography.Xml/EncryptedData.cs System.Security.Cryptography.Xml/EncryptedKey.cs System.Security.Cryptography.Xml/EncryptedReference.cs @@ -56,6 +76,9 @@ System.Security.Cryptography.Xml/EncryptedXml.cs System.Security.Cryptography.Xml/EncryptionMethod.cs System.Security.Cryptography.Xml/EncryptionProperties.cs System.Security.Cryptography.Xml/EncryptionProperty.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/ExcAncestralNamespaceContextManager.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/ExcCanonicalXml.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/ICanonicalizableNode.cs System.Security.Cryptography.Xml/IRelDecryptor.cs System.Security.Cryptography.Xml/KeyInfoClause.cs System.Security.Cryptography.Xml/KeyInfo.cs @@ -66,30 +89,39 @@ System.Security.Cryptography.Xml/KeyInfoRetrievalMethod.cs System.Security.Cryptography.Xml/KeyInfoX509Data.cs System.Security.Cryptography.Xml/KeyReference.cs System.Security.Cryptography.Xml/Manifest.cs -System.Security.Cryptography.Xml/Reference.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/MyXmlDocument.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/NamespaceFrame.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/NamespaceSortOrder.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Reference.cs System.Security.Cryptography.Xml/ReferenceList.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/ReferenceTargetType.cs System.Security.Cryptography.Xml/RSAKeyValue.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA1SignatureDescription.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA256SignatureDescription.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA384SignatureDescription.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SHA512SignatureDescription.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/RSAPKCS1SignatureDescription.cs System.Security.Cryptography.Xml/Signature.cs System.Security.Cryptography.Xml/SignedInfo.cs System.Security.Cryptography.Xml/SignedXml.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXmlDebugLog.cs System.Security.Cryptography.Xml/SymmetricKeyWrap.cs -System.Security.Cryptography.Xml/TransformChain.cs -System.Security.Cryptography.Xml/Transform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Transform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/TransformChain.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/Utils.cs System.Security.Cryptography.Xml/X509IssuerSerial.cs -System.Security.Cryptography.Xml/XmlDecryptionTransform.cs -System.Security.Cryptography.Xml/XmlDsigBase64Transform.cs -System.Security.Cryptography.Xml/XmlDsigC14NTransform.cs -System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransform.cs -System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs -System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs -System.Security.Cryptography.Xml/XmlDsigExcC14NWithCommentsTransform.cs -System.Security.Cryptography.Xml/XmlDsigNodeList.cs -System.Security.Cryptography.Xml/XmlDsigXPathTransform.cs -System.Security.Cryptography.Xml/XmlDsigXsltTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDecryptionTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigBase64Transform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigC14NTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigC14NWithCommentsTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigEnvelopedSignatureTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigExcC14NTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigExcC14NWithCommentsTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigXPathTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlDsigXsltTransform.cs System.Security.Cryptography.Xml/XmlEncryption.cs -System.Security.Cryptography.Xml/XmlLicenseTransform.cs +../../../external/corefx/src/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/XmlLicenseTransform.cs System.Security.Cryptography.Xml/XmlSignature.cs -System.Security.Cryptography.Xml/XmlSignatureStreamReader.cs ../../build/common/MonoTODOAttribute.cs System.Security.Permissions/DataProtectionPermission.cs System.Security.Permissions/DataProtectionPermissionAttribute.cs diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs index 8920ac34218..06dfb70c42f 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ReferenceTest.cs @@ -33,11 +33,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { { Assert.IsNull (reference.Uri, "Uri (null)"); Assert.IsNotNull (reference.TransformChain, "TransformChain"); - Assert.AreEqual ("System.Security.Cryptography.Xml.Reference", reference.ToString (), "ToString()"); // test uri constructor string uri = "uri"; reference = new Reference (uri); - Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#sha1", reference.DigestMethod, "DigestMethod"); + Assert.AreEqual (SignedXml.XmlDsigSHA256Url, reference.DigestMethod, "DigestMethod"); Assert.IsNull (reference.DigestValue, "DigestValue"); Assert.IsNull (reference.Id, "Id"); Assert.IsNull (reference.Type, "Type"); @@ -158,17 +157,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] - [Category ("NotDotNet")] - // MS throws a NullReferenceException (reported as FDBK25886) but only when executed in NUnit - // http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=3596d1e3-362b-40bd-bca9-2e8be75261ff public void AddAllTransforms () { - // adding an empty hash value - byte[] hash = new byte [20]; - reference.DigestValue = hash; - XmlElement xel = reference.GetXml (); - // this is the minimal Reference (DigestValue)! - Assert.IsNotNull (xel, "GetXml"); + reference.DigestMethod = SignedXml.XmlDsigSHA1Url; + reference.DigestValue = new byte [20]; reference.AddTransform (new XmlDsigBase64Transform ()); reference.AddTransform (new XmlDsigC14NTransform ()); @@ -177,13 +169,8 @@ namespace MonoTests.System.Security.Cryptography.Xml { reference.AddTransform (new XmlDsigXPathTransform ()); reference.AddTransform (new XmlDsigXsltTransform ()); - // MS's results - string test1 = "AAAAAAAAAAAAAAAAAAAAAAAAAAA="; - // Mono's result (xml is equivalent but not identical) - string test2 = test1.Replace ("", ""); - string result = reference.GetXml().OuterXml; - Assert.IsTrue (((result == test1) || (result == test2)), result); - // however this value cannot be loaded as it's missing some transform (xslt) parameters + const string expected = "AAAAAAAAAAAAAAAAAAAAAAAAAAA="; + Assert.That (reference.GetXml ().OuterXml, Is.EqualTo (expected), "OuterXml"); // can we add them again ? reference.AddTransform (new XmlDsigBase64Transform ()); diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs index 1c1d7a97772..0a06e23aa70 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs @@ -790,6 +790,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl; Reference reference = new Reference (); + reference.DigestMethod = SignedXml.XmlDsigSHA1Url; reference.Uri = ""; XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform (); diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs index abb64bb34b5..a21c4963003 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs @@ -157,7 +157,6 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] - [Category ("NotDotNet")] // see LoadInputAsXmlNodeList2 description public void LoadInputAsXmlNodeList () { @@ -166,11 +165,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { transform.LoadInput (doc.ChildNodes); Stream s = (Stream) transform.GetOutput (); string output = Stream2String (s); - Assert.AreEqual ("", output, "XmlChildNodes"); + Assert.AreEqual ("", output, "XmlChildNodes"); } [Test] - [Category ("NotDotNet")] // MS has a bug that those namespace declaration nodes in // the node-set are written to output. Related spec section is: // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel @@ -180,7 +178,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { transform.LoadInput (doc.SelectNodes ("//*")); Stream s = (Stream) transform.GetOutput (); string output = Stream2String (s); - string expected = @""; + string expected = ""; Assert.AreEqual (expected, output, "XmlChildNodes"); } @@ -507,20 +505,6 @@ namespace MonoTests.System.Security.Cryptography.Xml { Assert.AreEqual (xml, output); } - [Test] - public void PrefixlessNamespaceOutput () - { - XmlDocument doc = new XmlDocument (); - doc.AppendChild (doc.CreateElement ("foo", "urn:foo")); - doc.DocumentElement.AppendChild (doc.CreateElement ("bar", "urn:bar")); - Assert.AreEqual (String.Empty, doc.DocumentElement.GetAttribute ("xmlns"), "#1"); - XmlDsigC14NTransform t = new XmlDsigC14NTransform (); - t.LoadInput (doc); - Stream s = t.GetOutput () as Stream; - Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), ""); - Assert.AreEqual ("urn:foo", doc.DocumentElement.GetAttribute ("xmlns"), "#2"); - } - [Test] [Ignore ("find out how PropagatedNamespaces returns non-null instance on .NET")] public void PropagatedNamespaces () diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs index 7b56a240055..d14b5ee2802 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs @@ -251,7 +251,6 @@ namespace MonoTests.System.Security.Cryptography.Xml { } [Test] - [Category ("NotDotNet")] // see LoadInputAsXmlNodeList2 description public void LoadInputAsXmlNodeList () { @@ -260,11 +259,10 @@ namespace MonoTests.System.Security.Cryptography.Xml { transform.LoadInput (doc.ChildNodes); Stream s = (Stream) transform.GetOutput (); string output = Stream2String (s); - Assert.AreEqual ("", output, "XmlChildNodes"); + Assert.AreEqual ("", output, "XmlChildNodes"); } [Test] - [Category ("NotDotNet")] // MS has a bug that those namespace declaration nodes in // the node-set are written to output. Related spec section is: // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel @@ -274,7 +272,7 @@ namespace MonoTests.System.Security.Cryptography.Xml { transform.LoadInput (doc.SelectNodes ("//*")); Stream s = (Stream) transform.GetOutput (); string output = Stream2String (s); - string expected = @""; + string expected = ""; Assert.AreEqual (expected, output, "XmlChildNodes"); } diff --git a/mcs/class/System.Security/corefx/SR.cs b/mcs/class/System.Security/corefx/SR.cs index 6b6ac476f56..37820522a3a 100644 --- a/mcs/class/System.Security/corefx/SR.cs +++ b/mcs/class/System.Security/corefx/SR.cs @@ -21,6 +21,7 @@ partial class SR public const string Cryptography_Xml_InvalidReference = "Malformed reference element."; public const string Cryptography_Xml_InvalidSignatureLength = "The length of the signature with a MAC should be less than the hash output length."; public const string Cryptography_Xml_InvalidSignatureLength2 = "The length in bits of the signature with a MAC should be a multiple of 8."; + public const string Cryptography_Xml_InvalidX509IssuerSerialNumber = "X509 issuer serial number is invalid."; public const string Cryptography_Xml_KeyInfoRequired = "A KeyInfo element is required to check the signature."; public const string Cryptography_Xml_KW_BadKeySize = "The length of the encrypted data in Key Wrap is either 32, 40 or 48 bytes."; public const string Cryptography_Xml_LoadKeyFailed = "Signing key is not loaded."; -- 2.25.1