2004-03-17 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 17 Mar 2004 00:33:57 +0000 (00:33 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 17 Mar 2004 00:33:57 +0000 (00:33 -0000)
* SignedXml.cs : the result from enveloped signature transform should
  be canonicalized before getting its hash.
* XmlDsigEnvelopedSignatureTransform.cs : in XPath selection,
  if the node is Signature itself it is not allowed.
  PreserveWhitespace is required.

svn path=/trunk/mcs/; revision=24197

mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs

index 5b0e68487db12954207826df0b3890dc8858c6c2..650d60819f98bf05f4f385812cfd79b5aaf66d99 100644 (file)
@@ -1,3 +1,11 @@
+2004-03-17  Atsushi Enomoto <atsushi@ximian.com>
+
+       * SignedXml.cs : the result from enveloped signature transform should
+         be canonicalized before getting its hash.
+       * XmlDsigEnvelopedSignatureTransform.cs : in XPath selection,
+         if the node is Signature itself it is not allowed.
+         PreserveWhitespace is required.
+
 2004-03-16  Sebastien Pouliot  <sebastien@ximian.com>
 
        * SignedXml.cs: Changed (again). This time we use the Stream when 
index 526045153fdd212441c9de6a759912e971bb3d4f..270a5845481ad6e22b4ebfe7a6e01947669a97f4 100644 (file)
@@ -109,19 +109,11 @@ namespace System.Security.Cryptography.Xml {
 
                        t.LoadInput (doc);
                        if (t is XmlDsigEnvelopedSignatureTransform) {
-                               object o = t.GetOutput ();
-                               MemoryStream ms = new MemoryStream ();
-                               XmlTextWriter xw = new XmlTextWriter (ms, Encoding.UTF8);
-                               XmlDocument d = o as XmlDocument;
-                               if (d != null)
-                                       d.Save (xw);
-                               else {
-                                       XmlNodeList nl = (XmlNodeList) o;
-                                       foreach (XmlNode n in nl)
-                                               n.WriteTo (xw);
-                               }
-                               // don't close xw (and thus ms).
-                               return ms;
+                               // It returns XmlDocument for XmlDocument input.
+                               doc = (XmlDocument) t.GetOutput ();
+                               Transform c14n = GetC14NMethod ();
+                               c14n.LoadInput (doc);
+                               return (Stream) c14n.GetOutput ();
                        }
 
                        object obj = t.GetOutput ();
@@ -207,17 +199,22 @@ namespace System.Security.Cryptography.Xml {
                                r.DigestValue = GetReferenceHash (r);
                        }
                }
-               
-               private Stream SignedInfoTransformed () 
+
+               private Transform GetC14NMethod ()
                {
                        Transform t = (Transform) CryptoConfig.CreateFromName (signature.SignedInfo.CanonicalizationMethod);
                        if (t == null)
                                throw new CryptographicException ("Unknown Canonicalization Method {0}", signature.SignedInfo.CanonicalizationMethod);
+                       return t;
+               }
+
+               private Stream SignedInfoTransformed () 
+               {
+                       Transform t = GetC14NMethod ();
 
                        if (signatureElement != null) {
                                // TODO - check signature.SignedInfo.Id
                                XmlNodeList xnl = signatureElement.GetElementsByTagName (XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI);
-
                                byte[] si = Encoding.UTF8.GetBytes (xnl [0].OuterXml);
                                MemoryStream ms = new MemoryStream ();
                                ms.Write (si, 0, si.Length);
index 5f610cb7546ac3d51ba0832cf4eb7d2254c610d9..c7693f9410ecb01db0eeb25fee5554bc51286d8a 100644 (file)
@@ -77,6 +77,7 @@ namespace System.Security.Cryptography.Xml {
                        // possible input: Stream, XmlDocument, and XmlNodeList
                        if (inputObj is Stream) {
                                doc = new XmlDocument ();
+                               doc.PreserveWhitespace = true;
                                doc.XmlResolver = GetResolver ();
                                doc.Load (inputObj as Stream);
                                return GetOutputFromNode (doc, GetNamespaceManager (doc), true);
@@ -122,7 +123,7 @@ namespace System.Security.Cryptography.Xml {
                {
                        XmlDocument doc = input is XmlDocument ? input as XmlDocument : input.OwnerDocument;
                        if (remove) {
-                               XmlNodeList nl = input.SelectNodes ("//dsig:Signature", nsmgr);
+                               XmlNodeList nl = input.SelectNodes ("descendant-or-self::dsig:Signature", nsmgr);
                                foreach (XmlNode n in nl)
                                        n.ParentNode.RemoveChild (n);
                        }