// Author:
// Sebastien Pouliot <sebastien@ximian.com>
// Atsushi Enomoto <atsushi@ximian.com>
+// Tim Coleman <tim@timcoleman.com>
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// (C) 2004 Novell (http://www.novell.com)
-//
-
+// 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
using System.Text;
using System.Xml;
+#if NET_2_0
+using System.Security.Cryptography.X509Certificates;
+#endif
+
namespace System.Security.Cryptography.Xml {
public class SignedXml {
+ public const string XmlDsigCanonicalizationUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
+ public const string XmlDsigCanonicalizationWithCommentsUrl = XmlDsigCanonicalizationUrl + "#WithComments";
+ public const string XmlDsigDSAUrl = XmlDsigNamespaceUrl + "dsa-sha1";
+ public const string XmlDsigHMACSHA1Url = XmlDsigNamespaceUrl + "hmac-sha1";
+ public const string XmlDsigMinimalCanonicalizationUrl = XmlDsigNamespaceUrl + "minimal";
+ public const string XmlDsigNamespaceUrl = "http://www.w3.org/2000/09/xmldsig#";
+ public const string XmlDsigRSASHA1Url = XmlDsigNamespaceUrl + "rsa-sha1";
+ public const string XmlDsigSHA1Url = XmlDsigNamespaceUrl + "sha1";
+
+#if NET_2_0
+ public const string XmlDecryptionTransformUrl = "http://www.w3.org/2002/07/decrypt#XML";
+ public const string XmlDsigBase64TransformUrl = XmlDsigNamespaceUrl + "base64";
+ public const string XmlDsigC14NTransformUrl = XmlDsigCanonicalizationUrl;
+ public const string XmlDsigC14NWithCommentsTransformUrl = XmlDsigCanonicalizationWithCommentsUrl;
+ public const string XmlDsigEnvelopedSignatureTransformUrl = XmlDsigNamespaceUrl + "enveloped-signature";
+ public const string XmlDsigExcC14NTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#";
+ public const string XmlDsigExcC14NWithCommentsTransformUrl = XmlDsigExcC14NTransformUrl + "WithComments";
+ public const string XmlDsigXPathTransformUrl = "http://www.w3.org/TR/1999/REC-xpath-19991116";
+ public const string XmlDsigXsltTransformUrl = "http://www.w3.org/TR/1999/REC-xslt-19991116";
+
+ private EncryptedXml encryptedXml;
+#endif
+
protected Signature m_signature;
private AsymmetricAlgorithm key;
protected string m_strSigningKeyName;
envdoc.LoadXml (elem.OuterXml);
}
- public const string XmlDsigCanonicalizationUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
- public const string XmlDsigCanonicalizationWithCommentsUrl = XmlDsigCanonicalizationUrl + "#WithComments";
- public const string XmlDsigNamespaceUrl = "http://www.w3.org/2000/09/xmldsig#";
- public const string XmlDsigDSAUrl = XmlDsigNamespaceUrl + "dsa-sha1";
- public const string XmlDsigHMACSHA1Url = XmlDsigNamespaceUrl + "hmac-sha1";
- public const string XmlDsigMinimalCanonicalizationUrl = XmlDsigNamespaceUrl + "minimal";
- public const string XmlDsigRSASHA1Url = XmlDsigNamespaceUrl + "rsa-sha1";
- public const string XmlDsigSHA1Url = XmlDsigNamespaceUrl + "sha1";
+#if NET_2_0
+ public EncryptedXml EncryptedXml {
+ get { return encryptedXml; }
+ set { encryptedXml = value; }
+ }
+#endif
public KeyInfo KeyInfo {
get { return m_signature.KeyInfo; }
{
// These transformer modify input document, which should
// not affect to the input itself.
- if (t is XmlDsigXPathTransform ||
- t is XmlDsigEnvelopedSignatureTransform)
+ if (t is XmlDsigXPathTransform
+ || t is XmlDsigEnvelopedSignatureTransform
+#if NET_2_0
+ || t is XmlDecryptionTransform
+#endif
+ )
input = (XmlDocument) input.Clone ();
t.LoadInput (input);
MemoryStream ms = new MemoryStream ();
XmlTextWriter xtw = new XmlTextWriter (ms, Encoding.UTF8);
((XmlDocument) obj).WriteTo (xtw);
+
+ xtw.Flush ();
+
+ // Rewind to the start of the stream
+ ms.Position = 0;
return ms;
}
else if (obj == null) {
try {
// no way to know if valid without throwing an exception
Uri uri = new Uri (r.Uri);
- s = (Stream) xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream));
+ s = (Stream) xmlResolver.GetEntity (uri, null, typeof (Stream));
}
catch {
// may still be a local file (and maybe not xml)
return false;
}
+#if NET_2_0
+ [MonoTODO]
+ public bool CheckSignature (X509Certificate2 certificate, bool verifySignatureOnly)
+ {
+ throw new NotImplementedException ();
+ }
+#endif
+
public bool CheckSignatureReturningKey (out AsymmetricAlgorithm signingKey)
{
signingKey = CheckSignatureInternal (null);
public XmlElement GetXml ()
{
- return m_signature.GetXml ();
+ return m_signature.GetXml (envdoc);
}
public void LoadXml (XmlElement value)
signatureElement = value;
m_signature.LoadXml (value);
+#if NET_2_0
+ // Need to give the EncryptedXml object to the
+ // XmlDecryptionTransform to give it a fighting
+ // chance at decrypting the document.
+ foreach (Reference r in m_signature.SignedInfo.References) {
+ foreach (Transform t in r.TransformChain) {
+ if (t is XmlDecryptionTransform)
+ ((XmlDecryptionTransform) t).EncryptedXml = EncryptedXml;
+ }
+ }
+#endif
}
#if NET_1_1