2003-03-02 Sebastien Pouliot <spouliot@videotron.ca>
authorSebastien Pouliot <sebastien@ximian.com>
Sun, 2 Mar 2003 16:09:19 +0000 (16:09 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Sun, 2 Mar 2003 16:09:19 +0000 (16:09 -0000)
* DSAKeyValue.cs: New XML generation is commented. Old string technique
did a better job to match MS implementation.
* DataObject.cs: Replaced XML generation from StringBuilder to XmlElement.
* KeyInfo.cs: Replaced XML generation from StringBuilder to XmlElement.
* KeyInfoName.cs: Replaced XML generation from StringBuilder to XmlElement.
* KeyInfoNode.cs: Replaced XML generation from StringBuilder to XmlElement.
* KeyInfoRetrievalMethod.cs: Replaced XML generation from StringBuilder to XmlElement.
* KeyInfoX509Data.cs: Replaced XML generation from StringBuilder to XmlElement.
* RSAKeyValue.cs: New XML generation is commented. Old string technique
did a better job to match MS implementation.
* Reference.cs: Replaced XML generation from StringBuilder to XmlElement.
* Signature.cs: Replaced XML generation from StringBuilder to XmlElement.
* SignedInfo.cs: Replaced XML generation from StringBuilder to XmlElement.
* SignedXml.cs: Replaced XML generation from StringBuilder to XmlElement.
* Transform.cs: Replaced XML generation from StringBuilder to XmlElement.
* XmlDsigEnvelopedSignatureTransform.cs: Added missing Algorithm URL.
* XmlDsigXPathTransform.cs: Added missing Algorithm URL.
* XmlSignature.cs: New. Private contants (construct similar to WSE).

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

17 files changed:
mcs/class/System.Security/System.Security.Cryptography.Xml/ChangeLog
mcs/class/System.Security/System.Security.Cryptography.Xml/DSAKeyValue.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/DataObject.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/KeyInfo.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/KeyInfoName.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/KeyInfoNode.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/KeyInfoRetrievalMethod.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/KeyInfoX509Data.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/RSAKeyValue.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/Reference.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/Signature.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/SignedInfo.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/SignedXml.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/Transform.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigEnvelopedSignatureTransform.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/XmlDsigXPathTransform.cs
mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs [new file with mode: 0644]

index e17bcc2a5609c596c2b931e4929408f2d33693bd..d5cf42451c688d7e8c89c1184a8f0d711904101d 100644 (file)
@@ -1,3 +1,24 @@
+2003-03-02  Sebastien Pouliot  <spouliot@videotron.ca>
+
+       * DSAKeyValue.cs: New XML generation is commented. Old string technique
+       did a better job to match MS implementation.
+       * DataObject.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * KeyInfo.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * KeyInfoName.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * KeyInfoNode.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * KeyInfoRetrievalMethod.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * KeyInfoX509Data.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * RSAKeyValue.cs: New XML generation is commented. Old string technique
+       did a better job to match MS implementation.
+       * Reference.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * Signature.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * SignedInfo.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * SignedXml.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * Transform.cs: Replaced XML generation from StringBuilder to XmlElement.
+       * XmlDsigEnvelopedSignatureTransform.cs: Added missing Algorithm URL.
+       * XmlDsigXPathTransform.cs: Added missing Algorithm URL.
+       * XmlSignature.cs: New. Private contants (construct similar to WSE).
+
 2003-02-19  Sebastien Pouliot  <spouliot@videotron.ca>
 
        * All: Corrected class indentation, minor fixes, added many MonoTODO (so class status
index cac6e923be5e08d9c53f2f90edbf27d1f1395a70..e7137faad9f83efa09a6bd6ea12aecda14eae0f7 100644 (file)
@@ -15,7 +15,6 @@ namespace System.Security.Cryptography.Xml {
 
        public class DSAKeyValue : KeyInfoClause {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
                private DSA dsa;
 
                public DSAKeyValue () 
@@ -36,16 +35,14 @@ namespace System.Security.Cryptography.Xml {
 
                public override XmlElement GetXml () 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<KeyValue xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\">");
-                       sb.Append (dsa.ToXmlString (false));
-                       sb.Append ("</KeyValue>");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml(sb.ToString ());
-                       return doc.DocumentElement;
+                       XmlDocument document = new XmlDocument ();
+                       document.LoadXml ("<KeyValue xmlns=\"" + XmlSignature.NamespaceURI + "\">" + dsa.ToXmlString (false) + "</KeyValue>");
+                       return document.DocumentElement;
+
+                       // FIX: this way we get a xmlns="" in DSAKeyValue
+/*                     XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
+                       xel.InnerXml = dsa.ToXmlString (false);
+                       return xel;*/
                }
 
                public override void LoadXml (XmlElement value) 
@@ -53,10 +50,11 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ();
 
-                       if ((value.LocalName == "KeyValue") && (value.NamespaceURI == xmldsig))
-                               dsa.FromXmlString (value.InnerXml);
-                       else
+                       // FIXME: again hack to match MS implementation (required for previous hack)
+                       if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || ((value.NamespaceURI != XmlSignature.NamespaceURI) && (value.GetAttribute("xmlns") != XmlSignature.NamespaceURI)))
                                throw new CryptographicException ("value");
+
+                       dsa.FromXmlString (value.InnerXml);
                }
        }
 }
\ No newline at end of file
index 9266d85fb09e76ece86319cddb5ba1c77d8096f9..bb78685e87561ec088761a6c4b9ff368ac1dfac5 100644 (file)
@@ -8,7 +8,6 @@
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
 //
 
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
@@ -21,11 +20,9 @@ namespace System.Security.Cryptography.Xml {
                private string id;
                private string mimeType;
                private string encoding;
-               private XmlDocument doc;
+               private XmlDocument document;
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
-               public DataObject () 
+               public DataObject ()
                {
                        Build (null, null, null, null);
                }
@@ -38,43 +35,34 @@ namespace System.Security.Cryptography.Xml {
                        Build (id, mimeType, encoding, data);
                }
 
+               // this one accept a null "data" parameter
                private void Build (string id, string mimeType, string encoding, XmlElement data) 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<Object ");
+                       document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Object, XmlSignature.NamespaceURI);
                        if (id != null) {
                                this.id = id;
-                               sb.Append ("Id=\"");
-                               sb.Append (id);
-                               sb.Append ("\" ");
+                               xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
                        }
                        if (mimeType != null) {
                                this.mimeType = mimeType;
-                               sb.Append ("MimeType=\"");
-                               sb.Append (mimeType);
-                               sb.Append ("\" ");
+                               xel.SetAttribute (XmlSignature.AttributeNames.MimeType, mimeType);
                        }
                        if (encoding != null) {
                                this.encoding = encoding;
-                               sb.Append ("Encoding=\"");
-                               sb.Append (encoding);
-                               sb.Append ("\" ");
+                               xel.SetAttribute (XmlSignature.AttributeNames.Encoding, encoding);
                        }
-                       sb.Append ("xmlns=\"http://www.w3.org/2000/09/xmldsig#\" />");
-                       
-                       doc = new XmlDocument ();
-                       doc.LoadXml (sb.ToString ());
                        if (data != null) {
-                               XmlNodeList xnl = doc.GetElementsByTagName ("Object");
-                               XmlNode newNode = doc.ImportNode (data, true);
-                               xnl[0].AppendChild (newNode);
+                               XmlNode newNode = document.ImportNode (data, true);
+                               xel.AppendChild (newNode);
                        }
+                       document.AppendChild (xel);
                }
 
                // why is data a XmlNodeList instead of a XmlElement ?
                public XmlNodeList Data {
                        get { 
-                               XmlNodeList xnl = doc.GetElementsByTagName ("Object");
+                               XmlNodeList xnl = document.GetElementsByTagName (XmlSignature.ElementNames.Object);
                                return xnl[0].ChildNodes;
                        }
                        set {
@@ -82,11 +70,11 @@ namespace System.Security.Cryptography.Xml {
                                        throw new ArgumentNullException ("value");
 
                                Build (id, mimeType, encoding, null);
-                               XmlNodeList xnl = doc.GetElementsByTagName ("Object");
+                               XmlNodeList xnl = document.GetElementsByTagName (XmlSignature.ElementNames.Object);
                                if ((xnl != null) && (xnl.Count > 0)) {
                                        foreach (XmlNode xn in value) {
-                                               XmlNode newNode = doc.ImportNode (xn, true);
-                                               xnl[0].AppendChild (newNode);
+                                               XmlNode newNode = document.ImportNode (xn, true);
+                                               xnl [0].AppendChild (newNode);
                                        }
                                }
                        }
@@ -112,30 +100,30 @@ namespace System.Security.Cryptography.Xml {
 
                public XmlElement GetXml () 
                {
-                       if ((doc.DocumentElement.LocalName == "Object") && (doc.DocumentElement.NamespaceURI == xmldsig)) {
+                       if ((document.DocumentElement.LocalName == XmlSignature.ElementNames.Object) && (document.DocumentElement.NamespaceURI == XmlSignature.NamespaceURI)) {
                                // recreate all attributes in order
                                XmlAttribute xa = null;
-                               doc.DocumentElement.Attributes.RemoveAll ();
+                               document.DocumentElement.Attributes.RemoveAll ();
                                if (id != null) {
-                                       xa = doc.CreateAttribute ("Id");
+                                       xa = document.CreateAttribute (XmlSignature.AttributeNames.Id);
                                        xa.Value = id;
-                                       doc.DocumentElement.Attributes.Append (xa);
+                                       document.DocumentElement.Attributes.Append (xa);
                                }
                                if (mimeType != null) {
-                                       xa = doc.CreateAttribute ("MimeType");
+                                       xa = document.CreateAttribute (XmlSignature.AttributeNames.MimeType);
                                        xa.Value = mimeType;
-                                       doc.DocumentElement.Attributes.Append (xa);
+                                       document.DocumentElement.Attributes.Append (xa);
                                }
                                if (encoding != null) {
-                                       xa = doc.CreateAttribute ("Encoding");
+                                       xa = document.CreateAttribute (XmlSignature.AttributeNames.Encoding);
                                        xa.Value = encoding;
-                                       doc.DocumentElement.Attributes.Append (xa);
+                                       document.DocumentElement.Attributes.Append (xa);
                                }
-                               xa = doc.CreateAttribute ("xmlns");
-                               xa.Value = xmldsig;
-                               doc.DocumentElement.Attributes.Append (xa);
+                               xa = document.CreateAttribute ("xmlns");
+                               xa.Value = XmlSignature.NamespaceURI;
+                               document.DocumentElement.Attributes.Append (xa);
                        }
-                       return doc.DocumentElement;
+                       return document.DocumentElement;
                }
 
                public void LoadXml (XmlElement value) 
@@ -143,17 +131,18 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ("value");
 
-                       if ((value.LocalName == "Object") && (value.NamespaceURI == xmldsig)) {
-                               doc.LoadXml (value.OuterXml);
-                               XmlAttribute xa = value.Attributes ["Id"];
+                       if ((value.LocalName != XmlSignature.ElementNames.Object) || (value.NamespaceURI != XmlSignature.NamespaceURI)) {
+                               document.LoadXml (value.OuterXml);
+                       }
+                       else {
+                               document.LoadXml (value.OuterXml);
+                               XmlAttribute xa = value.Attributes [XmlSignature.AttributeNames.Id];
                                id = ((xa != null) ? xa.InnerText : null);
-                               xa = value.Attributes ["MimeType"];
+                               xa = value.Attributes [XmlSignature.AttributeNames.MimeType];
                                mimeType = ((xa != null) ? xa.InnerText : null);
-                               xa = value.Attributes ["Encoding"];
+                               xa = value.Attributes [XmlSignature.AttributeNames.Encoding];
                                encoding = ((xa != null) ? xa.InnerText : null);
                        }
-                       else
-                               doc.LoadXml (value.OuterXml);
                }
        }
 }
\ No newline at end of file
index 1262c08c1290ace104c425992d4eb4d9260feae3..b8f7be84de9ab133782e3015dc2324035902bbd1 100644 (file)
@@ -8,15 +8,12 @@
 //
 
 using System.Collections;
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
 
        public class KeyInfo : IEnumerable {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private ArrayList Info;
                private string id;
 
@@ -62,21 +59,16 @@ namespace System.Security.Cryptography.Xml {
 
                public XmlElement GetXml () 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<KeyInfo xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\" />");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml (sb.ToString ());
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyInfo, XmlSignature.NamespaceURI);
                        // we add References afterward so we don't end up with extraneous
                        // xmlns="..." in each reference elements.
                        foreach (KeyInfoClause kic in Info) {
                                XmlNode xn = kic.GetXml ();
-                               XmlNode newNode = doc.ImportNode (xn, true);
-                               doc.DocumentElement.AppendChild (newNode);
+                               XmlNode newNode = document.ImportNode (xn, true);
+                               xel.AppendChild (newNode);
                        }
-                       return doc.DocumentElement;
+                       return xel;
                }
 
                public void LoadXml (XmlElement value) 
@@ -84,41 +76,41 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ("value");
 
-                       if ((value.LocalName == "KeyInfo") && (value.NamespaceURI == xmldsig)) {
+                       if ((value.LocalName == XmlSignature.ElementNames.KeyInfo) && (value.NamespaceURI == XmlSignature.NamespaceURI)) {
                                foreach (XmlNode n in value.ChildNodes) {
                                        KeyInfoClause kic = null;
                                        if (n is XmlWhitespace)
                                                continue;
 
                                        switch (n.LocalName) {
-                                       case "KeyValue":
+                                       case XmlSignature.ElementNames.KeyValue:
                                                XmlNodeList xnl = n.ChildNodes;
                                                if (xnl.Count > 0) {
                                                        // we must now treat the whitespace !
                                                        foreach (XmlNode m in xnl) {
                                                                switch (m.LocalName) {
-                                                               case "DSAKeyValue":
+                                                               case XmlSignature.ElementNames.DSAKeyValue:
                                                                        kic = (KeyInfoClause) new DSAKeyValue ();
                                                                        break;
-                                                               case "RSAKeyValue":
+                                                               case XmlSignature.ElementNames.RSAKeyValue:
                                                                        kic = (KeyInfoClause) new RSAKeyValue ();
                                                                        break;
                                                                }
                                                        }
                                                }
                                                break;
-                                       case "KeyName":
+                                       case XmlSignature.ElementNames.KeyName:
                                                kic = (KeyInfoClause) new KeyInfoName ();
                                                break;
-                                       case "RetrievalMethod":
+                                       case XmlSignature.ElementNames.RetrievalMethod:
                                                kic = (KeyInfoClause) new KeyInfoRetrievalMethod ();
                                                break;
-                                       case "X509Data":
+                                       case XmlSignature.ElementNames.X509Data:
                                                kic = (KeyInfoClause) new KeyInfoX509Data ();
                                                break;
-                                       case "RSAKeyValue":
+/*                                     case XmlSignature.ElementNames.RSAKeyValue:
                                                kic = (KeyInfoClause) new RSAKeyValue ();
-                                               break;
+                                               break;*/
                                        default:
                                                kic = (KeyInfoClause) new KeyInfoNode ();
                                                break;
index 80bc7f53a6ea6a7e857f6bdbb7244a1ddd8bb89b..727a50f0b43dd3cfc046afe1d8f610c4f5543179 100644 (file)
@@ -7,47 +7,37 @@
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
 //
 
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
 
        public class KeyInfoName : KeyInfoClause {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
-               private string Name;
+               private string name;
 
                public KeyInfoName() {}
 
                public string Value {
-                       get { return Name; }
-                       set { Name = value; }
+                       get { return name; }
+                       set { name = value; }
                }
 
                public override XmlElement GetXml () 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<KeyName xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\">");
-                       sb.Append (Name);
-                       sb.Append ("</KeyName>");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml(sb.ToString ());
-                       return doc.DocumentElement;
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyName, XmlSignature.NamespaceURI);
+                       xel.InnerText = name;
+                       return xel;
                }
 
                public override void LoadXml (XmlElement value) 
                {
                        if (value == null)
                                throw new ArgumentNullException ();
-
-                       if ((value.LocalName == "KeyName") && (value.NamespaceURI == xmldsig))
-                               Name = value.InnerXml;
+                       if ((value.LocalName != XmlSignature.ElementNames.KeyName) || (value.NamespaceURI != XmlSignature.NamespaceURI))
+                               name = "";
                        else
-                               Name = null;
+                               name = value.InnerText;
                }
        }
 }
\ No newline at end of file
index 65257ea68195f4a8add1394ff7fe216259ebddff..833925cb82fef8da25b430e24669af80501207d4 100644 (file)
@@ -7,7 +7,6 @@
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
 //
 
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
index 48ede35744a6c97debc4e0287f38e73f3802ec6d..2a891e143c047119e43652a7e6f2d0bf5a902e4e 100644 (file)
@@ -7,15 +7,12 @@
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
 //
 
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
 
        public class KeyInfoRetrievalMethod : KeyInfoClause {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private string URI;
 
                public KeyInfoRetrievalMethod () {}
@@ -32,20 +29,11 @@ namespace System.Security.Cryptography.Xml {
 
                public override XmlElement GetXml () 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<RetrievalElement ");
-                       if (URI != null) {
-                               sb.Append ("URI=\"");
-                               sb.Append (URI);
-                               sb.Append ("\" ");
-                       }
-                       sb.Append ("xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\" />");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml(sb.ToString ());
-                       return doc.DocumentElement;
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.RetrievalMethod, XmlSignature.NamespaceURI);
+                       if (URI != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.URI, URI);
+                       return xel;
                }
 
                public override void LoadXml (XmlElement value) 
@@ -53,11 +41,10 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ();
 
-                       if ((value.LocalName == "RetrievalElement") && (value.NamespaceURI == xmldsig)) {
-                               URI = value.Attributes["URI"].Value;
-                       }
-                       else
+                       if ((value.LocalName != XmlSignature.ElementNames.RetrievalMethod) || (value.NamespaceURI != XmlSignature.NamespaceURI))
                                URI = ""; // not null - so we return URI="" as attribute !!!
+                       else
+                               URI = value.Attributes [XmlSignature.AttributeNames.URI].Value;
                }
        }
 }
\ No newline at end of file
index 17eaaba2e7dccf740b634a0a301162bb28bdbd2c..1252c20edb23be5b256be92110a02ab087411fb4 100644 (file)
@@ -9,7 +9,6 @@
 
 using System.Collections;
 using System.Security.Cryptography.X509Certificates;
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
@@ -28,8 +27,6 @@ namespace System.Security.Cryptography.Xml {
 
        public class KeyInfoX509Data : KeyInfoClause {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private byte[] x509crl;
                private ArrayList IssuerSerialList;
                private ArrayList SubjectKeyIdList;
@@ -103,58 +100,54 @@ namespace System.Security.Cryptography.Xml {
                        if ((x509crl == null) && (count == 0))
                                throw new CryptographicException ("value");
 
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<X509Data xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\">");
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.X509Data, XmlSignature.NamespaceURI);
+                       // FIXME: hack to match MS implementation
+                       xel.SetAttribute ("xmlns", XmlSignature.NamespaceURI);
                        // <X509IssuerSerial>
                        if (IssuerSerialList.Count > 0) {
-                               sb.Append ("<X509IssuerSerial>");
                                foreach (IssuerSerial iser in IssuerSerialList) {
-                                       sb.Append ("<X509IssuerName>");
-                                       sb.Append (iser.Issuer);
-                                       sb.Append ("</X509IssuerName>");
-                                       sb.Append ("<X509SerialNumber>");
-                                       sb.Append (iser.Serial);
-                                       sb.Append ("</X509SerialNumber>");
+                                       XmlElement isl = document.CreateElement (XmlSignature.ElementNames.X509IssuerSerial, XmlSignature.NamespaceURI);
+                                       XmlElement xin = document.CreateElement (XmlSignature.ElementNames.X509IssuerName, XmlSignature.NamespaceURI);
+                                       xin.InnerText = iser.Issuer;
+                                       isl.AppendChild (xin);
+                                       XmlElement xsn = document.CreateElement (XmlSignature.ElementNames.X509SerialNumber, XmlSignature.NamespaceURI);
+                                       xsn.InnerText = iser.Serial;
+                                       isl.AppendChild (xsn);
+                                       xel.AppendChild (isl);
                                }
-                               sb.Append ("</X509IssuerSerial>");
                        }
                        // <X509SKI>
                        if (SubjectKeyIdList.Count > 0) {
                                foreach (byte[] skid in SubjectKeyIdList) {
-                                       sb.Append ("<X509SKI>");
-                                       sb.Append (Convert.ToBase64String (skid));
-                                       sb.Append ("</X509SKI>");
+                                       XmlElement ski = document.CreateElement (XmlSignature.ElementNames.X509SKI, XmlSignature.NamespaceURI);
+                                       ski.InnerText = Convert.ToBase64String (skid);
+                                       xel.AppendChild (ski);
                                }
                        }
                        // <X509SubjectName>
                        if (SubjectNameList.Count > 0) {
                                foreach (string subject in SubjectNameList) {
-                                       sb.Append ("<X509SubjectName>");
-                                       sb.Append (subject);
-                                       sb.Append ("</X509SubjectName>");
+                                       XmlElement sn = document.CreateElement (XmlSignature.ElementNames.X509SubjectName, XmlSignature.NamespaceURI);
+                                       sn.InnerText = subject;
+                                       xel.AppendChild (sn);
                                }
                        }
                        // <X509Certificate>
                        if (X509CertificateList.Count > 0) {
                                foreach (X509Certificate x509 in X509CertificateList) {
-                                       sb.Append ("<X509Certificate>");
-                                       sb.Append (Convert.ToBase64String (x509.GetRawCertData ()));
-                                       sb.Append ("</X509Certificate>");
+                                       XmlElement cert = document.CreateElement (XmlSignature.ElementNames.X509Certificate, XmlSignature.NamespaceURI);
+                                       cert.InnerText = Convert.ToBase64String (x509.GetRawCertData ());
+                                       xel.AppendChild (cert);
                                }
                        }
                        // only one <X509CRL> 
                        if (x509crl != null) {
-                               sb.Append ("<X509CRL>");
-                               sb.Append (Convert.ToBase64String (x509crl));
-                               sb.Append ("</X509CRL>");
+                               XmlElement crl = document.CreateElement (XmlSignature.ElementNames.X509CRL, XmlSignature.NamespaceURI);
+                               crl.InnerText = Convert.ToBase64String (x509crl);
+                               xel.AppendChild (crl);
                        }
-                       sb.Append ("</X509Data>");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml(sb.ToString ());
-                       return doc.DocumentElement;
+                       return xel;
                }
 
                public override void LoadXml (XmlElement element) 
@@ -168,49 +161,48 @@ namespace System.Security.Cryptography.Xml {
                        X509CertificateList.Clear ();
                        x509crl = null;
 
-                       if ((element.LocalName == "X509Data") && (element.NamespaceURI == xmldsig)) {
-                               XmlNodeList xnl = null;
-                               // <X509IssuerSerial>
-                               xnl = element.GetElementsByTagName ("X509IssuerSerial", xmldsig);
-                               if (xnl != null) {
-                                       for (int i=0; i < xnl.Count; i++) {
-                                               XmlElement xel = (XmlElement) xnl[i];
-                                               XmlNodeList issuer = xel.GetElementsByTagName ("X509IssuerName", xmldsig);
-                                               XmlNodeList serial = xel.GetElementsByTagName ("X509SerialNumber", xmldsig);
-                                               AddIssuerSerial (issuer[0].InnerText, serial[0].InnerText);
-                                       }
-                               }
-                               // <X509SKI>
-                               xnl = element.GetElementsByTagName ("X509SKI", xmldsig);
-                               if (xnl != null) {
-                                       for (int i=0; i < xnl.Count; i++) {
-                                               byte[] skid = Convert.FromBase64String (xnl[i].InnerXml);
-                                               AddSubjectKeyId (skid);
-                                       }
+                       if ((element.LocalName != XmlSignature.ElementNames.X509Data) || (element.NamespaceURI != XmlSignature.NamespaceURI))
+                               throw new CryptographicException ("element");
+
+                       XmlNodeList xnl = null;
+                       // <X509IssuerSerial>
+                       xnl = element.GetElementsByTagName (XmlSignature.ElementNames.X509IssuerSerial, XmlSignature.NamespaceURI);
+                       if (xnl != null) {
+                               for (int i=0; i < xnl.Count; i++) {
+                                       XmlElement xel = (XmlElement) xnl[i];
+                                       XmlNodeList issuer = xel.GetElementsByTagName (XmlSignature.ElementNames.X509IssuerName, XmlSignature.NamespaceURI);
+                                       XmlNodeList serial = xel.GetElementsByTagName (XmlSignature.ElementNames.X509SerialNumber, XmlSignature.NamespaceURI);
+                                       AddIssuerSerial (issuer[0].InnerText, serial[0].InnerText);
                                }
-                               // <X509SubjectName>
-                               xnl = element.GetElementsByTagName ("X509SubjectName", xmldsig);
-                               if (xnl != null) {
-                                       for (int i=0; i < xnl.Count; i++) {
-                                               AddSubjectName (xnl[i].InnerXml);
-                                       }
+                       }
+                       // <X509SKI>
+                       xnl = element.GetElementsByTagName (XmlSignature.ElementNames.X509SKI, XmlSignature.NamespaceURI);
+                       if (xnl != null) {
+                               for (int i=0; i < xnl.Count; i++) {
+                                       byte[] skid = Convert.FromBase64String (xnl[i].InnerXml);
+                                       AddSubjectKeyId (skid);
                                }
-                               // <X509Certificate>
-                               xnl = element.GetElementsByTagName ("X509Certificate", xmldsig);
-                               if (xnl != null) {
-                                       for (int i=0; i < xnl.Count; i++) {
-                                               byte[] cert = Convert.FromBase64String (xnl[i].InnerXml);
-                                               AddCertificate (new X509Certificate (cert));
-                                       }
+                       }
+                       // <X509SubjectName>
+                       xnl = element.GetElementsByTagName (XmlSignature.ElementNames.X509SubjectName, XmlSignature.NamespaceURI);
+                       if (xnl != null) {
+                               for (int i=0; i < xnl.Count; i++) {
+                                       AddSubjectName (xnl[i].InnerXml);
                                }
-                               // only one <X509CRL> 
-                               xnl = element.GetElementsByTagName ("X509CRL", xmldsig);
-                               if ((xnl != null) && (xnl.Count > 0)) {
-                                       x509crl = Convert.FromBase64String (xnl[0].InnerXml);
+                       }
+                       // <X509Certificate>
+                       xnl = element.GetElementsByTagName (XmlSignature.ElementNames.X509Certificate, XmlSignature.NamespaceURI);
+                       if (xnl != null) {
+                               for (int i=0; i < xnl.Count; i++) {
+                                       byte[] cert = Convert.FromBase64String (xnl[i].InnerXml);
+                                       AddCertificate (new X509Certificate (cert));
                                }
                        }
-                       else
-                               throw new CryptographicException ("element");
+                       // only one <X509CRL> 
+                       xnl = element.GetElementsByTagName (XmlSignature.ElementNames.X509CRL, XmlSignature.NamespaceURI);
+                       if ((xnl != null) && (xnl.Count > 0)) {
+                               x509crl = Convert.FromBase64String (xnl[0].InnerXml);
+                       }
                }
        }
 }
\ No newline at end of file
index 5695909a5bc486a3eb469edfdfa101efb505af74..29bc4ff3af44b1894d795b81e5ed949f870256d0 100644 (file)
@@ -14,8 +14,6 @@ namespace System.Security.Cryptography.Xml {
 
        public class RSAKeyValue : KeyInfoClause {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private RSA rsa;
 
                public RSAKeyValue () 
@@ -35,16 +33,14 @@ namespace System.Security.Cryptography.Xml {
 
                public override XmlElement GetXml () 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<KeyValue xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\">");
-                       sb.Append (rsa.ToXmlString (false));
-                       sb.Append ("</KeyValue>");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml(sb.ToString ());
-                       return doc.DocumentElement;
+                       XmlDocument document = new XmlDocument ();
+                       document.LoadXml ("<KeyValue xmlns=\"" + XmlSignature.NamespaceURI + "\">" + rsa.ToXmlString (false) + "</KeyValue>");
+                       return document.DocumentElement;
+
+                       // FIX: this way we get a xmlns="" in RSAKeyValue
+/*                     XmlElement xel = document.CreateElement (XmlSignature.ElementNames.KeyValue, XmlSignature.NamespaceURI);
+                       xel.InnerXml = rsa.ToXmlString (false);
+                       return xel;*/
                }
 
                public override void LoadXml (XmlElement value) 
@@ -52,10 +48,11 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ();
 
-                       if ((value.LocalName == "KeyValue") && (value.NamespaceURI == xmldsig))
-                               rsa.FromXmlString (value.InnerXml);
-                       else
+                       // FIXME: again hack to match MS implementation (required for previous hack)
+                       if ((value.LocalName != XmlSignature.ElementNames.KeyValue) || ((value.NamespaceURI != XmlSignature.NamespaceURI) && (value.GetAttribute("xmlns") != XmlSignature.NamespaceURI)))
                                throw new CryptographicException ("value");
+
+                       rsa.FromXmlString (value.InnerXml);
                }
        }
 }
\ No newline at end of file
index 653dd410d7024331bce4ac668b056e4ae5ae2b76..7732864c548dcf04767379e1eb8a18a968084968 100644 (file)
@@ -8,7 +8,6 @@
 //
 
 using System.IO;
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml { 
@@ -24,13 +23,10 @@ namespace System.Security.Cryptography.Xml {
                private string type;
                private HashAlgorithm hash;
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-               static private string sha1 = xmldsig + "sha1";
-
                public Reference () 
                {
                        chain = new TransformChain ();
-                       digestMethod = sha1;
+                       digestMethod = XmlSignature.NamespaceURI + "sha1";
                }
 
                [MonoTODO()]
@@ -85,53 +81,34 @@ namespace System.Security.Cryptography.Xml {
                        if (digestValue == null)
                                throw new NullReferenceException ("DigestValue");
 
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<Reference");
-                       if (id != null) {
-                               sb.Append (" Id=\"");
-                               sb.Append (id);
-                               sb.Append ("\"");
-                       }
-                       if (uri != null) {
-                               sb.Append (" URI=\"");
-                               sb.Append (uri);
-                               sb.Append ("\"");
-                       }
-                       if (type != null) {
-                               sb.Append (" Type=\"");
-                               sb.Append (type);
-                               sb.Append ("\"");
-                       }
-                       sb.Append (" xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\">");
-
-                       if (chain.Count > 0) {
-                               sb.Append ("<Transforms>");
-                               sb.Append ("</Transforms>");
-                       }
-
-                       sb.Append ("<DigestMethod Algorithm=\"");
-                       sb.Append (digestMethod);
-                       sb.Append ("\" />");
-                       sb.Append ("<DigestValue>");
-                       sb.Append (Convert.ToBase64String (digestValue));
-                       sb.Append ("</DigestValue>");
-                       sb.Append ("</Reference>");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml (sb.ToString ());
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Reference, XmlSignature.NamespaceURI);
+                       if (id != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
+                       if (uri != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.URI, uri);
+                       if (type != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.Type, type);
 
                        if (chain.Count > 0) {
-                               XmlNodeList xnl = doc.GetElementsByTagName ("Transforms");
+                               XmlElement ts = document.CreateElement (XmlSignature.ElementNames.Transforms, XmlSignature.NamespaceURI);
                                foreach (Transform t in chain) {
                                        XmlNode xn = t.GetXml ();
-                                       XmlNode newNode = doc.ImportNode (xn, true);
-                                       xnl[0].AppendChild (newNode);
+                                       XmlNode newNode = document.ImportNode (xn, true);
+                                       ts.AppendChild (newNode);
                                }
+                               xel.AppendChild (ts);
                        }
 
-                       return doc.DocumentElement;
+                       XmlElement dm = document.CreateElement (XmlSignature.ElementNames.DigestMethod, XmlSignature.NamespaceURI);
+                       dm.SetAttribute (XmlSignature.AttributeNames.Algorithm, digestMethod);
+                       xel.AppendChild (dm);
+
+                       XmlElement dv = document.CreateElement (XmlSignature.ElementNames.DigestValue, XmlSignature.NamespaceURI);
+                       dv.InnerText = Convert.ToBase64String (digestValue);
+                       xel.AppendChild (dv);
+
+                       return xel;
                }
 
                private string GetAttributeFromElement (XmlElement xel, string attribute, string element) 
@@ -158,51 +135,50 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ("value");
 
-                       if ((value.LocalName == "Reference") && (value.NamespaceURI == xmldsig)) {
-                               id = GetAttribute (value, "Id");
-                               uri = GetAttribute (value, "URI");
-                               type = GetAttribute (value, "Type");
-                               // Note: order is important for validations
-                               XmlNodeList xnl = value.GetElementsByTagName ("Transform");
-                               if ((xnl != null) && (xnl.Count > 0)) {
-                                       Transform t = null;
-                                       foreach (XmlNode xn in xnl) {
-                                               string a = GetAttribute ((XmlElement)xn, "Algorithm");
-                                               switch (a) {
-                                                       case "http://www.w3.org/2000/09/xmldsig#base64":
-                                                               t = new XmlDsigBase64Transform ();
-                                                               break;
-                                                       case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315":
-                                                               t = new XmlDsigC14NTransform ();
-                                                               break;
-                                                       case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments":
-                                                               t = new XmlDsigC14NWithCommentsTransform ();
-                                                               break;
-                                                       case "http://www.w3.org/2000/09/xmldsig#enveloped-signature":
-                                                               t = new XmlDsigEnvelopedSignatureTransform ();
-                                                               break;
-                                                       case "http://www.w3.org/TR/1999/REC-xpath-19991116":
-                                                               t = new XmlDsigXPathTransform ();
-                                                               break;
-                                                       case "http://www.w3.org/TR/1999/REC-xslt-19991116":
-                                                               t = new XmlDsigXsltTransform ();
-                                                               break;
-                                                       default:
-                                                               throw new NotSupportedException ();
-                                               }
-                                               AddTransform (t);
+                       if ((value.LocalName != XmlSignature.ElementNames.Reference) || (value.NamespaceURI != XmlSignature.NamespaceURI))
+                               throw new CryptographicException ();
+
+                       id = GetAttribute (value, XmlSignature.AttributeNames.Id);
+                       uri = GetAttribute (value, XmlSignature.AttributeNames.URI);
+                       type = GetAttribute (value, XmlSignature.AttributeNames.Type);
+                       // Note: order is important for validations
+                       XmlNodeList xnl = value.GetElementsByTagName (XmlSignature.ElementNames.Transform);
+                       if ((xnl != null) && (xnl.Count > 0)) {
+                               Transform t = null;
+                               foreach (XmlNode xn in xnl) {
+                                       string a = GetAttribute ((XmlElement)xn, XmlSignature.AttributeNames.Algorithm);
+                                       switch (a) {
+                                               case "http://www.w3.org/2000/09/xmldsig#base64":
+                                                       t = new XmlDsigBase64Transform ();
+                                                       break;
+                                               case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315":
+                                                       t = new XmlDsigC14NTransform ();
+                                                       break;
+                                               case "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments":
+                                                       t = new XmlDsigC14NWithCommentsTransform ();
+                                                       break;
+                                               case "http://www.w3.org/2000/09/xmldsig#enveloped-signature":
+                                                       t = new XmlDsigEnvelopedSignatureTransform ();
+                                                       break;
+                                               case "http://www.w3.org/TR/1999/REC-xpath-19991116":
+                                                       t = new XmlDsigXPathTransform ();
+                                                       break;
+                                               case "http://www.w3.org/TR/1999/REC-xslt-19991116":
+                                                       t = new XmlDsigXsltTransform ();
+                                                       break;
+                                               default:
+                                                       throw new NotSupportedException ();
                                        }
-                               }
-                               // get DigestMethod
-                               DigestMethod = GetAttributeFromElement (value, "Algorithm", "DigestMethod");
-                               // get DigestValue
-                               xnl = value.GetElementsByTagName ("DigestValue");
-                               if ((xnl != null) && (xnl.Count > 0)) {
-                                       DigestValue = Convert.FromBase64String (xnl[0].InnerText);
+                                       AddTransform (t);
                                }
                        }
-                       else
-                               throw new CryptographicException ();
+                       // get DigestMethod
+                       DigestMethod = GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.DigestMethod);
+                       // get DigestValue
+                       xnl = value.GetElementsByTagName (XmlSignature.ElementNames.DigestValue);
+                       if ((xnl != null) && (xnl.Count > 0)) {
+                               DigestValue = Convert.FromBase64String (xnl[0].InnerText);
+                       }
                }
        }
 }
index 8e870fbfab98dc622758220915d5419c04e0f604..a2aeeb3aee42ee44b233a0ed885ca05f6c32c9e3 100644 (file)
@@ -9,15 +9,12 @@
 
 using System.Collections;
 using System.Security.Cryptography;
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
 
        public class Signature {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private ArrayList list;
                private SignedInfo info;
                private KeyInfo key;
@@ -66,51 +63,36 @@ namespace System.Security.Cryptography.Xml {
                        if (signature == null)
                                throw new CryptographicException ("SignatureValue");
 
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<Signature");
-                       if (id != null) {
-                               sb.Append (" Id = \"");
-                               sb.Append (id);
-                               sb.Append ("\"");
-                       }
-                       sb.Append (" xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\" />");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml (sb.ToString ());
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Signature, XmlSignature.NamespaceURI);
+                       if (id != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
 
-                       XmlNode xn = null;
-                       XmlNode newNode = null;
-
-                       if (info != null) {
-                               // this adds the xmlns=xmldsig
-                               xn = info.GetXml ();
-                               newNode = doc.ImportNode (xn, true);
-                               doc.DocumentElement.AppendChild (newNode);
-                       }
+                       XmlNode xn = info.GetXml ();
+                       XmlNode newNode = document.ImportNode (xn, true);
+                       xel.AppendChild (newNode);
 
                        if (signature != null) {
-                               XmlElement sv = doc.CreateElement ("SignatureValue", xmldsig);
+                               XmlElement sv = document.CreateElement (XmlSignature.ElementNames.SignatureValue, XmlSignature.NamespaceURI);
                                sv.InnerText = Convert.ToBase64String (signature);
-                               doc.DocumentElement.AppendChild (sv);
+                               xel.AppendChild (sv);
                        }
 
                        if (key != null) {
                                xn = key.GetXml ();
-                               newNode = doc.ImportNode (xn, true);
-                               doc.DocumentElement.AppendChild (newNode);
+                               newNode = document.ImportNode (xn, true);
+                               xel.AppendChild (newNode);
                        }
 
                        if (list.Count > 0) {
                                foreach (DataObject obj in list) {
                                        xn = obj.GetXml ();
-                                       newNode = doc.ImportNode (xn, true);
-                                       doc.DocumentElement.AppendChild (newNode);
+                                       newNode = document.ImportNode (xn, true);
+                                       xel.AppendChild (newNode);
                                }
                        }
 
-                       return doc.DocumentElement;
+                       return xel;
                }
 
                private string GetAttribute (XmlElement xel, string attribute) 
@@ -124,27 +106,27 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ("value");
 
-                       if ((value.LocalName == "Signature") && (value.NamespaceURI == xmldsig)) {
-                               id = GetAttribute (value, "Id");
+                       if ((value.LocalName == XmlSignature.ElementNames.Signature) && (value.NamespaceURI == XmlSignature.NamespaceURI)) {
+                               id = GetAttribute (value, XmlSignature.AttributeNames.Id);
 
-                               XmlNodeList xnl = value.GetElementsByTagName ("SignedInfo");
+                               XmlNodeList xnl = value.GetElementsByTagName (XmlSignature.ElementNames.SignedInfo);
                                if ((xnl != null) && (xnl.Count == 1)) {
                                        info = new SignedInfo ();
                                        info.LoadXml ((XmlElement) xnl[0]);
                                }
 
-                               xnl = value.GetElementsByTagName ("SignatureValue");
+                               xnl = value.GetElementsByTagName (XmlSignature.ElementNames.SignatureValue);
                                if ((xnl != null) && (xnl.Count == 1)) {
                                        signature = Convert.FromBase64String (xnl[0].InnerText);
                                }
 
-                               xnl = value.GetElementsByTagName ("KeyInfo");
+                               xnl = value.GetElementsByTagName (XmlSignature.ElementNames.KeyInfo);
                                if ((xnl != null) && (xnl.Count == 1)) {
                                        key = new KeyInfo ();
                                        key.LoadXml ((XmlElement) xnl[0]);
                                }
 
-                               xnl = value.GetElementsByTagName ("Object");
+                               xnl = value.GetElementsByTagName (XmlSignature.ElementNames.Object);
                                if ((xnl != null) && (xnl.Count > 0)) {
                                        foreach (XmlNode xn in xnl) {
                                                DataObject obj = new DataObject ();
index 05a8e3e849d6c3e6496304d935e086f00d99ecb0..af9657fe7db21ed66790944614fb745e5e7f7ff6 100644 (file)
@@ -8,15 +8,12 @@
 //
 
 using System.Collections;
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml { 
 
        public class SignedInfo : ICollection, IEnumerable {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private ArrayList references;
                private string c14nMethod;
                private string id;
@@ -96,47 +93,36 @@ namespace System.Security.Cryptography.Xml {
                        if (references.Count == 0)
                                throw new CryptographicException ("References empty");
 
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<SignedInfo");
-                       if (id != null) {
-                               sb.Append (" Id=\"");
-                               sb.Append (id);
-                               sb.Append ("\"");
-                       }
-                       sb.Append (" xmlns=\"");
-                       sb.Append (xmldsig);
-                       sb.Append ("\">");
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI);
+                       if (id != null)
+                               xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
+
                        if (c14nMethod != null) {
-                               sb.Append ("<CanonicalizationMethod Algorithm=\"");
-                               sb.Append (c14nMethod);
-                               sb.Append ("\" />");
+                               XmlElement c14n = document.CreateElement (XmlSignature.ElementNames.CanonicalizationMethod, XmlSignature.NamespaceURI);
+                               c14n.SetAttribute (XmlSignature.AttributeNames.Algorithm, c14nMethod);
+                               xel.AppendChild (c14n);
                        }
                        if (signatureMethod != null) {
-                               sb.Append ("<SignatureMethod Algorithm=\"");
-                               sb.Append (signatureMethod);
+                               XmlElement sm = document.CreateElement (XmlSignature.ElementNames.SignatureMethod, XmlSignature.NamespaceURI);
+                               sm.SetAttribute (XmlSignature.AttributeNames.Algorithm, signatureMethod);
                                if (signatureLength != null) {
-                                       sb.Append ("\">");
-                                       sb.Append ("<HMACOutputLength>");
-                                       sb.Append (signatureLength);
-                                       sb.Append ("</HMACOutputLength>");
-                                       sb.Append ("</SignatureMethod>");
+                                       XmlElement hmac = document.CreateElement (XmlSignature.ElementNames.HMACOutputLength, XmlSignature.NamespaceURI);
+                                       hmac.InnerText = signatureLength;
+                                       sm.AppendChild (hmac);
                                }
-                               else
-                                       sb.Append ("\" />");
+                               xel.AppendChild (sm);
                        }
-                       sb.Append ("</SignedInfo>");
 
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml (sb.ToString ());
                        // we add References afterward so we don't end up with extraneous
                        // xmlns="..." in each reference elements.
                        foreach (Reference r in references) {
                                XmlNode xn = r.GetXml ();
-                               XmlNode newNode = doc.ImportNode (xn, true);
-                               doc.DocumentElement.AppendChild (newNode);
+                               XmlNode newNode = document.ImportNode (xn, true);
+                               xel.AppendChild (newNode);
                        }
 
-                       return doc.DocumentElement;
+                       return xel;
                }
 
                private string GetAttributeFromElement (XmlElement xel, string attribute, string element) 
@@ -163,20 +149,19 @@ namespace System.Security.Cryptography.Xml {
                        if (value == null)
                                throw new ArgumentNullException ("value");
 
-                       if ((value.LocalName == "SignedInfo") && (value.NamespaceURI == xmldsig)) {
-                               id = GetAttribute (value, "Id");
-                               c14nMethod = GetAttributeFromElement (value, "Algorithm", "CanonicalizationMethod");
-                               signatureMethod = GetAttributeFromElement (value, "Algorithm", "SignatureMethod");
-                               // TODO signatureLength for HMAC
-                               XmlNodeList xnl = value.GetElementsByTagName ("Reference");
-                               foreach (XmlNode xn in xnl) {
-                                       Reference r = new Reference ();
-                                       r.LoadXml ((XmlElement) xn);
-                                       AddReference (r);
-                               }
-                       }
-                       else
+                       if ((value.LocalName != XmlSignature.ElementNames.SignedInfo) || (value.NamespaceURI != XmlSignature.NamespaceURI))
                                throw new CryptographicException ();
+
+                       id = GetAttribute (value, XmlSignature.AttributeNames.Id);
+                       c14nMethod = GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.CanonicalizationMethod);
+                       signatureMethod = GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.SignatureMethod);
+                       // TODO signatureLength for HMAC
+                       XmlNodeList xnl = value.GetElementsByTagName (XmlSignature.ElementNames.Reference);
+                       foreach (XmlNode xn in xnl) {
+                               Reference r = new Reference ();
+                               r.LoadXml ((XmlElement) xn);
+                               AddReference (r);
+                       }
                }
        }
 }
index 7e86f199e7f6f0efc3c09ff59d8d708b2b31625c..68b1566f83720e159786ff352491de4f4e7c7550 100644 (file)
@@ -10,7 +10,6 @@
 using System.Collections;
 using System.IO;
 using System.Security.Cryptography;
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml {
index f03c1da34b6f5a65b3d733f33d5a49832c852cbd..acabe1a99bd68526505693d69ffa6322a573d859 100644 (file)
@@ -7,15 +7,12 @@
 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
 //
 
-using System.Text;
 using System.Xml;
 
 namespace System.Security.Cryptography.Xml { 
 
        public abstract class Transform {
 
-               static private string xmldsig = "http://www.w3.org/2000/09/xmldsig#";
-
                private string algo;
 
                public Transform () {}
@@ -41,16 +38,10 @@ namespace System.Security.Cryptography.Xml {
 
                public XmlElement GetXml () 
                {
-                       StringBuilder sb = new StringBuilder ();
-                       sb.Append ("<Transform Algorithm=\"");
-                       sb.Append (algo);
-//                     sb.Append ("\" xmlns=\"");
-//                     sb.Append (xmldsig);
-                       sb.Append ("\" />");
-
-                       XmlDocument doc = new XmlDocument ();
-                       doc.LoadXml (sb.ToString ());
-                       return doc.DocumentElement;
+                       XmlDocument document = new XmlDocument ();
+                       XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI);
+                       xel.SetAttribute (XmlSignature.AttributeNames.Algorithm, algo);
+                       return xel;
                }
 
                public abstract void LoadInnerXml (XmlNodeList nodeList);
index 45c69d274c6966fc4daaf732a28f506da136fa96..601bcbf596dc676d24ec8ee01d8174e182f0937d 100644 (file)
@@ -22,6 +22,7 @@ namespace System.Security.Cryptography.Xml {
 
                public XmlDsigEnvelopedSignatureTransform () 
                {
+                       Algorithm = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
                        comments = false;
                }
 
index b55f0e078a0a0851ad9c25618bcd392660ab3962..66c321286e1d4b30b56ec2f9026be7e7453c0394 100644 (file)
@@ -27,6 +27,7 @@ namespace System.Security.Cryptography.Xml {
 
                public XmlDsigXPathTransform () 
                {
+                       Algorithm = "http://www.w3.org/TR/1999/REC-xpath-19991116";
                }
 
                public override Type[] InputTypes {
diff --git a/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs b/mcs/class/System.Security/System.Security.Cryptography.Xml/XmlSignature.cs
new file mode 100644 (file)
index 0000000..b0033fe
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// XmlSignature.cs: Handles Xml Signature
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+
+namespace System.Security.Cryptography.Xml {
+
+       // following the design of WSE
+       internal class XmlSignature {
+
+               public class ElementNames {
+
+                       public const string CanonicalizationMethod = "CanonicalizationMethod";
+                       public const string DigestMethod = "DigestMethod";
+                       public const string DigestValue = "DigestValue";
+                       public const string DSAKeyValue = "DSAKeyValue";
+                       public const string HMACOutputLength = "HMACOutputLength";
+                       public const string KeyInfo = "KeyInfo";
+                       public const string KeyName = "KeyName";
+                       public const string KeyValue = "KeyValue";
+                       public const string Object = "Object";
+                       public const string Reference = "Reference";
+                       // RetrievalMethod - RetrievalElement ??? seems like a BUG to me ?
+                       public const string RetrievalMethod = "RetrievalElement";
+                       public const string RSAKeyValue = "RSAKeyValue";
+                       public const string Signature = "Signature";
+                       public const string SignatureMethod = "SignatureMethod";
+                       public const string SignatureValue = "SignatureValue";
+                       public const string SignedInfo = "SignedInfo";
+                       public const string Transform = "Transform";
+                       public const string Transforms = "Transforms";
+                       public const string X509Data = "X509Data";
+                       public const string X509IssuerSerial = "X509IssuerSerial";
+                       public const string X509IssuerName = "X509IssuerName";
+                       public const string X509SerialNumber = "X509SerialNumber";
+                       public const string X509SKI = "X509SKI";
+                       public const string X509SubjectName = "X509SubjectName";
+                       public const string X509Certificate = "X509Certificate";
+                       public const string X509CRL = "X509CRL";
+
+                       public ElementNames () {}
+               }
+
+               public class AttributeNames {
+
+                       public const string Algorithm = "Algorithm";
+                       public const string Encoding = "Encoding";
+                       public const string Id = "Id";
+                       public const string MimeType = "MimeType";
+                       public const string Type = "Type";
+                       public const string URI = "URI";
+
+                       public AttributeNames () {}
+               }
+
+               public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
+               public const string Prefix = "ds";
+
+               public XmlSignature () {}
+       }
+}