diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2007-01-22 23:48:17 +0300 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2007-01-22 23:48:17 +0300 |
commit | 6e62bf5a02fba751ff232f38124a8324a0bbf30d (patch) | |
tree | 850ae3e71f09894ac62d47fc53dfde9711b0f7c8 /mcs/class/System.Security/Test | |
parent | 532e97f63f98e095deab93a290d5c2bd11a2490c (diff) |
2007-01-22 Atsushi Enomoto <atsushi@ximian.com>
* XmlDsigExcC14NTransformTest.cs, XmlDsigC14NTransformTest.cs,
SignedXmlTest.cs : added some more tests which blocks indigo.
svn path=/trunk/mcs/; revision=71462
Diffstat (limited to 'mcs/class/System.Security/Test')
4 files changed, 81 insertions, 0 deletions
diff --git a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog index 155ab782ce8..dd7279ce4f8 100644 --- a/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog +++ b/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog @@ -1,3 +1,8 @@ +2007-01-22 Atsushi Enomoto <atsushi@ximian.com> + + * XmlDsigExcC14NTransformTest.cs, XmlDsigC14NTransformTest.cs, + SignedXmlTest.cs : added some more tests which blocks indigo. + 2007-01-17 Atsushi Enomoto <atsushi@ximian.com> * XmlDsigExcC14NTransformTest.cs : new tests, mostly copied from 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 f5b88362012..8939a4cbe14 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 @@ -538,6 +538,54 @@ namespace MonoTests.System.Security.Cryptography.Xml { signedXml.ComputeSignature (); } + [Test] + public void SignElementWithoutPrefixedNamespace () + { + string input = "<Action xmlns='urn:foo'>http://tempuri.org/IFoo/Echo</Action>"; + string expected = @"<Signature xmlns=""http://www.w3.org/2000/09/xmldsig#""><SignedInfo><CanonicalizationMethod Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315"" /><SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#hmac-sha1"" /><Reference URI=""#_1""><Transforms><Transform Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315"" /></Transforms><DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" /><DigestValue>zdFEZB8rNzvpNG/gFEJBWk/M5Nk=</DigestValue></Reference></SignedInfo><SignatureValue>+OyGVzrHjmKSDWLNyvgx8pjbPfM=</SignatureValue><Object Id=""_1""><Action xmlns=""urn:foo"">http://tempuri.org/IFoo/Echo</Action></Object></Signature>"; + + byte [] decrypted = Convert.FromBase64String ( + "1W5EigVnbnRjGLbg99ElieOmuUgYO+KcwMJtE35SAGI="); + AssertEquals (expected, SignWithHMACSHA1 (input, decrypted)); + } + + [Test] + [Category ("NotWorking")] + public void SignElementWithPrefixedNamespace () + { + string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>"; + string expected = @"<Signature xmlns=""http://www.w3.org/2000/09/xmldsig#""><SignedInfo><CanonicalizationMethod Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315"" /><SignatureMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#hmac-sha1"" /><Reference URI=""#_1""><Transforms><Transform Algorithm=""http://www.w3.org/TR/2001/REC-xml-c14n-20010315"" /></Transforms><DigestMethod Algorithm=""http://www.w3.org/2000/09/xmldsig#sha1"" /><DigestValue>6i5FlqkEfJOdUaOMCK7xn0I0HDg=</DigestValue></Reference></SignedInfo><SignatureValue>tASp+e2A0xqcm02jKg5TGqlhKpI=</SignatureValue><Object Id=""_1""><a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action></Object></Signature>"; + + byte [] decrypted = Convert.FromBase64String ( + "1W5EigVnbnRjGLbg99ElieOmuUgYO+KcwMJtE35SAGI="); + AssertEquals (expected, SignWithHMACSHA1 (input, decrypted)); + } + + string SignWithHMACSHA1 (string input, byte [] key) + { + XmlDocument doc = new XmlDocument (); + doc.LoadXml (input); + SignedXml sxml = new SignedXml (doc); + + HMACSHA1 keyhash = new HMACSHA1 (key); + DataObject d = new DataObject (); + //d.Data = doc.SelectNodes ("//*[local-name()='Body']/*"); + d.Data = doc.SelectNodes ("//*[local-name()='Action']"); + d.Id = "_1"; + sxml.AddObject (d); + Reference r = new Reference ("#_1"); + //r.AddTransform (new XmlDsigExcC14NTransform ()); + r.AddTransform (new XmlDsigC14NTransform ()); + r.DigestMethod = SignedXml.XmlDsigSHA1Url; + sxml.SignedInfo.AddReference (r); + sxml.ComputeSignature (keyhash); + StringWriter sw = new StringWriter (); + XmlWriter w = new XmlTextWriter (sw); + sxml.GetXml ().WriteTo (w); + w.Close (); + return sw.ToString (); + } + #if NET_2_0 [Test] [Category ("NotWorking")] // bug #79483 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 5a59b45bd5f..454f16c9bee 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 @@ -472,5 +472,19 @@ namespace MonoTests.System.Security.Cryptography.Xml { "]"; static string C14NSpecExample7Output = "<e1 xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\" xml:space=\"preserve\"></e3></e1>"; + + [Test] + public void SimpleNamespacePrefixes () + { + string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>"; + string expected = @"<a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action>"; + + XmlDocument doc = new XmlDocument (); + doc.LoadXml (input); + XmlDsigC14NTransform t = new XmlDsigC14NTransform (); + t.LoadInput (doc); + Stream s = t.GetOutput () as Stream; + AssertEquals (expected, new StreamReader (s, Encoding.UTF8).ReadToEnd ()); + } } } 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 ac00aaebe28..678644f3253 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 @@ -479,6 +479,20 @@ namespace MonoTests.System.Security.Cryptography.Xml { "]"; static string ExcC14NSpecExample7Output = "<e1 xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\" xml:space=\"preserve\"></e3></e1>"; + + [Test] + public void SimpleNamespacePrefixes () + { + string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>"; + string expected = @"<a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action>"; + + XmlDocument doc = new XmlDocument (); + doc.LoadXml (input); + XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform (); + t.LoadInput (doc); + Stream s = t.GetOutput () as Stream; + AssertEquals (expected, new StreamReader (s, Encoding.UTF8).ReadToEnd ()); + } } } |