* EncryptedKey.cs: Fixed typo.
* Security.cs: Fixed compilation issues.
* SignedXml.cs: Fixed compilation issues.
* SignedXmlSignature.cs: Copied from System.Security assembly (where
it is known as Signature.cs) as MS duplicate the class (in WSE) to
fixed some issues.
* XmlSignature.cs: Added more missing string used in System.Security.
svn path=/trunk/mcs/; revision=17940
+2003-09-06 Sebastien Pouliot <spouliot@videotron.ca>
+
+ * EncryptedKey.cs: Fixed typo.
+ * Security.cs: Fixed compilation issues.
+ * SignedXml.cs: Fixed compilation issues.
+ * SignedXmlSignature.cs: Copied from System.Security assembly (where
+ it is known as Signature.cs) as MS duplicate the class (in WSE) to
+ fixed some issues.
+ * XmlSignature.cs: Added more missing string used in System.Security.
+
2003-09-04 Sebastien Pouliot <spouliot@videotron.ca>
* Reference.cs: Copied from System.Security assembly as MS duplicate
-//\r
-// EncryptedKey.cs: Handles WS-Security EncryptedKey\r
-//\r
-// Author:\r
-// Sebastien Pouliot (spouliot@motus.com)\r
-//\r
-// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)\r
-//\r
-// Licensed under MIT X11 (see LICENSE) with this specific addition:\r
-//\r
-// \93This source code may incorporate intellectual property owned by Microsoft \r
-// Corporation. Our provision of this source code does not include any licenses\r
-// or any other rights to you under any Microsoft intellectual property. If you\r
-// would like a license from Microsoft (e.g. rebrand, redistribute), you need \r
-// to contact Microsoft directly.\94 \r
-//\r
-\r
-using System;\r
-using System.Security.Cryptography.Xml;\r
-using System.Xml;\r
-\r
-namespace Microsoft.Web.Services.Security {\r
-\r
- public class EncryptedKey : IXmlElement {\r
-\r
- private AsymmetricEncryptionKey aek;\r
- private KeyInfo ki;\r
- private ReferenceList list;\r
-\r
- internal EncryptedKey () \r
- {\r
- list = new ReferenceList ();\r
- }\r
-\r
- public EncryptedKey (AsymmetricEncryptionKey key) : this ()\r
- {\r
- if (key == null)\r
- throw new ArgumentNullException ("key");\r
- aek = key;\r
- ki = ki.KeyInfo;\r
- }\r
-\r
- public EncryptedKey (XmlElement element) : this ()\r
- {\r
- LoadXml (element);\r
- }\r
-\r
- public string EncryptionMethod {\r
- get { return null; }\r
- }\r
-\r
- public KeyInfo KeyInfo {\r
- get { return ki; }\r
- }\r
-\r
- public ReferenceList ReferenceList {\r
- get { return list; }\r
- }\r
-\r
- public XmlElement GetXml (XmlDocument document) \r
- {\r
- if (document == null)\r
- throw new ArgumentNullException ("document");\r
- return ki.GetXml ();\r
- }\r
-\r
- public void LoadXml (XmlElement element) \r
- {\r
- if ((element.LocalName != "") || (element.NamespaceURI != ""))\r
- throw new System.ArgumentException ("invalid LocalName or NamespaceURI");\r
- ki = new KeyInfo ();\r
- try {\r
- ki.LoadXml (element);\r
- }\r
- catch {\r
- throw new ArgumentException ("element has no KeyInfo");\r
- }\r
- }\r
- }\r
-}\r
+//
+// EncryptedKey.cs: Handles WS-Security EncryptedKey
+//
+// Author:
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+// Licensed under MIT X11 (see LICENSE) with this specific addition:
+//
+// \93This source code may incorporate intellectual property owned by Microsoft
+// Corporation. Our provision of this source code does not include any licenses
+// or any other rights to you under any Microsoft intellectual property. If you
+// would like a license from Microsoft (e.g. rebrand, redistribute), you need
+// to contact Microsoft directly.\94
+//
+
+using System;
+using System.Security.Cryptography.Xml;
+using System.Xml;
+
+namespace Microsoft.Web.Services.Security {
+
+ public class EncryptedKey : IXmlElement {
+
+ private AsymmetricEncryptionKey aek;
+ private KeyInfo ki;
+ private ReferenceList list;
+
+ internal EncryptedKey ()
+ {
+ list = new ReferenceList ();
+ }
+
+ public EncryptedKey (AsymmetricEncryptionKey key) : this ()
+ {
+ if (key == null)
+ throw new ArgumentNullException ("key");
+ aek = key;
+ ki = new KeyInfo ();
+ }
+
+ public EncryptedKey (XmlElement element) : this ()
+ {
+ LoadXml (element);
+ }
+
+ public string EncryptionMethod {
+ get { return null; }
+ }
+
+ public KeyInfo KeyInfo {
+ get { return ki; }
+ }
+
+ public ReferenceList ReferenceList {
+ get { return list; }
+ }
+
+ public XmlElement GetXml (XmlDocument document)
+ {
+ if (document == null)
+ throw new ArgumentNullException ("document");
+ return ki.GetXml ();
+ }
+
+ public void LoadXml (XmlElement element)
+ {
+ if ((element.LocalName != "") || (element.NamespaceURI != ""))
+ throw new System.ArgumentException ("invalid LocalName or NamespaceURI");
+ ki = new KeyInfo ();
+ try {
+ ki.LoadXml (element);
+ }
+ catch {
+ throw new ArgumentException ("element has no KeyInfo");
+ }
+ }
+ }
+}
-//\r
-// Security.cs: Handles WS-Security Security\r
-//\r
-// Author:\r
-// Sebastien Pouliot (spouliot@motus.com)\r
-//\r
-// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)\r
-//\r
-// Licensed under MIT X11 (see LICENSE) with this specific addition:\r
-//\r
-// \93This source code may incorporate intellectual property owned by Microsoft \r
-// Corporation. Our provision of this source code does not include any licenses\r
-// or any other rights to you under any Microsoft intellectual property. If you\r
-// would like a license from Microsoft (e.g. rebrand, redistribute), you need \r
-// to contact Microsoft directly.\94 \r
-//\r
-\r
-using System;\r
-using System.Web.Services.Protocols;\r
-using System.Xml;\r
-\r
-namespace Microsoft.Web.Services.Security {\r
-\r
- public class Security : SoapHeader, IXmlElement {\r
-\r
- private static string SoapActor = "actor"; // not Actor - no capital A\r
- private static string SoapNamespaceURI = "http://www.w3.org/2001/12/soap-envelope";\r
-\r
- private SecurityElementCollection elems;\r
- private SecurityTokenCollection tokens;\r
-\r
- public Security (string actor) \r
- {\r
- if (actor == null)\r
- throw new ArgumentNullException ("actor");\r
- Actor = actor;\r
- }\r
-\r
- public Security (XmlElement element) \r
- {\r
- LoadXml (element);\r
- }\r
-\r
- public SecurityElementCollection Elements {\r
- get { return elems; }\r
- }\r
-\r
- public SecurityTokenCollection Tokens {\r
- get { return tokens; }\r
- }\r
-\r
- public XmlElement GetXml (XmlDocument document) \r
- {\r
- if (document == null)\r
- throw new ArgumentNullException ("document");\r
-\r
- // much cleaner than using StringBuilder!\r
- XmlElement xel = document.CreateElement (WSSecurity.Prefix, WSSecurity.ElementNames.Security, WSSecurity.NamespaceURI);\r
- xel.SetAttribute (SoapActor, SoapNamespaceURI, Actor);\r
-\r
- foreach (ISecurityElement se in Elements) {\r
- if (se is Signature) {\r
- // TODO\r
- }\r
- else if (se is EncryptedData) {\r
- xel.AppendChild ((se as EncryptedData).GetXml (document));\r
- }\r
- }\r
-\r
- foreach (SecurityToken st in Tokens)\r
- xel.AppendChild (st.GetXml (document));\r
-\r
- return xel;\r
- }\r
-\r
- // base class doesn't have a LoadXml method\r
- public void LoadXml (XmlElement element) \r
- {\r
- if ((element.LocalName != WSSecurity.ElementNames.Security) || (element.NamespaceURI != WSSecurity.NamespaceURI))\r
- throw new System.ArgumentException ("invalid LocalName or NamespaceURI");\r
-\r
- // get attributes\r
- XmlAttribute xa = element.Attributes [SoapActor, SoapNamespaceURI];\r
- Actor = ((xa == null) ? null : xa.Value);\r
-\r
- Elements.Clear ();\r
- Tokens.Clear ();\r
- foreach (XmlNode xn in element.ChildNodes) {\r
- XmlElement xel = (XmlElement) xn;\r
- switch (xn.NamespaceURI) {\r
- case WSSecurity.NamespaceURI:\r
- switch (xn.LocalName) {\r
- case WSSecurity.ElementNames.UsernameToken:\r
- UsernameToken unt = new UsernameToken (xel);\r
- Tokens.Add (unt);\r
- break;\r
- case WSSecurity.ElementNames.BinarySecurityToken:\r
- BinarySecurityToken bst = new BinarySecurityToken (xel);\r
- Tokens.Add (bst);\r
- break;\r
- }\r
- break;\r
- }\r
- }\r
- }\r
- }\r
-}\r
+//
+// Security.cs: Handles WS-Security Security
+//
+// Author:
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+// Licensed under MIT X11 (see LICENSE) with this specific addition:
+//
+// \93This source code may incorporate intellectual property owned by Microsoft
+// Corporation. Our provision of this source code does not include any licenses
+// or any other rights to you under any Microsoft intellectual property. If you
+// would like a license from Microsoft (e.g. rebrand, redistribute), you need
+// to contact Microsoft directly.\94
+//
+
+using System;
+using System.Web.Services.Protocols;
+using System.Xml;
+
+namespace Microsoft.Web.Services.Security {
+
+ public class Security : SoapHeader, IXmlElement {
+
+ private static string SoapActor = "actor"; // not Actor - no capital A
+ private static string SoapNamespaceURI = "http://www.w3.org/2001/12/soap-envelope";
+
+ private SecurityElementCollection elems;
+ private SecurityTokenCollection tokens;
+
+ public Security (string actor)
+ {
+ if (actor == null)
+ throw new ArgumentNullException ("actor");
+ Actor = actor;
+ }
+
+ public Security (XmlElement element)
+ {
+ LoadXml (element);
+ }
+
+ public SecurityElementCollection Elements {
+ get { return elems; }
+ }
+
+ public SecurityTokenCollection Tokens {
+ get { return tokens; }
+ }
+
+ public XmlElement GetXml (XmlDocument document)
+ {
+ if (document == null)
+ throw new ArgumentNullException ("document");
+
+ // much cleaner than using StringBuilder!
+ XmlElement xel = document.CreateElement (WSSecurity.Prefix, WSSecurity.ElementNames.Security, WSSecurity.NamespaceURI);
+ xel.SetAttribute (SoapActor, SoapNamespaceURI, Actor);
+
+ foreach (ISecurityElement se in Elements) {
+ if (se is Signature) {
+ // TODO
+ }
+ else if (se is EncryptedData) {
+ xel.AppendChild ((se as EncryptedData).GetXml (document));
+ }
+ }
+
+ foreach (SecurityToken st in Tokens)
+ xel.AppendChild (st.GetXml (document));
+
+ return xel;
+ }
+
+ // base class doesn't have a LoadXml method
+ public void LoadXml (XmlElement element)
+ {
+ if ((element.LocalName != WSSecurity.ElementNames.Security) || (element.NamespaceURI != WSSecurity.NamespaceURI))
+ throw new System.ArgumentException ("invalid LocalName or NamespaceURI");
+
+ // get attributes
+ XmlAttribute xa = element.Attributes [SoapActor, SoapNamespaceURI];
+ Actor = ((xa == null) ? null : xa.Value);
+
+ Elements.Clear ();
+ Tokens.Clear ();
+ foreach (XmlNode xn in element.ChildNodes) {
+ XmlElement xel = (XmlElement) xn;
+ switch (xn.NamespaceURI) {
+ case WSSecurity.NamespaceURI:
+ switch (xn.LocalName) {
+ case WSSecurity.ElementNames.UsernameToken:
+ UsernameToken unt = new UsernameToken (xel);
+ Tokens.Add (unt);
+ break;
+ case WSSecurity.ElementNames.BinarySecurityToken:
+//FIXME BinarySecurityToken bst = new BinarySecurityToken (xel);
+//FIXME Tokens.Add (bst);
+ break;
+ }
+ break;
+ }
+ }
+ }
+ }
+}
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
//
+using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Xml;
+using SSCX = System.Security.Cryptography.Xml;
+
#if (WSE1 || WSE2)
-using System.Security.Cryptography.Xml;
+using Microsoft.Web.Services.Security;
namespace Microsoft.Web.Services.Security {
#else
+using System.Security.Cryptography.Xml;
+
namespace System.Security.Cryptography.Xml {
#endif
public class SignedXml {
- private Signature signature;
- private AsymmetricAlgorithm key;
- private string keyName;
- private XmlDocument envdoc;
+#if (WSE1 || WSE2)
+ private SignedXmlSignature signature;
public SignedXml ()
{
- signature = new Signature ();
+ signature = new SignedXmlSignature ();
signature.SignedInfo = new SignedInfo ();
}
+#else
+ private Signature signature;
- public SignedXml (XmlDocument document)
+ public SignedXml ()
{
signature = new Signature ();
signature.SignedInfo = new SignedInfo ();
+ }
+#endif
+ private AsymmetricAlgorithm key;
+ private string keyName;
+ private XmlDocument envdoc;
+
+ public SignedXml (XmlDocument document) : this ()
+ {
envdoc = document;
}
{
if (elem == null)
throw new ArgumentNullException ("elem");
- signature = new Signature ();
- signature.SignedInfo = new SignedInfo ();
}
public const string XmlDsigCanonicalizationUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
public const string XmlDsigRSASHA1Url = XmlDsigNamespaceUrl + "rsa-sha1";
public const string XmlDsigSHA1Url = XmlDsigNamespaceUrl + "sha1";
- public KeyInfo KeyInfo {
+ public SSCX.KeyInfo KeyInfo {
get { return signature.KeyInfo; }
set { signature.KeyInfo = value; }
}
+#if (WSE1 || WSE2)
+ public SignedXmlSignature Signature {
+ get { return signature; }
+ }
+#else
public Signature Signature {
get { return signature; }
}
-
+#endif
public string SignatureLength {
get { return signature.SignedInfo.SignatureLength; }
}
set { keyName = value; }
}
- public void AddObject (DataObject dataObject)
+ public void AddObject (SSCX.DataObject dataObject)
{
signature.AddObject (dataObject);
}
signature.SignedInfo.AddReference (reference);
}
- private Stream ApplyTransform (Transform t, XmlDocument doc)
+ private Stream ApplyTransform (SSCX.Transform t, XmlDocument doc)
{
t.LoadInput (doc);
- if (t is XmlDsigEnvelopedSignatureTransform) {
+ if (t is SSCX.XmlDsigEnvelopedSignatureTransform) {
XmlDocument d = (XmlDocument) t.GetOutput ();
MemoryStream ms = new MemoryStream ();
d.Save (ms);
return (Stream) t.GetOutput ();
}
- private Stream ApplyTransform (Transform t, Stream s)
+ private Stream ApplyTransform (SSCX.Transform t, Stream s)
{
try {
t.LoadInput (s);
if (r.Uri == "")
doc = envdoc;
else {
- foreach (DataObject obj in signature.ObjectList) {
+ foreach (SSCX.DataObject obj in signature.ObjectList) {
if ("#" + obj.Id == r.Uri) {
doc.LoadXml (obj.GetXml ().OuterXml);
break;
Stream s = null;
if (r.TransformChain.Count > 0) {
- foreach (Transform t in r.TransformChain) {
+ foreach (SSCX.Transform t in r.TransformChain) {
if (s == null)
s = ApplyTransform (t, doc);
else
}
}
else
- s = ApplyTransform (new XmlDsigC14NTransform (), doc);
+ s = ApplyTransform (new SSCX.XmlDsigC14NTransform (), doc);
// TODO: We should reuse the same hash object (when possible)
HashAlgorithm hash = (HashAlgorithm) CryptoConfig.CreateFromName (r.DigestMethod);
private Stream SignedInfoTransformed ()
{
- Transform t = (Transform) CryptoConfig.CreateFromName (signature.SignedInfo.CanonicalizationMethod);
+ SSCX.Transform t = (SSCX.Transform) CryptoConfig.CreateFromName (signature.SignedInfo.CanonicalizationMethod);
if (t == null)
return null;
{
AsymmetricAlgorithm key = null;
if (signature.KeyInfo != null) {
- foreach (KeyInfoClause kic in signature.KeyInfo) {
- if (kic is DSAKeyValue)
+ foreach (SSCX.KeyInfoClause kic in signature.KeyInfo) {
+ if (kic is SSCX.DSAKeyValue)
key = DSA.Create ();
- else if (kic is RSAKeyValue)
+ else if (kic is SSCX.RSAKeyValue)
key = RSA.Create ();
if (key != null) {
--- /dev/null
+//
+// For System.Security.Cryptography.Xml
+// Signature.cs - Signature implementation for XML Signature
+// For Microsoft.Web.Services.Security
+// SignedXmlSignature.cs
+//
+// Author:
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Collections;
+using System.Security.Cryptography;
+using System.Xml;
+
+#if (WSE1 || WSE2)
+using System.Security.Cryptography.Xml;
+
+namespace Microsoft.Web.Services.Security {
+
+ public class SignedXmlSignature {
+
+ public SignedXmlSignature ()
+#else
+namespace System.Security.Cryptography.Xml {
+
+ public class Signature {
+
+ public Signature ()
+#endif
+ {
+ list = new ArrayList ();
+ }
+
+ private ArrayList list;
+ private SignedInfo info;
+ private KeyInfo key;
+ private string id;
+ private byte[] signature;
+
+ public string Id {
+ get { return id; }
+ set { id = value; }
+ }
+
+ public KeyInfo KeyInfo {
+ get { return key; }
+ set { key = value; }
+ }
+
+ public IList ObjectList {
+ get { return list; }
+ set { list = ArrayList.Adapter (value); }
+ }
+
+ public byte[] SignatureValue {
+ get { return signature; }
+ set { signature = value; }
+ }
+
+ public SignedInfo SignedInfo {
+ get { return info; }
+ set { info = value; }
+ }
+
+ public void AddObject (DataObject dataObject)
+ {
+ list.Add (dataObject);
+ }
+
+ public XmlElement GetXml ()
+ {
+ if (info == null)
+ throw new CryptographicException ("SignedInfo");
+ if (signature == null)
+ throw new CryptographicException ("SignatureValue");
+
+ XmlDocument document = new XmlDocument ();
+ XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Signature, XmlSignature.NamespaceURI);
+ if (id != null)
+ xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
+
+ XmlNode xn = info.GetXml ();
+ XmlNode newNode = document.ImportNode (xn, true);
+ xel.AppendChild (newNode);
+
+ if (signature != null) {
+ XmlElement sv = document.CreateElement (XmlSignature.ElementNames.SignatureValue, XmlSignature.NamespaceURI);
+ sv.InnerText = Convert.ToBase64String (signature);
+ xel.AppendChild (sv);
+ }
+
+ if (key != null) {
+ xn = key.GetXml ();
+ newNode = document.ImportNode (xn, true);
+ xel.AppendChild (newNode);
+ }
+
+ if (list.Count > 0) {
+ foreach (DataObject obj in list) {
+ xn = obj.GetXml ();
+ newNode = document.ImportNode (xn, true);
+ xel.AppendChild (newNode);
+ }
+ }
+
+ return xel;
+ }
+
+ private string GetAttribute (XmlElement xel, string attribute)
+ {
+ XmlAttribute xa = xel.Attributes [attribute];
+ return ((xa != null) ? xa.InnerText : null);
+ }
+
+ public void LoadXml (XmlElement value)
+ {
+ if (value == null)
+ throw new ArgumentNullException ("value");
+
+ if ((value.LocalName == XmlSignature.ElementNames.Signature) && (value.NamespaceURI == XmlSignature.NamespaceURI)) {
+ id = GetAttribute (value, XmlSignature.AttributeNames.Id);
+
+ XmlNodeList xnl = value.GetElementsByTagName (XmlSignature.ElementNames.SignedInfo);
+ if ((xnl != null) && (xnl.Count == 1)) {
+ info = new SignedInfo ();
+ info.LoadXml ((XmlElement) xnl[0]);
+ }
+
+ xnl = value.GetElementsByTagName (XmlSignature.ElementNames.SignatureValue);
+ if ((xnl != null) && (xnl.Count == 1)) {
+ signature = Convert.FromBase64String (xnl[0].InnerText);
+ }
+
+ xnl = value.GetElementsByTagName (XmlSignature.ElementNames.KeyInfo);
+ if ((xnl != null) && (xnl.Count == 1)) {
+ key = new KeyInfo ();
+ key.LoadXml ((XmlElement) xnl[0]);
+ }
+
+ xnl = value.GetElementsByTagName (XmlSignature.ElementNames.Object);
+ if ((xnl != null) && (xnl.Count > 0)) {
+ foreach (XmlNode xn in xnl) {
+ DataObject obj = new DataObject ();
+ obj.LoadXml ((XmlElement) xn);
+ AddObject (obj);
+ }
+ }
+ }
+
+ // if invalid
+ if (info == null)
+ throw new CryptographicException ("SignedInfo");
+ if (signature == null)
+ throw new CryptographicException ("SignatureValue");
+ }
+ }
+}
\ No newline at end of file
internal const string Transforms = "Transforms";
internal const string DigestMethod = "DigestMethod";
internal const string DigestValue = "DigestValue";
+ internal const string SignatureValue = "SignatureValue";
+ internal const string Object = "Object";
public ElementNames () {}
}