2006-10-11 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 10 Oct 2006 23:11:22 +0000 (23:11 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 10 Oct 2006 23:11:22 +0000 (23:11 -0000)
* SignedXml.cs : when SigningMethod does not match the algorithm that
  the key actually supports, it raises an error.

* SignedXmlTest.cs : added a test for signature method mismatch.

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

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 2446e0d0bddf2e977c199ed1462d782fa1fe01eb..c99d2435b1ea8f353dc3010594d148ef009cd6de 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * SignedXml.cs : when SigningMethod does not match the algorithm that
+         the key actually supports, it raises an error.
+
 2006-09-22  Atsushi Enomoto  <atsushi@ximian.com>
 
        * EncryptedXml.cs : use Padding member instead of const ISO10126 (though
index 4d30baa407f58959b45003717ba4fc06b8704c5f..0deb351d9d15c09678bd9dfd2bd60476a1206086 100644 (file)
@@ -623,8 +623,11 @@ namespace System.Security.Cryptography.Xml {
                public void ComputeSignature () 
                {
                        if (key != null) {
-                               // required before hashing
-                               m_signature.SignedInfo.SignatureMethod = key.SignatureAlgorithm;
+                               if (m_signature.SignedInfo.SignatureMethod == null)
+                                       // required before hashing
+                                       m_signature.SignedInfo.SignatureMethod = key.SignatureAlgorithm;
+                               else if (m_signature.SignedInfo.SignatureMethod != key.SignatureAlgorithm)
+                                       throw new CryptographicException ("Specified SignatureAlgorithm is not supported by the signing key.");
                                DigestReferences ();
 
                                AsymmetricSignatureFormatter signer = null;
index 3db849e2361eb3f0edf155f1b2bb3d1dbae51d00..d1b915266a8203e9bed14cc4c15c14f78bc1ddfc 100644 (file)
@@ -1,3 +1,7 @@
+2006-10-11  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * SignedXmlTest.cs : added a test for signature method mismatch.
+
 2006-09-25  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * SignedXmlTest.cs: Added tests for bug #79454 and bug #79483 (marked
index 014783199ad214d2baf4c2f6dcfedec13a223579..df91d52f7e47b81b4980c6d571fb8fae7d990989 100644 (file)
@@ -154,6 +154,26 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        return signedXml;
                }
 
+               [Test]
+               [ExpectedException (typeof (CryptographicException))]
+               public void SignatureMethodMismatch () 
+               {
+                       SignedXml signedXml = MSDNSample ();
+
+                       RSA key = RSA.Create ();
+                       signedXml.SigningKey = key;
+                       signedXml.SignedInfo.SignatureMethod = SignedXml.XmlDsigHMACSHA1Url;
+
+                       // Add a KeyInfo.
+                       KeyInfo keyInfo = new KeyInfo ();
+                       keyInfo.AddClause (new RSAKeyValue (key));
+                       signedXml.KeyInfo = keyInfo;
+
+                       AssertNotNull ("SignatureMethod", signedXml.SignatureMethod);
+                       // Compute the signature - causes unsupported algorithm by the key.
+                       signedXml.ComputeSignature ();
+               }
+
                [Test]
                public void AsymmetricRSASignature () 
                {