Author: atsushi
Date: 2007-01-17 12:30:12 -0500 (Wed, 17 Jan 2007)
New Revision: 71220
Added:
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs
Modified:
trunk/mcs/class/System.Security/ChangeLog
trunk/mcs/class/System.Security/Mono.Xml/ChangeLog
trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
trunk/mcs/class/System.Security/System.Security_test.dll.sources
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
trunk/mcs/class/System.Security/Test/standalone_tests/ChangeLog
trunk/mcs/class/System.Security/Test/standalone_tests/Makefile
trunk/mcs/class/System.Security/Test/standalone_tests/xmldsig.cs
Log:
2007-01-17 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlCanonicalizer.cs : don't output default namespace when the node's
namespace is not empty. Check "visibly utilized" namespace nodes in
exc-c14n. Also, in exc-c14n, rendered namespaces are not written.
Added InclusiveNamespaces PrefixList field (not in use yet).
* XmlDsigExcC14NTransform.cs :
re-imported from XmlDsigC14NTransform.cs.
* System.Security_test.dll.sources : added
XmlDsigExcC14NTransformTest.cs.
* XmlDsigExcC14NTransformTest.cs : new tests, mostly copied from
non-exc test.
* xmldsig.cs : exc-c14n tests could be run under 2.0 profile (and
they are not working correctly yet).
* Makefile : Added net_2_0 profile support.
Modified: trunk/mcs/class/System.Security/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/ChangeLog 2007-01-17 17:29:52 UTC (rev
71219)
+++ trunk/mcs/class/System.Security/ChangeLog 2007-01-17 17:30:12 UTC (rev
71220)
@@ -1,3 +1,8 @@
+2007-01-17 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * System.Security_test.dll.sources : added
+ XmlDsigExcC14NTransformTest.cs.
+
2006-12-15 Sebastien Pouliot <[EMAIL PROTECTED]>
* Makefile: Execute PKITS tests only if the data is installed locally.
Modified: trunk/mcs/class/System.Security/Mono.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/Mono.Xml/ChangeLog 2007-01-17 17:29:52 UTC
(rev 71219)
+++ trunk/mcs/class/System.Security/Mono.Xml/ChangeLog 2007-01-17 17:30:12 UTC
(rev 71220)
@@ -1,3 +1,10 @@
+2007-01-17 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlCanonicalizer.cs : don't output default namespace when the node's
+ namespace is not empty. Check "visibly utilized" namespace nodes in
+ exc-c14n. Also, in exc-c14n, rendered namespaces are not written.
+ Added InclusiveNamespaces PrefixList field (not in use yet).
+
2005-04-04 Atsushi Enomoto <[EMAIL PROTECTED]>
* XmlCanonicalizer.cs : don't rip 
 off here.
Modified: trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
===================================================================
--- trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
2007-01-17 17:29:52 UTC (rev 71219)
+++ trunk/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs
2007-01-17 17:30:12 UTC (rev 71220)
@@ -48,6 +48,7 @@
// c14n parameters
private bool comments;
private bool exclusive;
+ string inclusiveNamespacesPrefixList;
// input/output
private XmlNodeList xnl;
@@ -87,6 +88,12 @@
return Canonicalize (nodes[0].OwnerDocument);
}
+ // See xml-enc-c14n specification
+ public string InclusiveNamespacesPrefixList {
+ get { return inclusiveNamespacesPrefixList; }
+ set { inclusiveNamespacesPrefixList = value; }
+ }
+
private void WriteNode (XmlNode node)
{
// Console.WriteLine ("C14N Debug: node=" + node.Name);
@@ -226,7 +233,7 @@
bool has_empty_namespace = false;
ArrayList list = new ArrayList ();
for (XmlNode cur = node; cur != null && cur != doc; cur
= cur.ParentNode) {
- foreach (XmlNode attribute in cur.Attributes) {
+ foreach (XmlAttribute attribute in
cur.Attributes) {
if (!IsNamespaceNode (attribute))
continue;
@@ -252,6 +259,13 @@
// check that we have not rendered it
yet
bool rendered = IsNamespaceRendered
(prefix, attribute.Value);
+ // For exc-c14n, only visually utilized
+ // namespaces are written.
+ if (exclusive && rendered)
+ continue;
+ if (exclusive && !IsVisiblyUtilized
(node as XmlElement, attribute))
+ continue;
+
// add to the visible namespaces stack
if (visible)
visibleNamespaces.Add
(attribute);
@@ -264,8 +278,8 @@
}
}
- // add empty namespace if needed
- if (visible && !has_empty_namespace &&
!IsNamespaceRendered (string.Empty, string.Empty))
+ // 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
());
@@ -441,7 +455,8 @@
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
@@ -456,7 +471,30 @@
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
Modified:
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
2007-01-17 17:29:52 UTC (rev 71219)
+++ trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
2007-01-17 17:30:12 UTC (rev 71220)
@@ -1,3 +1,8 @@
+2007-01-17 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlDsigExcC14NTransform.cs :
+ re-imported from XmlDsigC14NTransform.cs.
+
2007-01-12 Atsushi Enomoto <[EMAIL PROTECTED]>
* SignedXml.cs : when there is an envelope document and no referenced
Modified:
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
===================================================================
---
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
2007-01-17 17:29:52 UTC (rev 71219)
+++
trunk/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigExcC14NTransform.cs
2007-01-17 17:30:12 UTC (rev 71220)
@@ -1,11 +1,16 @@
//
-// XmlDsigExcC14NTransform.cs - XmlDsigExcC14NTransform implementation for XML
Encryption
+// XmlDsigExcC14NTransform.cs - ExcC14N Transform implementation for XML
Signature
+// http://www.w3.org/TR/xml-c14n
//
-// Author:
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+// Aleksey Sanin ([EMAIL PROTECTED])
// Tim Coleman ([EMAIL PROTECTED])
//
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// (C) 2003 Aleksey Sanin ([EMAIL PROTECTED])
// 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
@@ -26,55 +31,45 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-
#if NET_2_0
-using Mono.Xml;
+using System.Collections;
using System.IO;
+using System.Runtime.InteropServices;
+using System.Text;
using System.Xml;
-namespace System.Security.Cryptography.Xml {
- public class XmlDsigExcC14NTransform : Transform {
+using Mono.Xml;
- #region Fields
+namespace System.Security.Cryptography.Xml {
- XmlCanonicalizer canonicalizer;
- object inputObj;
- string inclusiveNamespacesPrefixList;
- bool includeComments;
-
- #endregion // Fields
-
- #region Constructors
-
- public XmlDsigExcC14NTransform ()
+ public class XmlDsigExcC14NTransform : Transform {
+ private Type[] input;
+ private Type[] output;
+ private XmlCanonicalizer canonicalizer;
+ private Stream s;
+ private string inclusiveNamespacesPrefixList;
+
+ public XmlDsigExcC14NTransform ()
+ : this (false, null)
{
- Algorithm =
XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform;
- canonicalizer = new XmlCanonicalizer (true, false);
}
- public XmlDsigExcC14NTransform (bool includeComments)
+ public XmlDsigExcC14NTransform (bool includeComments)
+ : this (includeComments, null)
{
- this.includeComments = includeComments;
- canonicalizer = new XmlCanonicalizer (true,
includeComments);
}
- [MonoTODO ("What does inclusiveNamespacesPrefixList mean?")]
public XmlDsigExcC14NTransform (string
inclusiveNamespacesPrefixList)
+ : this (false, inclusiveNamespacesPrefixList)
{
- this.inclusiveNamespacesPrefixList =
inclusiveNamespacesPrefixList;
}
- [MonoTODO ("What does inclusiveNamespacesPrefixList mean?")]
public XmlDsigExcC14NTransform (bool includeComments, string
inclusiveNamespacesPrefixList)
{
- this.inclusiveNamespacesPrefixList =
inclusiveNamespacesPrefixList;
- this.includeComments = includeComments;
+ Algorithm =
XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform;
+ canonicalizer = new XmlCanonicalizer (includeComments,
true);
}
-
- #endregion // Constructors
-
- #region Properties
public string InclusiveNamespacesPrefixList {
get { return inclusiveNamespacesPrefixList; }
@@ -82,64 +77,88 @@
}
public override Type[] InputTypes {
- get { return new Type [3] {typeof (System.IO.Stream),
typeof (System.Xml.XmlDocument), typeof (System.Xml.XmlNodeList)}; }
+ get {
+ if (input == null) {
+ lock (this) {
+ // this way the result is
cached if called multiple time
+ 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 { return new Type [1] {typeof (System.IO.Stream)}; }
+ get {
+ if (output == null) {
+ lock (this) {
+ // this way the result is
cached if called multiple time
+ output = new Type [1];
+ output[0] = typeof
(System.IO.Stream);
+ }
+ }
+ return output;
+ }
}
- #endregion // Properties
-
- #region Methods
-
- public override byte[] GetDigestedOutput (HashAlgorithm hash)
+ protected override XmlNodeList GetInnerXml ()
{
- return hash.ComputeHash ((Stream) GetOutput());
+ return null; // THIS IS DOCUMENTED AS SUCH
}
- protected override XmlNodeList GetInnerXml ()
+#if NET_2_0
+ [ComVisible (false)]
+ public override byte[] GetDigestedOutput (HashAlgorithm hash)
{
- return null;
+ return hash.ComputeHash ((Stream) GetOutput ());
}
+#endif
- public override object GetOutput ()
+ public override object GetOutput ()
{
- Stream s = null;
-
- if (inputObj is Stream) {
- XmlDocument doc = new XmlDocument ();
- doc.PreserveWhitespace = true; // REALLY
IMPORTANT
- doc.Load (inputObj as Stream);
- s = canonicalizer.Canonicalize (doc);
- }
- else if (inputObj is XmlDocument)
- s = canonicalizer.Canonicalize (inputObj as
XmlDocument);
- else if (inputObj is XmlNodeList)
- s = canonicalizer.Canonicalize (inputObj as
XmlNodeList);
-
- // note: there is no default are other types won't
throw an exception
-
return (object) s;
}
- public override object GetOutput (Type type)
+ public override object GetOutput (Type type)
{
- if (type == Type.GetType ("Stream"))
+ if (type == Type.GetType ("Stream"))
return GetOutput ();
throw new ArgumentException ("type");
}
- public override void LoadInnerXml (XmlNodeList nodeList)
+ public override void LoadInnerXml (XmlNodeList nodeList)
{
+ // documented as not changing the state of the transform
}
-
- public override void LoadInput (object obj)
+
+ public override void LoadInput (object obj)
{
- inputObj = obj;
+ canonicalizer.InclusiveNamespacesPrefixList =
InclusiveNamespacesPrefixList;
+ if (obj is Stream) {
+ s = (obj as Stream);
+ XmlDocument doc = new XmlDocument ();
+ doc.PreserveWhitespace = true; // REALLY
IMPORTANT
+#if NET_1_1
+ doc.XmlResolver = GetResolver ();
+#endif
+ doc.Load (new XmlSignatureStreamReader (
+ new StreamReader ((Stream) obj)));
+// doc.Load ((Stream) obj);
+ s = canonicalizer.Canonicalize (doc);
+ } else if (obj is XmlDocument)
+ s = canonicalizer.Canonicalize ((obj as
XmlDocument));
+ else if (obj is XmlNodeList)
+ s = canonicalizer.Canonicalize ((obj as
XmlNodeList));
+#if NET_2_0
+ else
+ throw new ArgumentException ("obj");
+#else
+ // note: there is no default are other types won't
throw an exception
+#endif
}
-
- #endregion // Methods
}
}
Modified: trunk/mcs/class/System.Security/System.Security_test.dll.sources
===================================================================
--- trunk/mcs/class/System.Security/System.Security_test.dll.sources
2007-01-17 17:29:52 UTC (rev 71219)
+++ trunk/mcs/class/System.Security/System.Security_test.dll.sources
2007-01-17 17:30:12 UTC (rev 71220)
@@ -41,6 +41,7 @@
System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransformTest.cs
System.Security.Cryptography.Xml/XmlDsigC14NTransformTest.cs
System.Security.Cryptography.Xml/XmlDsigC14NWithCommentsTransformTest.cs
+System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs
System.Security.Cryptography.Xml/XmlDsigXPathTransformTest.cs
System.Security.Cryptography.Xml/XmlDsigXsltTransformTest.cs
System.Security.Cryptography.X509Certificates/X509Certificate2UITest.cs
Modified:
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
===================================================================
---
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
2007-01-17 17:29:52 UTC (rev 71219)
+++
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/ChangeLog
2007-01-17 17:30:12 UTC (rev 71220)
@@ -1,3 +1,8 @@
+2007-01-17 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * XmlDsigExcC14NTransformTest.cs : new tests, mostly copied from
+ non-exc test.
+
2007-01-12 Atsushi Enomoto <[EMAIL PROTECTED]>
* SignedXmlTest.cs : added DataReferenceToNonDataObject().
Added:
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs
===================================================================
---
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs
2007-01-17 17:29:52 UTC (rev 71219)
+++
trunk/mcs/class/System.Security/Test/System.Security.Cryptography.Xml/XmlDsigExcC14NTransformTest.cs
2007-01-17 17:30:12 UTC (rev 71220)
@@ -0,0 +1,485 @@
+//
+// XmlDsigExcC14NTransformTest.cs - NUnit Test Cases for
XmlDsigExcC14NTransform
+//
+// Author:
+// original:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+// Aleksey Sanin ([EMAIL PROTECTED])
+// this file:
+// Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// (C) 2003 Aleksey Sanin ([EMAIL PROTECTED])
+// (C) 2004 Novell (http://www.novell.com)
+//
+
+//
+// WARNING!!
+// This file is simply replaced C14N->ExcC14N, and then replaced expected
+// output XML. So, they are *not* from c14n specification.
+//
+
+#if NET_2_0
+
+using System;
+using System.IO;
+using System.Security.Cryptography.Xml;
+using System.Text;
+using System.Xml;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Security.Cryptography.Xml {
+
+ // Note: GetInnerXml is protected in XmlDsigExcC14NTransform making it
+ // difficult to test properly. This class "open it up" :-)
+ public class UnprotectedXmlDsigExcC14NTransform :
XmlDsigExcC14NTransform {
+
+ public XmlNodeList UnprotectedGetInnerXml () {
+ return base.GetInnerXml ();
+ }
+ }
+
+ [TestFixture]
+ public class XmlDsigExcC14NTransformTest : Assertion {
+
+ protected UnprotectedXmlDsigExcC14NTransform transform;
+
+ [SetUp]
+ protected void SetUp ()
+ {
+ transform = new UnprotectedXmlDsigExcC14NTransform ();
+ }
+
+ [TearDown]
+ protected void CleanUp ()
+ {
+ try {
+ if (File.Exists ("doc.dtd"))
+ File.Delete ("doc.dtd");
+ if (File.Exists ("world.txt"))
+ File.Delete ("world.txt");
+ }
+ catch {}
+ }
+
+ [Test]
+ public void Properties ()
+ {
+ AssertEquals ("Algorithm",
"http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm);
+
+ Type[] input = transform.InputTypes;
+ Assert ("Input #", (input.Length == 3));
+ // check presence of every supported input types
+ bool istream = false;
+ bool ixmldoc = false;
+ bool ixmlnl = false;
+ foreach (Type t in input) {
+ if (t.ToString () == "System.IO.Stream")
+ istream = true;
+ if (t.ToString () == "System.Xml.XmlDocument")
+ ixmldoc = true;
+ if (t.ToString () == "System.Xml.XmlNodeList")
+ ixmlnl = true;
+ }
+ Assert ("Input Stream", istream);
+ Assert ("Input XmlDocument", ixmldoc);
+ Assert ("Input XmlNodeList", ixmlnl);
+
+ Type[] output = transform.OutputTypes;
+ Assert ("Output #", (output.Length == 1));
+ // check presence of every supported output types
+ bool ostream = false;
+ foreach (Type t in output) {
+ if (t.ToString () == "System.IO.Stream")
+ ostream = true;
+ }
+ Assert ("Output Stream", ostream);
+ }
+
+ [Test]
+ public void GetInnerXml ()
+ {
+ XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
+ AssertNull ("Default InnerXml", xnl);
+ }
+
+ private string Stream2String (Stream s)
+ {
+ StringBuilder sb = new StringBuilder ();
+ int b = s.ReadByte ();
+ while (b != -1) {
+ sb.Append (Convert.ToChar (b));
+ b = s.ReadByte ();
+ }
+ return sb.ToString ();
+ }
+
+ static string xml = "<Test attrib='at '
xmlns=\"http://www.go-mono.com/\" > \r\n 
 <Toto/> text & </Test >";
+ // BAD for XmlDocument input (framework 1.0 result)
+ static string c14xml1 = "<Test
xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \r\n \r <Toto></Toto> text
& </Test>";
+ // GOOD for Stream input
+ static string c14xml2 = "<Test
xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \n 
 <Toto></Toto> text
& </Test>";
+ // GOOD for XmlDocument input. The difference is because once
+ // xml string is loaded to XmlDocument, there is no difference
+ // between \r and 
, so every \r must be handled as 
.
+ static string c14xml3 = "<Test
xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> 
\n 
 <Toto></Toto>
text & </Test>";
+
+ private XmlDocument GetDoc ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.PreserveWhitespace = true;
+ doc.LoadXml (xml);
+ return doc;
+ }
+
+ [Test]
+ public void LoadInputAsXmlDocument ()
+ {
+ XmlDocument doc = GetDoc ();
+ transform.LoadInput (doc);
+ Stream s = (Stream) transform.GetOutput ();
+ string output = Stream2String (s);
+#if NET_1_1
+ AssertEquals("XmlDocument", c14xml3, output);
+#else
+ // .NET 1.0 keeps the \r\n (0x0D, 0x0A) - bug
+ AssertEquals("XmlDocument", c14xml1, output);
+#endif
+ }
+
+ [Test]
+#if NET_2_0
+ [Category ("NotDotNet")]
+ // see LoadInputAsXmlNodeList2 description
+#endif
+ public void LoadInputAsXmlNodeList ()
+ {
+ XmlDocument doc = GetDoc ();
+ // Argument list just contains element Test.
+ transform.LoadInput (doc.ChildNodes);
+ Stream s = (Stream) transform.GetOutput ();
+ string output = Stream2String (s);
+ AssertEquals ("XmlChildNodes", "<Test></Test>", output);
+ }
+
+ [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
+ public void LoadInputAsXmlNodeList2 ()
+ {
+ XmlDocument doc = GetDoc ();
+ transform.LoadInput (doc.SelectNodes ("//*"));
+ Stream s = (Stream) transform.GetOutput ();
+ string output = Stream2String (s);
+ string expected = @"<Test><Toto></Toto></Test>";
+ AssertEquals ("XmlChildNodes", expected, output);
+ }
+
+ [Test]
+ public void LoadInputAsStream ()
+ {
+ MemoryStream ms = new MemoryStream ();
+ byte[] x = Encoding.ASCII.GetBytes (xml);
+ ms.Write (x, 0, x.Length);
+ ms.Position = 0;
+ transform.LoadInput (ms);
+ Stream s = (Stream) transform.GetOutput ();
+ string output = Stream2String (s);
+ AssertEquals ("MemoryStream", c14xml2, output);
+ }
+
+ [Test]
+ [Ignore ("LAMESPEC: input MUST be one of InputType - but no
exception is thrown (not documented)")]
+ public void LoadInputWithUnsupportedType ()
+ {
+ byte[] bad = { 0xBA, 0xD };
+ transform.LoadInput (bad);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void UnsupportedOutput ()
+ {
+ XmlDocument doc = new XmlDocument();
+ object o = transform.GetOutput (doc.GetType ());
+ }
+
+ [Test]
+ public void ExcC14NSpecExample1 ()
+ {
+ using (StreamWriter sw = new StreamWriter ("doc.dtd",
false, Encoding.ASCII)) {
+ sw.Write ("<!-- presence, not content, required
-->");
+ sw.Close ();
+ }
+ string res = ExecuteXmlDSigExcC14NTransform
(ExcC14NSpecExample1Input);
+ AssertEquals ("Example 1 from c14n spec - PIs,
Comments, and Outside of Document Element (without comments)",
+ ExcC14NSpecExample1Output, res);
+ }
+
+ [Test]
+ public void ExcC14NSpecExample2 ()
+ {
+ string res = ExecuteXmlDSigExcC14NTransform
(ExcC14NSpecExample2Input);
+ AssertEquals ("Example 2 from c14n spec - Whitespace in
Document Content (without comments)",
+ ExcC14NSpecExample2Output, res);
+ }
+
+ [Test]
+ public void ExcC14NSpecExample3 ()
+ {
+ string res = ExecuteXmlDSigExcC14NTransform
(ExcC14NSpecExample3Input);
+ AssertEquals ("Example 3 from c14n spec - Start and End
Tags (without comments)",
+ ExcC14NSpecExample3Output, res);
+ }
+
+ [Test]
+// [Ignore ("This test should be fine, but it does not pass under
MS.NET")]
+ public void ExcC14NSpecExample4 ()
+ {
+ string res = ExecuteXmlDSigExcC14NTransform
(ExcC14NSpecExample4Input);
+ AssertEquals ("Example 4 from c14n spec - Character
Modifications and Character References (without comments)",
+ ExcC14NSpecExample4Output, res);
+ }
+
+ [Test]
+ public void ExcC14NSpecExample5 ()
+ {
+ using (StreamWriter sw = new StreamWriter ("world.txt",
false, Encoding.ASCII)) {
+ sw.Write ("world");
+ sw.Close ();
+ }
+ string res = ExecuteXmlDSigExcC14NTransform
(ExcC14NSpecExample5Input);
+ AssertEquals ("Example 5 from c14n spec - Entity
References (without comments)",
+ ExcC14NSpecExample5Output, res);
+ }
+
+ [Test]
+ public void ExcC14NSpecExample6 ()
+ {
+ string res = ExecuteXmlDSigExcC14NTransform
(ExcC14NSpecExample6Input);
+ AssertEquals ("Example 6 from c14n spec - UTF-8
Encoding (without comments)",
+ ExcC14NSpecExample6Output, res);
+ }
+
+ private string ExecuteXmlDSigExcC14NTransform (string InputXml)
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.PreserveWhitespace = true;
+ doc.LoadXml (InputXml);
+
+ // Testing default attribute support with
+ // vreader.ValidationType = ValidationType.None.
+ //
+ UTF8Encoding utf8 = new UTF8Encoding ();
+ byte[] data = utf8.GetBytes (InputXml.ToString ());
+ Stream stream = new MemoryStream (data);
+ XmlTextReader reader = new XmlTextReader (stream);
+ XmlValidatingReader vreader = new XmlValidatingReader
(reader);
+ vreader.ValidationType = ValidationType.None;
+ vreader.EntityHandling =
EntityHandling.ExpandCharEntities;
+ doc.Load (vreader);
+
+ transform.LoadInput (doc);
+ return Stream2String ((Stream)transform.GetOutput ());
+ }
+
+ //
+ // Example 1 from ExcC14N spec - PIs, Comments, and Outside of
Document Element:
+ // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
+ //
+ // Aleksey:
+ // removed reference to an empty external DTD
+ //
+ static string ExcC14NSpecExample1Input =
+ "<?xml version=\"1.0\"?>\n" +
+ "\n" +
+ "<?xml-stylesheet href=\"doc.xsl\"\n" +
+ " type=\"text/xsl\" ?>\n" +
+ "\n" +
+ // "<!DOCTYPE doc SYSTEM \"doc.dtd\">\n" +
+ "\n" +
+ "<doc>Hello, world!<!-- Comment 1 --></doc>\n" +
+ "\n" +
+ "<?pi-without-data ?>\n\n" +
+ "<!-- Comment 2 -->\n\n" +
+ "<!-- Comment 3 -->\n";
+ static string ExcC14NSpecExample1Output =
+ "<?xml-stylesheet href=\"doc.xsl\"\n" +
+ " type=\"text/xsl\" ?>\n" +
+ "<doc>Hello, world!</doc>\n" +
+ "<?pi-without-data?>";
+
+ //
+ // Example 2 from ExcC14N spec - Whitespace in Document
Content:
+ // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
+ //
+ static string ExcC14NSpecExample2Input =
+ "<doc>\n" +
+ " <clean> </clean>\n" +
+ " <dirty> A B </dirty>\n" +
+ " <mixed>\n" +
+ " A\n" +
+ " <clean> </clean>\n" +
+ " B\n" +
+ " <dirty> A B </dirty>\n" +
+ " C\n" +
+ " </mixed>\n" +
+ "</doc>\n";
+ static string ExcC14NSpecExample2Output =
+ "<doc>\n" +
+ " <clean> </clean>\n" +
+ " <dirty> A B </dirty>\n" +
+ " <mixed>\n" +
+ " A\n" +
+ " <clean> </clean>\n" +
+ " B\n" +
+ " <dirty> A B </dirty>\n" +
+ " C\n" +
+ " </mixed>\n" +
+ "</doc>";
+
+ //
+ // Example 3 from ExcC14N spec - Start and End Tags:
+ // http://www.w3.org/TR/xml-c14n#Example-SETags
+ //
+ static string ExcC14NSpecExample3Input =
+ "<!DOCTYPE doc [<!ATTLIST e9 attr CDATA
\"default\">]>\n" +
+ "<doc>\n" +
+ " <e1 />\n" +
+ " <e2 ></e2>\n" +
+ " <e3 name = \"elem3\" id=\"elem3\" />\n" +
+ " <e4 name=\"elem4\" id=\"elem4\" ></e4>\n" +
+ " <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\"
attr=\"I\'m\"\n" +
+ " xmlns:b=\"http://www.ietf.org\" \n" +
+ " xmlns:a=\"http://www.w3.org\"\n" +
+ " xmlns=\"http://www.uvic.ca\"/>\n" +
+ " <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
+ " <e7 xmlns=\"http://www.ietf.org\">\n" +
+ " <e8 xmlns=\"\"
xmlns:a=\"http://www.w3.org\">\n" +
+ " <e9 xmlns=\"\"
xmlns:a=\"http://www.ietf.org\"/>\n" +
+ " </e8>\n" +
+ " </e7>\n" +
+ " </e6>\n" +
+ "</doc>\n";
+ static string ExcC14NSpecExample3Output =
+ "<doc>\n" +
+ " <e1></e1>\n" +
+ " <e2></e2>\n" +
+ " <e3 id=\"elem3\" name=\"elem3\"></e3>\n" +
+ " <e4 id=\"elem4\" name=\"elem4\"></e4>\n" +
+ " <e5 xmlns=\"http://www.uvic.ca\"
xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I\'m\"
attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" +
+ " <e6>\n" +
+ " <e7 xmlns=\"http://www.ietf.org\">\n" +
+ " <e8 xmlns=\"\">\n" +
+ " <e9 attr=\"default\"></e9>\n" +
+// " <e9
xmlns:a=\"http://www.ietf.org\"></e9>\n" +
+ " </e8>\n" +
+ " </e7>\n" +
+ " </e6>\n" +
+ "</doc>";
+
+
+ //
+ // Example 4 from ExcC14N spec - Character Modifications and
Character References:
+ // http://www.w3.org/TR/xml-c14n#Example-Chars
+ //
+ // Aleksey:
+ // This test does not include "normId" element
+ // because it has an invalid ID attribute "id" which
+ // should be normalized by XML parser. Currently Mono
+ // does not support this (see comment after this example
+ // in the spec).
+ static string ExcC14NSpecExample4Input =
+ "<!DOCTYPE doc [<!ATTLIST normId id ID #IMPLIED>]>\n" +
+ "<doc>\n" +
+ " <text>First line
 Second line</text>\n" +
+ " <value>2</value>\n" +
+ " <compute><![CDATA[value>\"0\" && value<\"10\"
?\"valid\":\"error\"]]></compute>\n" +
+ " <compute expr=\'value>\"0\" &&
value<\"10\" ?\"valid\":\"error\"\'>valid</compute>\n" +
+ " <norm attr=\' '   
	
' \'/>\n" +
+ // " <normId id=\' '   
	
' \'/>\n" +
+ "</doc>\n";
+ static string ExcC14NSpecExample4Output =
+ "<doc>\n" +
+ " <text>First line
\n" +
+ "Second line</text>\n" +
+ " <value>2</value>\n" +
+ " <compute>value>\"0\" && value<\"10\"
?\"valid\":\"error\"</compute>\n" +
+ " <compute expr=\"value>"0" &&
value<"10"
?"valid":"error"\">valid</compute>\n" +
+ " <norm attr=\" \' 
	 \'
\"></norm>\n" +
+ // " <normId id=\"\' 
	
\'\"></normId>\n" +
+ "</doc>";
+
+ //
+ // Example 5 from ExcC14N spec - Entity References:
+ // http://www.w3.org/TR/xml-c14n#Example-Entities
+ //
+ static string ExcC14NSpecExample5Input =
+ "<!DOCTYPE doc [\n" +
+ "<!ATTLIST doc attrExtEnt ENTITY #IMPLIED>\n" +
+ "<!ENTITY ent1 \"Hello\">\n" +
+ "<!ENTITY ent2 SYSTEM \"world.txt\">\n" +
+ "<!ENTITY entExt SYSTEM \"earth.gif\" NDATA gif>\n" +
+ "<!NOTATION gif SYSTEM \"viewgif.exe\">\n" +
+ "]>\n" +
+ "<doc attrExtEnt=\"entExt\">\n" +
+ " &ent1;, &ent2;!\n" +
+ "</doc>\n" +
+ "\n" +
+ "<!-- Let world.txt contain \"world\" (excluding the
quotes) -->\n";
+ static string ExcC14NSpecExample5Output =
+ "<doc attrExtEnt=\"entExt\">\n" +
+ " Hello, world!\n" +
+ "</doc>";
+
+ //
+ // Example 6 from ExcC14N spec - UTF-8 Encoding:
+ // http://www.w3.org/TR/xml-c14n#Example-UTF8
+ //
+ static string ExcC14NSpecExample6Input =
+ "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
+ "<doc>©</doc>\n";
+ static string ExcC14NSpecExample6Output =
+ "<doc>\xC2\xA9</doc>";
+
+
+ //
+ // Example 7 from ExcC14N spec - Document Subsets:
+ // http://www.w3.org/TR/xml-c14n#Example-DocSubsets
+ //
+ // Aleksey:
+ // Well, XPath support in Mono is far from complete....
+ // I was not able to simplify the xpath expression from this
test
+ // so it runs on Mono and still makes sense for testing this
feature.
+ // Thus this test is not included in the suite now.
+ static string ExcC14NSpecExample7Input =
+ "<!DOCTYPE doc [\n" +
+ "<!ATTLIST e2 xml:space (default|preserve)
\'preserve\'>\n" +
+ "<!ATTLIST e3 id ID #IMPLIED>\n" +
+ "]>\n" +
+ "<doc xmlns=\"http://www.ietf.org\"
xmlns:w3c=\"http://www.w3.org\">\n" +
+ " <e1>\n" +
+ " <e2 xmlns=\"\">\n" +
+ " <e3 id=\"E3\"/>\n" +
+ " </e2>\n" +
+ " </e1>\n" +
+ "</doc>\n";
+
+ static string ExcC14NSpecExample7Xpath =
+ "(//.|//@*|//namespace::*)\n" +
+ "[\n" +
+ "self::ietf:e1\n" +
+ " or\n" +
+ "(parent::ietf:e1 and not(self::text() or self::e2))\n"
+
+ " or\n" +
+ "count(id(\"E3\")|ancestor-or-self::node()) =
count(ancestor-or-self::node())\n" +
+ "]";
+ static string ExcC14NSpecExample7Output =
+ "<e1 xmlns=\"http://www.ietf.org\"
xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\"
xml:space=\"preserve\"></e3></e1>";
+ }
+}
+
+#endif
Modified: trunk/mcs/class/System.Security/Test/standalone_tests/ChangeLog
===================================================================
--- trunk/mcs/class/System.Security/Test/standalone_tests/ChangeLog
2007-01-17 17:29:52 UTC (rev 71219)
+++ trunk/mcs/class/System.Security/Test/standalone_tests/ChangeLog
2007-01-17 17:30:12 UTC (rev 71220)
@@ -1,3 +1,9 @@
+2007-01-17 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * xmldsig.cs : exc-c14n tests could be run under 2.0 profile (and
+ they are not working correctly yet).
+ * Makefile : Added net_2_0 profile support.
+
2007-01-12 Atsushi Enomoto <[EMAIL PROTECTED]>
* xmldsig.cs : signature-big.xml also depends on the input document.
Modified: trunk/mcs/class/System.Security/Test/standalone_tests/Makefile
===================================================================
--- trunk/mcs/class/System.Security/Test/standalone_tests/Makefile
2007-01-17 17:29:52 UTC (rev 71219)
+++ trunk/mcs/class/System.Security/Test/standalone_tests/Makefile
2007-01-17 17:30:12 UTC (rev 71220)
@@ -1,9 +1,14 @@
-RUNTIME = mono --debug
-CSCOMPILE = mcs --debug
PROFILE = default
+RUNTIME = MONO_PATH=../../../lib/$(PROFILE) mono --debug
#XMLDSIG_EXE_OPTIONS =
XMLDSIG_EXE_OPTIONS = --decent-reader
+ifeq ($(PROFILE), net_2_0)
+CSCOMPILE = gmcs --debug -d:NET_2_0
+else
+CSCOMPILE = mcs --debug
+endif
+
run-test: c14n.exe xmldsig.exe merlin-xmldsig-twenty-three
$(RUNTIME) $(RUNTIME_FLAGS) c14n.exe
merlin-xmldsig-twenty-three/signature-enveloped-dsa.xml SignedInfo | cmp
merlin-xmldsig-twenty-three/signature-enveloped-dsa-c14n-1.txt
$(RUNTIME) $(RUNTIME_FLAGS) c14n.exe
merlin-xmldsig-twenty-three/signature-enveloping-b64-dsa.xml SignedInfo | cmp
merlin-xmldsig-twenty-three/signature-enveloping-b64-dsa-c14n-0.txt
@@ -29,7 +34,7 @@
rm Mono.Security.dll
clean:
- rm *.exe
+ rm -f *.exe *.exe.mdb
c14n.exe : c14n.cs
$(CSCOMPILE) c14n.cs -r:System.Security.dll
Modified: trunk/mcs/class/System.Security/Test/standalone_tests/xmldsig.cs
===================================================================
--- trunk/mcs/class/System.Security/Test/standalone_tests/xmldsig.cs
2007-01-17 17:29:52 UTC (rev 71219)
+++ trunk/mcs/class/System.Security/Test/standalone_tests/xmldsig.cs
2007-01-17 17:30:12 UTC (rev 71220)
@@ -258,11 +258,13 @@
// some documents references other documents in the directory
Directory.SetCurrentDirectory ("phaos-xmldsig-three");
foreach (FileInfo fi in new DirectoryInfo (".").GetFiles
("signature-*.xml")) {
+#if !NET_2_0
if ((fi.Name.IndexOf ("exclusive") >= 0) && (!exc14n)) {
Console.WriteLine ("NOT RUN: " + fi.Name + " :
System.Security.dll cannot validate exclusive-c14n.");
skip++;
continue;
}
+#endif
if ((fi.Name.IndexOf ("md5") >= 0) && (!hmacmd5)) {
Console.WriteLine ("NOT RUN: " + fi.Name + " :
System.Security.dll doesn't support HMAC-MD5.");
skip++;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches