2007-01-12 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 12 Jan 2007 10:51:17 +0000 (10:51 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 12 Jan 2007 10:51:17 +0000 (10:51 -0000)
* SignedXml.cs : actually ComputeSignature() itself does not raise
  silly exception. It always use CryptographicException.
  Added another check; malformed reference object.

* SignedXmlTest.cs : fixed ComputeSignatureNoSigningKey() to not
  expect silly exception. Added test for malformed reference.

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

mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs
mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
mcs/class/System.Security/Test/System.Security.Cryptography.Xml/SignedXmlTest.cs

index cc2463381373499f5ec16f49c804cbb146f830b6..b290b234dcecf51ec4c94172c420f257d772e42d 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-12  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * SignedXml.cs : actually ComputeSignature() itself does not raise
+         silly exception. It always use CryptographicException.
+         Added another check; malformed reference object.
+
 2007-01-12  Atsushi Enomoto  <atsushi@ximian.com>
 
        * SignedXml.cs : ComputeSignature() should check empty key.
index 29144c2e432ddc94fee35824cc4c8db7a9280257..1005fe522381ee1bcce7ae11ed6adb53a5a15ed3 100644 (file)
@@ -314,14 +314,18 @@ namespace System.Security.Cryptography.Xml {
                                        }
                                }
                                if (objectName != null) {
+                                       bool found = false;
                                        foreach (DataObject obj in m_signature.ObjectList) {
                                                if (obj.Id == objectName) {
                                                        XmlElement xel = obj.GetXml ();
                                                        doc.LoadXml (xel.OuterXml);
                                                        FixupNamespaceNodes (xel, doc.DocumentElement);
+                                                       found = true;
                                                        break;
                                                }
                                        }
+                                       if (!found)
+                                               throw new CryptographicException (String.Format ("Malformed reference object: {0}", objectName));
                                }
                        }
 
@@ -649,11 +653,7 @@ namespace System.Security.Cryptography.Xml {
                                }
                        }
                        else
-#if NET_2_0 // correct
                                throw new CryptographicException ("signing key is not specified");
-#else // silly
-                               throw new ArgumentNullException ("signing key is not specified");
-#endif
                }
 
                public void ComputeSignature (KeyedHashAlgorithm macAlg) 
index 8ae0798ad5afb18433862c4da82aaa8a8a25689c..899e870224b1f05652178c4dded9f03ac69f3e43 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-12  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * SignedXmlTest.cs : fixed ComputeSignatureNoSigningKey() to not
+         expect silly exception. Added test for malformed reference.
+
 2007-01-12  Atsushi Enomoto  <atsushi@ximian.com>
 
        * SignedXmlTest.cs : added ComputeSignatureNoSigningKey().
index e476bea353efd5c1e951d3dd4d2006972b8d1475..89e5fb53e3ca3cc2485d432d26d123b7f4af8bc6 100644 (file)
@@ -482,14 +482,12 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                }
 
                [Test]
-#if NET_2_0
-               [ExpectedException (typeof (CryptographicException))] // correct
-#else
-               [ExpectedException (typeof (ArgumentNullException))] // silly
-#endif
+               [ExpectedException (typeof (CryptographicException))]
                public void ComputeSignatureNoSigningKey ()
                {
-                       SignedXml signedXml = new SignedXml (new XmlDocument ());
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml ("<foo/>");
+                       SignedXml signedXml = new SignedXml (doc);
 
                        Reference reference = new Reference ();
                        reference.Uri = "";
@@ -501,6 +499,26 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        signedXml.ComputeSignature ();
                }
 
+               [Test]
+               [ExpectedException (typeof (CryptographicException))]
+               public void ComputeSignatureMissingReferencedObject ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml ("<foo/>");
+                       SignedXml signedXml = new SignedXml (doc);
+                       DSA key = DSA.Create ();
+                       signedXml.SigningKey = key;
+
+                       Reference reference = new Reference ();
+                       reference.Uri = "#bleh";
+
+                       XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform ();
+                       reference.AddTransform (env);
+                       signedXml.AddReference (reference);
+
+                       signedXml.ComputeSignature ();
+               }
+
 #if NET_2_0
                [Test]
                [Category ("NotWorking")] // bug #79483