You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -134,31 +134,31 @@ namespace System.Security.Cryptography.Xml {
|
||||
foreach (XmlNode xn in ((XmlElement) n).GetElementsByTagName (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI)) {
|
||||
Transform t = null;
|
||||
switch (((XmlElement) xn).Attributes [XmlSignature.AttributeNames.Algorithm].Value) {
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform:
|
||||
case SignedXml.XmlDsigBase64TransformUrl:
|
||||
t = new XmlDsigBase64Transform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform:
|
||||
case SignedXml.XmlDsigC14NTransformUrl:
|
||||
t = new XmlDsigC14NTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform:
|
||||
case SignedXml.XmlDsigC14NWithCommentsTransformUrl:
|
||||
t = new XmlDsigC14NWithCommentsTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform:
|
||||
case SignedXml.XmlDsigEnvelopedSignatureTransformUrl:
|
||||
t = new XmlDsigEnvelopedSignatureTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform:
|
||||
case SignedXml.XmlDsigXPathTransformUrl:
|
||||
t = new XmlDsigXPathTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform:
|
||||
case SignedXml.XmlDsigXsltTransformUrl:
|
||||
t = new XmlDsigXsltTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform:
|
||||
case SignedXml.XmlDsigExcC14NTransformUrl:
|
||||
t = new XmlDsigExcC14NTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NWithCommentsTransform:
|
||||
case SignedXml.XmlDsigExcC14NWithCommentsTransformUrl:
|
||||
t = new XmlDsigExcC14NWithCommentsTransform ();
|
||||
break;
|
||||
case XmlSignature.AlgorithmNamespaces.XmlDecryptionTransform:
|
||||
case SignedXml.XmlDecryptionTransformUrl:
|
||||
t = new XmlDecryptionTransform ();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
//
|
||||
// Reference.cs - Reference implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// 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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
// http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/Overview.html#sec-Reference
|
||||
public class Reference {
|
||||
|
||||
private TransformChain chain;
|
||||
private string digestMethod;
|
||||
private byte[] digestValue;
|
||||
private string id;
|
||||
private string uri;
|
||||
private string type;
|
||||
private Stream stream;
|
||||
private XmlElement element;
|
||||
|
||||
public Reference ()
|
||||
{
|
||||
chain = new TransformChain ();
|
||||
digestMethod = XmlSignature.NamespaceURI + "sha1";
|
||||
}
|
||||
|
||||
[MonoTODO ("There is no description about how it is used.")]
|
||||
public Reference (Stream stream) : this ()
|
||||
{
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public Reference (string uri) : this ()
|
||||
{
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
// default to SHA1
|
||||
public string DigestMethod {
|
||||
get { return digestMethod; }
|
||||
set {
|
||||
element = null;
|
||||
digestMethod = value;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] DigestValue {
|
||||
get { return digestValue; }
|
||||
set {
|
||||
element = null;
|
||||
digestValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Id {
|
||||
get { return id; }
|
||||
set {
|
||||
element = null;
|
||||
id = value;
|
||||
}
|
||||
}
|
||||
|
||||
public TransformChain TransformChain {
|
||||
get { return chain; }
|
||||
[ComVisible (false)]
|
||||
set { chain = value; }
|
||||
}
|
||||
|
||||
public string Type {
|
||||
get { return type; }
|
||||
set {
|
||||
element = null;
|
||||
type = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Uri {
|
||||
get { return uri; }
|
||||
set {
|
||||
element = null;
|
||||
uri = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddTransform (Transform transform)
|
||||
{
|
||||
chain.Add (transform);
|
||||
}
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
if (element != null)
|
||||
return element;
|
||||
|
||||
if (digestMethod == null)
|
||||
throw new CryptographicException ("DigestMethod");
|
||||
if (digestValue == null)
|
||||
throw new NullReferenceException ("DigestValue");
|
||||
|
||||
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) {
|
||||
XmlElement ts = document.CreateElement (XmlSignature.ElementNames.Transforms, XmlSignature.NamespaceURI);
|
||||
foreach (Transform t in chain) {
|
||||
XmlNode xn = t.GetXml ();
|
||||
XmlNode newNode = document.ImportNode (xn, true);
|
||||
ts.AppendChild (newNode);
|
||||
}
|
||||
xel.AppendChild (ts);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// note: we do NOT return null -on purpose- if attribute isn't found
|
||||
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.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, XmlSignature.NamespaceURI);
|
||||
if ((xnl != null) && (xnl.Count > 0)) {
|
||||
Transform t = null;
|
||||
foreach (XmlNode xn in xnl) {
|
||||
string a = GetAttribute ((XmlElement)xn, XmlSignature.AttributeNames.Algorithm);
|
||||
/* This code is useful for debugging in VS.NET because using CryptoConfig
|
||||
(from MS mscorlib) would throw InvalidCastException because it's
|
||||
Transform would come from MS System.Security.dll not Mono's.
|
||||
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;
|
||||
case "http://www.w3.org/2002/07/decrypt#XML":
|
||||
t = new XmlDecryptionTransform ();
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
*/
|
||||
t = (Transform) CryptoConfig.CreateFromName (a);
|
||||
if (t == null)
|
||||
throw new CryptographicException ("Unknown transform {0}.", a);
|
||||
|
||||
if (xn.ChildNodes.Count > 0) {
|
||||
t.LoadInnerXml (xn.ChildNodes);
|
||||
}
|
||||
AddTransform (t);
|
||||
}
|
||||
}
|
||||
// get DigestMethod
|
||||
DigestMethod = XmlSignature.GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.DigestMethod);
|
||||
// get DigestValue
|
||||
XmlElement dig = XmlSignature.GetChildElement (value, XmlSignature.ElementNames.DigestValue, XmlSignature.NamespaceURI);
|
||||
if (dig != null)
|
||||
DigestValue = Convert.FromBase64String (dig.InnerText);
|
||||
element = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,26 +43,36 @@ using System.Security.Cryptography.X509Certificates;
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class SignedXml {
|
||||
public const string XmlDsigNamespaceUrl = "http://www.w3.org/2000/09/xmldsig#";
|
||||
public const string XmlDsigMinimalCanonicalizationUrl = "http://www.w3.org/2000/09/xmldsig#minimal";
|
||||
public const string XmlDsigCanonicalizationUrl = XmlDsigC14NTransformUrl;
|
||||
public const string XmlDsigCanonicalizationWithCommentsUrl = XmlDsigC14NWithCommentsTransformUrl;
|
||||
|
||||
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";
|
||||
public const string XmlDsigSHA1Url = "http://www.w3.org/2000/09/xmldsig#sha1";
|
||||
public const string XmlDsigDSAUrl = "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
|
||||
public const string XmlDsigRSASHA1Url = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
|
||||
public const string XmlDsigHMACSHA1Url = "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
|
||||
|
||||
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";
|
||||
public const string XmlLicenseTransformUrl = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform";
|
||||
public const string XmlDsigSHA256Url = "http://www.w3.org/2001/04/xmlenc#sha256";
|
||||
public const string XmlDsigRSASHA256Url = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
|
||||
|
||||
// Yes, SHA384 is in the xmldsig-more namespace even though all the other SHA variants are in xmlenc. That's the standard.
|
||||
public const string XmlDsigSHA384Url = "http://www.w3.org/2001/04/xmldsig-more#sha384";
|
||||
public const string XmlDsigRSASHA384Url = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384";
|
||||
|
||||
public const string XmlDsigSHA512Url = "http://www.w3.org/2001/04/xmlenc#sha512";
|
||||
public const string XmlDsigRSASHA512Url = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
|
||||
|
||||
public const string XmlDsigC14NTransformUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
|
||||
public const string XmlDsigC14NWithCommentsTransformUrl = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
|
||||
public const string XmlDsigExcC14NTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#";
|
||||
public const string XmlDsigExcC14NWithCommentsTransformUrl = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
|
||||
public const string XmlDsigBase64TransformUrl = "http://www.w3.org/2000/09/xmldsig#base64";
|
||||
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";
|
||||
public const string XmlDsigEnvelopedSignatureTransformUrl = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
|
||||
public const string XmlDecryptionTransformUrl = "http://www.w3.org/2002/07/decrypt#XML";
|
||||
public const string XmlLicenseTransformUrl = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform";
|
||||
|
||||
private EncryptedXml encryptedXml;
|
||||
|
||||
@@ -74,7 +84,9 @@ namespace System.Security.Cryptography.Xml {
|
||||
private XmlElement signatureElement;
|
||||
private Hashtable hashes;
|
||||
// FIXME: enable it after CAS implementation
|
||||
private XmlResolver xmlResolver = new XmlUrlResolver ();
|
||||
internal XmlResolver _xmlResolver = new XmlUrlResolver ();
|
||||
private bool _bResolverSet = true;
|
||||
internal XmlElement _context;
|
||||
private ArrayList manifests;
|
||||
private IEnumerator _x509Enumerator;
|
||||
|
||||
@@ -85,6 +97,7 @@ namespace System.Security.Cryptography.Xml {
|
||||
m_signature = new Signature ();
|
||||
m_signature.SignedInfo = new SignedInfo ();
|
||||
hashes = new Hashtable (2); // 98% SHA1 for now
|
||||
_context = null;
|
||||
}
|
||||
|
||||
public SignedXml (XmlDocument document) : this ()
|
||||
@@ -92,6 +105,7 @@ namespace System.Security.Cryptography.Xml {
|
||||
if (document == null)
|
||||
throw new ArgumentNullException ("document");
|
||||
envdoc = document;
|
||||
_context = document.DocumentElement;
|
||||
}
|
||||
|
||||
public SignedXml (XmlElement elem) : this ()
|
||||
@@ -99,6 +113,7 @@ namespace System.Security.Cryptography.Xml {
|
||||
if (elem == null)
|
||||
throw new ArgumentNullException ("elem");
|
||||
envdoc = new XmlDocument ();
|
||||
_context = elem;
|
||||
envdoc.LoadXml (elem.OuterXml);
|
||||
}
|
||||
|
||||
@@ -148,6 +163,22 @@ namespace System.Security.Cryptography.Xml {
|
||||
set { m_strSigningKeyName = value; }
|
||||
}
|
||||
|
||||
public XmlResolver Resolver
|
||||
{
|
||||
// This property only has a setter. The rationale for this is that we don't have a good value
|
||||
// to return when it has not been explicitely set, as we are using XmlSecureResolver by default
|
||||
set
|
||||
{
|
||||
_xmlResolver = value;
|
||||
_bResolverSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool ResolverSet
|
||||
{
|
||||
get { return _bResolverSet; }
|
||||
}
|
||||
|
||||
public void AddObject (DataObject dataObject)
|
||||
{
|
||||
m_signature.AddObject (dataObject);
|
||||
@@ -221,9 +252,9 @@ namespace System.Security.Cryptography.Xml {
|
||||
FixupNamespaceNodes (xel, doc.DocumentElement, false);
|
||||
}
|
||||
}
|
||||
else if (xmlResolver != null) {
|
||||
else if (_xmlResolver != null) {
|
||||
// TODO: need testing
|
||||
Stream s = (Stream) xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream));
|
||||
Stream s = (Stream) _xmlResolver.GetEntity (new Uri (r.Uri), null, typeof (Stream));
|
||||
doc.Load (s);
|
||||
}
|
||||
|
||||
@@ -281,12 +312,12 @@ namespace System.Security.Cryptography.Xml {
|
||||
else if (r.Uri [0] == '#') {
|
||||
objectName = r.Uri.Substring (1);
|
||||
}
|
||||
else if (xmlResolver != null) {
|
||||
else if (_xmlResolver != null) {
|
||||
// TODO: test but doc says that Resolver = null -> no access
|
||||
try {
|
||||
// no way to know if valid without throwing an exception
|
||||
Uri uri = new Uri (r.Uri);
|
||||
s = (Stream) xmlResolver.GetEntity (uri, null, typeof (Stream));
|
||||
s = (Stream) _xmlResolver.GetEntity (uri, null, typeof (Stream));
|
||||
}
|
||||
catch {
|
||||
// may still be a local file (and maybe not xml)
|
||||
@@ -763,6 +794,11 @@ namespace System.Security.Cryptography.Xml {
|
||||
|
||||
signatureElement = value;
|
||||
m_signature.LoadXml (value);
|
||||
|
||||
if (_context == null) {
|
||||
_context = value;
|
||||
}
|
||||
|
||||
// Need to give the EncryptedXml object to the
|
||||
// XmlDecryptionTransform to give it a fighting
|
||||
// chance at decrypting the document.
|
||||
@@ -773,10 +809,5 @@ namespace System.Security.Cryptography.Xml {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
public XmlResolver Resolver {
|
||||
set { xmlResolver = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
//
|
||||
// Transform.cs - Transform implementation for XML Signature
|
||||
//
|
||||
// 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)
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
// Copyright (C) 2004-2006 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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Policy;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public abstract class Transform {
|
||||
|
||||
private string algo;
|
||||
private XmlResolver xmlResolver;
|
||||
private Hashtable propagated_namespaces = new Hashtable ();
|
||||
|
||||
protected Transform ()
|
||||
{
|
||||
if (SecurityManager.SecurityEnabled) {
|
||||
xmlResolver = new XmlSecureResolver (new XmlUrlResolver (), (Evidence) new Evidence ());
|
||||
} else {
|
||||
xmlResolver = new XmlUrlResolver ();
|
||||
}
|
||||
}
|
||||
|
||||
#region Properties
|
||||
|
||||
public string Algorithm {
|
||||
get { return algo; }
|
||||
set { algo = value; }
|
||||
}
|
||||
|
||||
public abstract Type[] InputTypes {
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract Type[] OutputTypes {
|
||||
get;
|
||||
}
|
||||
|
||||
[ComVisible(false)]
|
||||
public XmlResolver Resolver {
|
||||
set { xmlResolver = value; }
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
[ComVisible (false)]
|
||||
public XmlElement Context {
|
||||
get { throw new NotImplementedException (); }
|
||||
set { throw new NotImplementedException (); }
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
public Hashtable PropagatedNamespaces {
|
||||
get { return propagated_namespaces; }
|
||||
}
|
||||
|
||||
#endregion // Properties
|
||||
|
||||
#region Methods
|
||||
[ComVisible (false)]
|
||||
public virtual byte[] GetDigestedOutput (HashAlgorithm hash)
|
||||
{
|
||||
// no null check, MS throws a NullReferenceException here
|
||||
return hash.ComputeHash ((Stream) GetOutput (typeof (Stream)));
|
||||
}
|
||||
|
||||
protected abstract XmlNodeList GetInnerXml ();
|
||||
|
||||
public abstract object GetOutput ();
|
||||
|
||||
public abstract object GetOutput (Type type);
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
XmlDocument document = new XmlDocument ();
|
||||
document.XmlResolver = GetResolver ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.Transform, XmlSignature.NamespaceURI);
|
||||
xel.SetAttribute (XmlSignature.AttributeNames.Algorithm, algo);
|
||||
XmlNodeList xnl = this.GetInnerXml ();
|
||||
if (xnl != null) {
|
||||
foreach (XmlNode xn in xnl) {
|
||||
XmlNode importedNode = document.ImportNode (xn, true);
|
||||
xel.AppendChild (importedNode);
|
||||
}
|
||||
}
|
||||
return xel;
|
||||
}
|
||||
|
||||
public abstract void LoadInnerXml (XmlNodeList nodeList);
|
||||
|
||||
public abstract void LoadInput (object obj);
|
||||
|
||||
internal XmlResolver GetResolver ()
|
||||
{
|
||||
return xmlResolver;
|
||||
}
|
||||
|
||||
#endregion // Methods
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// TransformChain.cs - TransformChain implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class TransformChain {
|
||||
|
||||
private ArrayList chain;
|
||||
|
||||
public TransformChain()
|
||||
{
|
||||
chain = new ArrayList ();
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get { return chain.Count; }
|
||||
}
|
||||
|
||||
public Transform this [int index] {
|
||||
get { return (Transform) chain [index]; }
|
||||
}
|
||||
|
||||
public void Add (Transform transform)
|
||||
{
|
||||
chain.Add (transform);
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator ()
|
||||
{
|
||||
return chain.GetEnumerator ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
//
|
||||
// XmlDecryptionTransform.cs - XmlDecryptionTransform implementation for XML Encryption
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class XmlDecryptionTransform : Transform {
|
||||
|
||||
#region Fields
|
||||
|
||||
EncryptedXml encryptedXml;
|
||||
Type[] inputTypes;
|
||||
Type[] outputTypes;
|
||||
object inputObj;
|
||||
ArrayList exceptUris;
|
||||
|
||||
const string NamespaceUri = "http://www.w3.org/2002/07/decrypt#";
|
||||
|
||||
#endregion // Fields
|
||||
|
||||
#region Constructors
|
||||
|
||||
public XmlDecryptionTransform ()
|
||||
{
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDecryptionTransform;
|
||||
encryptedXml = new EncryptedXml ();
|
||||
exceptUris = new ArrayList ();
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
|
||||
#region Properties
|
||||
|
||||
public EncryptedXml EncryptedXml {
|
||||
get { return encryptedXml; }
|
||||
set { encryptedXml = value; }
|
||||
}
|
||||
|
||||
public override Type[] InputTypes {
|
||||
get {
|
||||
if (inputTypes == null)
|
||||
inputTypes = new Type [2] {typeof (System.IO.Stream), typeof (System.Xml.XmlDocument)};
|
||||
|
||||
return inputTypes;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (outputTypes == null)
|
||||
outputTypes = new Type [1] {typeof (System.Xml.XmlDocument)};
|
||||
|
||||
return outputTypes;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // Properties
|
||||
|
||||
#region Methods
|
||||
|
||||
public void AddExceptUri (string uri)
|
||||
{
|
||||
exceptUris.Add (uri);
|
||||
}
|
||||
|
||||
private void ClearExceptUris ()
|
||||
{
|
||||
exceptUris.Clear ();
|
||||
}
|
||||
|
||||
[MonoTODO ("Verify")]
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.AppendChild (doc.CreateElement ("DecryptionTransform"));
|
||||
|
||||
foreach (object o in exceptUris) {
|
||||
XmlElement element = doc.CreateElement ("Except", NamespaceUri);
|
||||
element.Attributes.Append (doc.CreateAttribute ("URI", NamespaceUri));
|
||||
element.Attributes ["URI", NamespaceUri].Value = (string) o;
|
||||
doc.DocumentElement.AppendChild (element);
|
||||
}
|
||||
|
||||
return doc.GetElementsByTagName ("Except", NamespaceUri);
|
||||
}
|
||||
|
||||
[MonoTODO ("Verify processing of ExceptURIs")]
|
||||
public override object GetOutput ()
|
||||
{
|
||||
XmlDocument document;
|
||||
if (inputObj is Stream) {
|
||||
document = new XmlDocument ();
|
||||
document.PreserveWhitespace = true;
|
||||
document.XmlResolver = GetResolver ();
|
||||
document.Load (new XmlSignatureStreamReader (
|
||||
new StreamReader (inputObj as Stream)));
|
||||
}
|
||||
else if (inputObj is XmlDocument) {
|
||||
document = inputObj as XmlDocument;
|
||||
}
|
||||
else
|
||||
throw new NullReferenceException ();
|
||||
|
||||
XmlNodeList nodes = document.GetElementsByTagName ("EncryptedData", EncryptedXml.XmlEncNamespaceUrl);
|
||||
foreach (XmlNode node in nodes) {
|
||||
if (node == document.DocumentElement && exceptUris.Contains ("#xpointer(/)"))
|
||||
break;
|
||||
|
||||
// Need to exclude based on ExceptURI. Only accept #id references.
|
||||
foreach (string uri in exceptUris)
|
||||
if (IsTargetElement ((XmlElement) node, uri.Substring (1)))
|
||||
break;
|
||||
|
||||
EncryptedData encryptedData = new EncryptedData ();
|
||||
encryptedData.LoadXml ((XmlElement) node);
|
||||
SymmetricAlgorithm symAlg = EncryptedXml.GetDecryptionKey (encryptedData, encryptedData.EncryptionMethod.KeyAlgorithm);
|
||||
EncryptedXml.ReplaceData ((XmlElement) node, EncryptedXml.DecryptData (encryptedData, symAlg));
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type == typeof (Stream))
|
||||
return GetOutput ();
|
||||
throw new ArgumentException ("type");
|
||||
}
|
||||
|
||||
[MonoTODO ("verify")]
|
||||
protected virtual bool IsTargetElement (XmlElement inputElement, string idValue)
|
||||
{
|
||||
if ((inputElement == null) || (idValue == null))
|
||||
return false;
|
||||
return (inputElement.Attributes ["id"].Value == idValue);
|
||||
}
|
||||
|
||||
[MonoTODO ("This doesn't seem to work in .NET")]
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
if (nodeList == null)
|
||||
throw new NullReferenceException ();
|
||||
|
||||
ClearExceptUris ();
|
||||
foreach (XmlNode node in nodeList) {
|
||||
XmlElement element = node as XmlElement;
|
||||
if (element.NamespaceURI.Equals (NamespaceUri) && element.LocalName.Equals ("Except")) {
|
||||
string uri = element.Attributes ["URI", NamespaceUri].Value;
|
||||
if (!uri.StartsWith ("#"))
|
||||
throw new CryptographicException ("A Uri attribute is required for a CipherReference element.");
|
||||
AddExceptUri (uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
inputObj = obj;
|
||||
}
|
||||
|
||||
#endregion // Methods
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
//
|
||||
// XmlDsigBase64Transform.cs - Base64 Transform implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// (C) 2004 Novell (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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
// http://www.w3.org/2000/09/xmldsig#base64
|
||||
public class XmlDsigBase64Transform : Transform {
|
||||
|
||||
private CryptoStream cs;
|
||||
private Type[] input;
|
||||
private Type[] output;
|
||||
|
||||
public XmlDsigBase64Transform ()
|
||||
{
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigBase64Transform;
|
||||
}
|
||||
|
||||
public override Type[] InputTypes {
|
||||
get {
|
||||
if (input == null) {
|
||||
input = new Type [3];
|
||||
input[0] = typeof (System.IO.Stream);
|
||||
input[1] = typeof (System.Xml.XmlDocument);
|
||||
input[2] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (output == null) {
|
||||
output = new Type [1];
|
||||
output[0] = typeof (System.IO.Stream);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
return null; // THIS IS DOCUMENTED AS SUCH
|
||||
}
|
||||
|
||||
public override object GetOutput ()
|
||||
{
|
||||
return (object) cs;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type != typeof (System.IO.Stream))
|
||||
throw new ArgumentException ("type");
|
||||
return GetOutput ();
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
// documented as not changing the state of the transform
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
XmlNodeList xnl = null;
|
||||
Stream stream = null;
|
||||
|
||||
if (obj is Stream)
|
||||
stream = (obj as Stream);
|
||||
else if (obj is XmlDocument)
|
||||
xnl = (obj as XmlDocument).SelectNodes ("//.");
|
||||
else if (obj is XmlNodeList)
|
||||
xnl = (XmlNodeList) obj;
|
||||
|
||||
if (xnl != null) {
|
||||
stream = new MemoryStream ();
|
||||
StreamWriter sw = new StreamWriter (stream);
|
||||
foreach (XmlNode xn in xnl) {
|
||||
switch (xn.NodeType) {
|
||||
case XmlNodeType.Attribute:
|
||||
case XmlNodeType.Text:
|
||||
case XmlNodeType.CDATA:
|
||||
case XmlNodeType.SignificantWhitespace:
|
||||
case XmlNodeType.Whitespace:
|
||||
sw.Write (xn.Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
sw.Flush ();
|
||||
// ready to be re-used
|
||||
stream.Position = 0;
|
||||
}
|
||||
|
||||
if (stream != null)
|
||||
cs = new CryptoStream (stream, new FromBase64Transform (), CryptoStreamMode.Read);
|
||||
// note: there is no default are other types won't throw an exception
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
//
|
||||
// XmlDsigC14NTransform.cs - C14N Transform implementation for XML Signature
|
||||
// http://www.w3.org/TR/xml-c14n
|
||||
//
|
||||
// Authors:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
// Aleksey Sanin (aleksey@aleksey.com)
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// (C) 2003 Aleksey Sanin (aleksey@aleksey.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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class XmlDsigC14NTransform : Transform {
|
||||
private Type[] input;
|
||||
private Type[] output;
|
||||
private XmlCanonicalizer canonicalizer;
|
||||
private Stream s;
|
||||
|
||||
public XmlDsigC14NTransform () : this (false)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigC14NTransform (bool includeComments)
|
||||
{
|
||||
if (includeComments)
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NWithCommentsTransform;
|
||||
else
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigC14NTransform;
|
||||
canonicalizer = new XmlCanonicalizer (includeComments, false, PropagatedNamespaces);
|
||||
}
|
||||
|
||||
public override Type[] InputTypes {
|
||||
get {
|
||||
if (input == null) {
|
||||
input = new Type [3];
|
||||
input[0] = typeof (System.IO.Stream);
|
||||
input[1] = typeof (System.Xml.XmlDocument);
|
||||
input[2] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (output == null) {
|
||||
output = new Type [1];
|
||||
output[0] = typeof (System.IO.Stream);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
return null; // THIS IS DOCUMENTED AS SUCH
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
public override byte[] GetDigestedOutput (HashAlgorithm hash)
|
||||
{
|
||||
// no null check, MS throws a NullReferenceException here
|
||||
return hash.ComputeHash ((Stream) GetOutput ());
|
||||
}
|
||||
|
||||
public override object GetOutput ()
|
||||
{
|
||||
return (object) s;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type == typeof (Stream))
|
||||
return GetOutput ();
|
||||
throw new ArgumentException ("type");
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
// documented as not changing the state of the transform
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
// possible input: Stream, XmlDocument, and XmlNodeList
|
||||
Stream stream = (obj as Stream);
|
||||
if (stream != null) {
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.PreserveWhitespace = true; // REALLY IMPORTANT
|
||||
doc.XmlResolver = GetResolver ();
|
||||
doc.Load (new XmlSignatureStreamReader (new StreamReader (stream)));
|
||||
// doc.Load ((Stream) obj);
|
||||
s = canonicalizer.Canonicalize (doc);
|
||||
return;
|
||||
}
|
||||
|
||||
XmlDocument xd = (obj as XmlDocument);
|
||||
if (xd != null) {
|
||||
s = canonicalizer.Canonicalize (xd);
|
||||
return;
|
||||
}
|
||||
|
||||
XmlNodeList nl = (obj as XmlNodeList);
|
||||
if (nl != null) {
|
||||
s = canonicalizer.Canonicalize (nl);
|
||||
}
|
||||
else
|
||||
throw new ArgumentException ("obj");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// XmlDsigC14NWithCommentsTransform.cs -
|
||||
// C14N with comments Transform implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class XmlDsigC14NWithCommentsTransform : XmlDsigC14NTransform {
|
||||
|
||||
public XmlDsigC14NWithCommentsTransform() : base (true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
//
|
||||
// XmlDsigEnvelopedSignatureTransform.cs -
|
||||
// Enveloped Signature Transform implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
// Atsushi Enomoto (atsushi@ximian.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// (C) 2004 Novell Inc.
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class XmlDsigEnvelopedSignatureTransform : Transform {
|
||||
|
||||
private Type[] input;
|
||||
private Type[] output;
|
||||
private bool comments;
|
||||
private object inputObj;
|
||||
|
||||
public XmlDsigEnvelopedSignatureTransform ()
|
||||
: this (false)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigEnvelopedSignatureTransform (bool includeComments)
|
||||
{
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigEnvelopedSignatureTransform;
|
||||
comments = includeComments;
|
||||
}
|
||||
|
||||
public override Type[] InputTypes {
|
||||
get {
|
||||
if (input == null) {
|
||||
input = new Type [3];
|
||||
input[0] = typeof (System.IO.Stream);
|
||||
input[1] = typeof (System.Xml.XmlDocument);
|
||||
input[2] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (output == null) {
|
||||
output = new Type [2];
|
||||
output [0] = typeof (System.Xml.XmlDocument);
|
||||
output [1] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
return null; // THIS IS DOCUMENTED AS SUCH
|
||||
}
|
||||
|
||||
// NOTE: This method never supports the requirements written
|
||||
// in xmldsig spec that says its input is canonicalized before
|
||||
// transforming. This method just removes Signature element.
|
||||
// Canonicalization is done in SignedXml.
|
||||
public override object GetOutput ()
|
||||
{
|
||||
XmlDocument doc = null;
|
||||
|
||||
// possible input: Stream, XmlDocument, and XmlNodeList
|
||||
if (inputObj is Stream) {
|
||||
doc = new XmlDocument ();
|
||||
doc.PreserveWhitespace = true;
|
||||
doc.XmlResolver = GetResolver ();
|
||||
doc.Load (new XmlSignatureStreamReader (
|
||||
new StreamReader (inputObj as Stream)));
|
||||
return GetOutputFromNode (doc, GetNamespaceManager (doc), true);
|
||||
}
|
||||
else if (inputObj is XmlDocument) {
|
||||
doc = inputObj as XmlDocument;
|
||||
return GetOutputFromNode (doc, GetNamespaceManager (doc), true);
|
||||
}
|
||||
else if (inputObj is XmlNodeList) {
|
||||
ArrayList al = new ArrayList ();
|
||||
XmlNodeList nl = (XmlNodeList) inputObj;
|
||||
if (nl.Count > 0) {
|
||||
XmlNamespaceManager m = GetNamespaceManager (nl.Item (0));
|
||||
ArrayList tmp = new ArrayList ();
|
||||
foreach (XmlNode n in nl)
|
||||
tmp.Add (n);
|
||||
foreach (XmlNode n in tmp)
|
||||
if (n.SelectNodes ("ancestor-or-self::dsig:Signature", m).Count == 0)
|
||||
al.Add (GetOutputFromNode (n, m, false));
|
||||
}
|
||||
return new XmlDsigNodeList (al);
|
||||
}
|
||||
// Note that it is unexpected behavior with related to InputTypes (MS.NET accepts XmlElement)
|
||||
else if (inputObj is XmlElement) {
|
||||
XmlElement el = inputObj as XmlElement;
|
||||
XmlNamespaceManager m = GetNamespaceManager (el);
|
||||
if (el.SelectNodes ("ancestor-or-self::dsig:Signature", m).Count == 0)
|
||||
return GetOutputFromNode (el, m, true);
|
||||
}
|
||||
|
||||
throw new NullReferenceException ();
|
||||
}
|
||||
|
||||
private XmlNamespaceManager GetNamespaceManager (XmlNode n)
|
||||
{
|
||||
XmlDocument doc = ((n is XmlDocument) ? (n as XmlDocument) : n.OwnerDocument);
|
||||
XmlNamespaceManager nsmgr = new XmlNamespaceManager (doc.NameTable);
|
||||
nsmgr.AddNamespace ("dsig", XmlSignature.NamespaceURI);
|
||||
return nsmgr;
|
||||
}
|
||||
|
||||
private XmlNode GetOutputFromNode (XmlNode input, XmlNamespaceManager nsmgr, bool remove)
|
||||
{
|
||||
if (remove) {
|
||||
XmlNodeList nl = input.SelectNodes ("descendant-or-self::dsig:Signature", nsmgr);
|
||||
ArrayList al = new ArrayList ();
|
||||
foreach (XmlNode n in nl)
|
||||
al.Add (n);
|
||||
foreach (XmlNode n in al)
|
||||
n.ParentNode.RemoveChild (n);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type == typeof (Stream))
|
||||
return GetOutput ();
|
||||
throw new ArgumentException ("type");
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
// NO CHANGE
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
inputObj = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
//
|
||||
// XmlDsigExcC14NTransform.cs - ExcC14N Transform implementation for XML Signature
|
||||
// http://www.w3.org/TR/xml-c14n
|
||||
//
|
||||
// Authors:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
// Aleksey Sanin (aleksey@aleksey.com)
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// (C) 2003 Aleksey Sanin (aleksey@aleksey.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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class XmlDsigExcC14NTransform : Transform {
|
||||
private Type[] input;
|
||||
private Type[] output;
|
||||
private XmlCanonicalizer canonicalizer;
|
||||
private Stream s;
|
||||
private string inclusiveNamespacesPrefixList;
|
||||
|
||||
public XmlDsigExcC14NTransform ()
|
||||
: this (false, null)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigExcC14NTransform (bool includeComments)
|
||||
: this (includeComments, null)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList)
|
||||
: this (false, inclusiveNamespacesPrefixList)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList)
|
||||
{
|
||||
if (includeComments)
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NWithCommentsTransform;
|
||||
else
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigExcC14NTransform;
|
||||
this.inclusiveNamespacesPrefixList = inclusiveNamespacesPrefixList;
|
||||
canonicalizer = new XmlCanonicalizer (includeComments, true, PropagatedNamespaces);
|
||||
}
|
||||
|
||||
public string InclusiveNamespacesPrefixList {
|
||||
get { return inclusiveNamespacesPrefixList; }
|
||||
set { inclusiveNamespacesPrefixList = value; }
|
||||
}
|
||||
|
||||
public override Type[] InputTypes {
|
||||
get {
|
||||
if (input == null) {
|
||||
input = new Type [3];
|
||||
input[0] = typeof (System.IO.Stream);
|
||||
input[1] = typeof (System.Xml.XmlDocument);
|
||||
input[2] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (output == null) {
|
||||
output = new Type [1];
|
||||
output[0] = typeof (System.IO.Stream);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
return null; // THIS IS DOCUMENTED AS SUCH
|
||||
}
|
||||
|
||||
public override byte[] GetDigestedOutput (HashAlgorithm hash)
|
||||
{
|
||||
// no null check, MS throws a NullReferenceException here
|
||||
return hash.ComputeHash ((Stream) GetOutput ());
|
||||
}
|
||||
|
||||
public override object GetOutput ()
|
||||
{
|
||||
return (object) s;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type == typeof (Stream))
|
||||
return GetOutput ();
|
||||
throw new ArgumentException ("type");
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
// documented as not changing the state of the transform
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
canonicalizer.InclusiveNamespacesPrefixList = InclusiveNamespacesPrefixList;
|
||||
// possible input: Stream, XmlDocument, and XmlNodeList
|
||||
Stream stream = (obj as Stream);
|
||||
if (stream != null) {
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.PreserveWhitespace = true; // REALLY IMPORTANT
|
||||
doc.XmlResolver = GetResolver ();
|
||||
doc.Load (new XmlSignatureStreamReader (new StreamReader (stream)));
|
||||
// doc.Load ((Stream) obj);
|
||||
s = canonicalizer.Canonicalize (doc);
|
||||
return;
|
||||
}
|
||||
|
||||
XmlDocument xd = (obj as XmlDocument);
|
||||
if (xd != null) {
|
||||
s = canonicalizer.Canonicalize (xd);
|
||||
return;
|
||||
}
|
||||
|
||||
XmlNodeList nl = (obj as XmlNodeList);
|
||||
if (nl != null) {
|
||||
s = canonicalizer.Canonicalize (nl);
|
||||
}
|
||||
else
|
||||
throw new ArgumentException ("obj");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// XmlDsigExcC14NWithCommentsTransform.cs - XmlDsigExcC14NWithCommentsTransform implementation for XML Encryption
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
public class XmlDsigExcC14NWithCommentsTransform : XmlDsigExcC14NTransform {
|
||||
|
||||
#region Constructors
|
||||
|
||||
public XmlDsigExcC14NWithCommentsTransform ()
|
||||
: base (true)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigExcC14NWithCommentsTransform (string inclusiveNamespacesPrefixList)
|
||||
: base (true, inclusiveNamespacesPrefixList)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion // Constructors
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// XmlDsigNodeList.cs - derived node list class for dsig
|
||||
//
|
||||
// Author:
|
||||
// Atsushi Enomoto <atsushi@ximian.com>
|
||||
//
|
||||
// (C)2004 Novell Inc.
|
||||
//
|
||||
// This class is mostly copied from System.Xml/XmlNodeArrayList.cs
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml
|
||||
{
|
||||
// Copied from XmlNodeArrayList.cs
|
||||
internal class XmlDsigNodeList : XmlNodeList
|
||||
{
|
||||
ArrayList _rgNodes;
|
||||
|
||||
public XmlDsigNodeList (ArrayList rgNodes)
|
||||
{
|
||||
_rgNodes = rgNodes;
|
||||
}
|
||||
|
||||
public override int Count { get { return _rgNodes.Count; } }
|
||||
|
||||
public override IEnumerator GetEnumerator ()
|
||||
{
|
||||
return _rgNodes.GetEnumerator ();
|
||||
}
|
||||
|
||||
public override XmlNode Item (int index)
|
||||
{
|
||||
// Return null if index is out of range. by DOM design.
|
||||
if (index < 0 || _rgNodes.Count <= index)
|
||||
return null;
|
||||
|
||||
return (XmlNode) _rgNodes [index];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
//
|
||||
// XmlDsigXPathTransform.cs -
|
||||
// XmlDsigXPathTransform implementation for XML Signature
|
||||
// http://www.w3.org/TR/1999/REC-xpath-19991116
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
// Atsushi Enomoto <atsushi@ximian.com>
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// 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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.XPath;
|
||||
using System.Xml.Xsl;
|
||||
|
||||
namespace System.Security.Cryptography.Xml
|
||||
{
|
||||
|
||||
// www.w3.org/TR/xmldsig-core/
|
||||
// see Section 6.6.3 of the XMLDSIG specification
|
||||
public class XmlDsigXPathTransform : Transform
|
||||
{
|
||||
|
||||
private Type [] input;
|
||||
private Type [] output;
|
||||
private XmlNodeList xpath;
|
||||
private XmlDocument doc;
|
||||
private XsltContext ctx;
|
||||
|
||||
public XmlDsigXPathTransform ()
|
||||
{
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigXPathTransform;
|
||||
}
|
||||
|
||||
public override Type [] InputTypes {
|
||||
get {
|
||||
if (input == null) {
|
||||
input = new Type [3];
|
||||
input [0] = typeof (System.IO.Stream);
|
||||
input [1] = typeof (System.Xml.XmlDocument);
|
||||
input [2] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (output == null) {
|
||||
// this way the result is cached if called multiple time
|
||||
output = new Type [1];
|
||||
output [0] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
if (xpath == null) {
|
||||
// default value
|
||||
XmlDocument xpdoc = new XmlDocument ();
|
||||
xpdoc.LoadXml ("<XPath xmlns=\"" + XmlSignature.NamespaceURI + "\"></XPath>");
|
||||
xpath = xpdoc.ChildNodes;
|
||||
}
|
||||
return xpath;
|
||||
}
|
||||
|
||||
[MonoTODO ("Evaluation of extension function here() results in different from MS.NET (is MS.NET really correct??).")]
|
||||
public override object GetOutput ()
|
||||
{
|
||||
if ((xpath == null) || (doc == null))
|
||||
return new XmlDsigNodeList (new ArrayList ());
|
||||
// evaluate every time since input or xpath might have changed.
|
||||
string x = null;
|
||||
for (int i = 0; i < xpath.Count; i++) {
|
||||
switch (xpath [i].NodeType) {
|
||||
case XmlNodeType.Text:
|
||||
case XmlNodeType.CDATA:
|
||||
case XmlNodeType.Element:
|
||||
x += xpath [i].InnerText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctx = new XmlDsigXPathContext (doc);
|
||||
foreach (XmlNode n in xpath) {
|
||||
XPathNavigator nav = n.CreateNavigator ();
|
||||
XPathNodeIterator iter = nav.Select ("namespace::*");
|
||||
while (iter.MoveNext ())
|
||||
if (iter.Current.LocalName != "xml")
|
||||
ctx.AddNamespace (iter.Current.LocalName, iter.Current.Value);
|
||||
}
|
||||
return EvaluateMatch (doc, x);
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type != typeof (XmlNodeList))
|
||||
throw new ArgumentException ("type");
|
||||
return GetOutput ();
|
||||
}
|
||||
|
||||
private XmlDsigNodeList EvaluateMatch (XmlNode n, string xpath)
|
||||
{
|
||||
ArrayList al = new ArrayList ();
|
||||
// Strictly to say, document node is explicitly
|
||||
// excluded by W3C spec (context node is initialized
|
||||
// to the document root and XPath expression is
|
||||
// "//. | //@* | //namespace::*)
|
||||
XPathNavigator nav = n.CreateNavigator ();
|
||||
XPathExpression exp = nav.Compile (xpath);
|
||||
exp.SetContext (ctx);
|
||||
EvaluateMatch (n, exp, al);
|
||||
return new XmlDsigNodeList (al);
|
||||
}
|
||||
|
||||
private void EvaluateMatch (XmlNode n, XPathExpression exp, ArrayList al)
|
||||
{
|
||||
if (NodeMatches (n, exp))
|
||||
al.Add (n);
|
||||
if (n.Attributes != null)
|
||||
for (int i = 0; i < n.Attributes.Count; i++)
|
||||
if (NodeMatches (n.Attributes [i], exp))
|
||||
al.Add (n.Attributes [i]);
|
||||
for (int i = 0; i < n.ChildNodes.Count; i++)
|
||||
EvaluateMatch (n.ChildNodes [i], exp, al);
|
||||
}
|
||||
|
||||
private bool NodeMatches (XmlNode n, XPathExpression exp)
|
||||
{
|
||||
// This looks waste of memory since it creates
|
||||
// XPathNavigator every time, but even if we use
|
||||
// XPathNodeIterator.Current, it also clones every time.
|
||||
object ret = n.CreateNavigator ().Evaluate (exp);
|
||||
if (ret is bool)
|
||||
return (bool) ret;
|
||||
if (ret is double) {
|
||||
double d = (double) ret;
|
||||
return !(d == 0.0 || Double.IsNaN (d));
|
||||
}
|
||||
if (ret is string)
|
||||
return ((string) ret).Length > 0;
|
||||
if (ret is XPathNodeIterator) {
|
||||
XPathNodeIterator retiter = (XPathNodeIterator) ret;
|
||||
return retiter.Count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
if (nodeList == null)
|
||||
throw new CryptographicException ("nodeList");
|
||||
xpath = nodeList;
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
// possible input: Stream, XmlDocument, and XmlNodeList
|
||||
if (obj is Stream) {
|
||||
doc = new XmlDocument ();
|
||||
doc.PreserveWhitespace = true;
|
||||
doc.XmlResolver = GetResolver ();
|
||||
doc.Load (new XmlSignatureStreamReader (
|
||||
new StreamReader ((Stream) obj)));
|
||||
}
|
||||
else if (obj is XmlDocument) {
|
||||
doc = (obj as XmlDocument);
|
||||
}
|
||||
else if (obj is XmlNodeList) {
|
||||
doc = new XmlDocument ();
|
||||
doc.XmlResolver = GetResolver ();
|
||||
foreach (XmlNode xn in (obj as XmlNodeList)) {
|
||||
XmlNode importedNode = doc.ImportNode (xn, true);
|
||||
doc.AppendChild (importedNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Internal classes to support XPath extension function here()
|
||||
|
||||
internal class XmlDsigXPathContext : XsltContext
|
||||
{
|
||||
XmlDsigXPathFunctionHere here;
|
||||
public XmlDsigXPathContext (XmlNode node)
|
||||
{
|
||||
here = new XmlDsigXPathFunctionHere (node);
|
||||
}
|
||||
|
||||
public override IXsltContextFunction ResolveFunction (
|
||||
string prefix, string name, XPathResultType [] argType)
|
||||
{
|
||||
// Here MS.NET incorrectly allows arbitrary
|
||||
// name e.g. "heretic()".
|
||||
if (name == "here" &&
|
||||
prefix == String.Empty &&
|
||||
argType.Length == 0)
|
||||
return here;
|
||||
else
|
||||
return null; // ????
|
||||
}
|
||||
|
||||
public override bool Whitespace {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool PreserveWhitespace (XPathNavigator node)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int CompareDocument (string s1, string s2)
|
||||
{
|
||||
return String.Compare (s1, s2);
|
||||
}
|
||||
|
||||
public override IXsltContextVariable ResolveVariable (string prefix, string name)
|
||||
{
|
||||
throw new InvalidOperationException ();
|
||||
}
|
||||
}
|
||||
|
||||
internal class XmlDsigXPathFunctionHere : IXsltContextFunction
|
||||
{
|
||||
// Static
|
||||
|
||||
static XPathResultType [] types;
|
||||
static XmlDsigXPathFunctionHere ()
|
||||
{
|
||||
types = new XPathResultType [0];
|
||||
}
|
||||
|
||||
// Instance
|
||||
|
||||
XPathNodeIterator xpathNode;
|
||||
|
||||
public XmlDsigXPathFunctionHere (XmlNode node)
|
||||
{
|
||||
xpathNode = node.CreateNavigator ().Select (".");
|
||||
}
|
||||
|
||||
public XPathResultType [] ArgTypes {
|
||||
get { return types; }
|
||||
}
|
||||
|
||||
public int Maxargs { get { return 0; } }
|
||||
|
||||
public int Minargs { get { return 0; } }
|
||||
|
||||
public XPathResultType ReturnType {
|
||||
get { return XPathResultType.NodeSet; }
|
||||
}
|
||||
|
||||
public object Invoke (XsltContext ctx, object [] args, XPathNavigator docContext)
|
||||
{
|
||||
if (args.Length != 0)
|
||||
throw new ArgumentException ("Not allowed arguments for function here().", "args");
|
||||
|
||||
return xpathNode.Clone ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
//
|
||||
// XmlDsigEnvelopedSignatureTransform.cs -
|
||||
// Enveloped Signature Transform implementation for XML Signature
|
||||
// http://www.w3.org/TR/1999/REC-xslt-19991116
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
// Atsushi Enomoto (atsushi@ximian.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// (C) 2004 Novell Inc.
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Xsl;
|
||||
|
||||
namespace System.Security.Cryptography.Xml
|
||||
{
|
||||
|
||||
public class XmlDsigXsltTransform : Transform
|
||||
{
|
||||
|
||||
private Type [] input;
|
||||
private Type [] output;
|
||||
private bool comments;
|
||||
private XmlNodeList xnl;
|
||||
private XmlDocument inputDoc;
|
||||
|
||||
public XmlDsigXsltTransform () : this (false)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlDsigXsltTransform (bool includeComments)
|
||||
{
|
||||
comments = includeComments;
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlDsigXsltTransform;
|
||||
}
|
||||
|
||||
public override Type [] InputTypes {
|
||||
get {
|
||||
if (input == null) {
|
||||
input = new Type [3];
|
||||
input [0] = typeof (System.IO.Stream);
|
||||
input [1] = typeof (System.Xml.XmlDocument);
|
||||
input [2] = typeof (System.Xml.XmlNodeList);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type [] OutputTypes {
|
||||
get {
|
||||
if (output == null) {
|
||||
output = new Type [1];
|
||||
output [0] = typeof (System.IO.Stream);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
return xnl;
|
||||
}
|
||||
|
||||
public override object GetOutput ()
|
||||
{
|
||||
if (xnl == null)
|
||||
throw new ArgumentNullException ("LoadInnerXml before transformation.");
|
||||
|
||||
XmlResolver resolver = GetResolver ();
|
||||
|
||||
XslTransform xsl = new XslTransform ();
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
doc.XmlResolver = resolver;
|
||||
foreach (XmlNode n in xnl)
|
||||
doc.AppendChild (doc.ImportNode (n, true));
|
||||
xsl.Load (doc, resolver);
|
||||
|
||||
if (inputDoc == null)
|
||||
throw new ArgumentNullException ("LoadInput before transformation.");
|
||||
|
||||
MemoryStream stream = new MemoryStream ();
|
||||
// only possible output: Stream
|
||||
xsl.XmlResolver = resolver;
|
||||
xsl.Transform (inputDoc, null, stream);
|
||||
|
||||
stream.Seek (0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type != typeof (Stream))
|
||||
throw new ArgumentException ("type");
|
||||
return GetOutput ();
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
if (nodeList == null)
|
||||
throw new CryptographicException ("nodeList");
|
||||
xnl = nodeList;
|
||||
}
|
||||
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
// possible input: Stream, XmlDocument, and XmlNodeList
|
||||
Stream s = (obj as Stream);
|
||||
if (s != null) {
|
||||
inputDoc = new XmlDocument ();
|
||||
inputDoc.XmlResolver = GetResolver ();
|
||||
// inputDoc.Load (obj as Stream);
|
||||
inputDoc.Load (new XmlSignatureStreamReader (new StreamReader (s)));
|
||||
return;
|
||||
}
|
||||
|
||||
XmlDocument xd = (obj as XmlDocument);
|
||||
if (xd != null) {
|
||||
inputDoc = xd;
|
||||
return;
|
||||
}
|
||||
|
||||
XmlNodeList nl = (obj as XmlNodeList);
|
||||
if (nl != null) {
|
||||
inputDoc = new XmlDocument ();
|
||||
inputDoc.XmlResolver = GetResolver ();
|
||||
for (int i = 0; i < nl.Count; i++)
|
||||
inputDoc.AppendChild (inputDoc.ImportNode (nl [i], true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
//
|
||||
// System.Security.Cryptography.Xml.XmlLicenseTransform class
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
// Copyright (C) 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
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class XmlLicenseTransform : Transform {
|
||||
|
||||
private IRelDecryptor _decryptor;
|
||||
private Type[] inputTypes;
|
||||
private Type[] outputTypes;
|
||||
|
||||
public XmlLicenseTransform ()
|
||||
{
|
||||
Algorithm = XmlSignature.AlgorithmNamespaces.XmlLicenseTransform;
|
||||
}
|
||||
|
||||
public IRelDecryptor Decryptor {
|
||||
get { return _decryptor; }
|
||||
set { _decryptor = value; }
|
||||
}
|
||||
|
||||
public override Type[] InputTypes {
|
||||
get {
|
||||
if (inputTypes == null)
|
||||
inputTypes = new Type [1] { typeof (XmlDocument) };
|
||||
|
||||
return inputTypes;
|
||||
}
|
||||
}
|
||||
|
||||
public override Type[] OutputTypes {
|
||||
get {
|
||||
if (outputTypes == null)
|
||||
outputTypes = new Type [1] {typeof (XmlDocument)};
|
||||
|
||||
return outputTypes;
|
||||
}
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
protected override XmlNodeList GetInnerXml ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public override object GetOutput ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override object GetOutput (Type type)
|
||||
{
|
||||
if (type != typeof (XmlDocument))
|
||||
throw new ArgumentException ("type");
|
||||
return GetOutput ();
|
||||
}
|
||||
|
||||
public override void LoadInnerXml (XmlNodeList nodeList)
|
||||
{
|
||||
// documented as not supported
|
||||
}
|
||||
|
||||
[MonoTODO]
|
||||
public override void LoadInput (object obj)
|
||||
{
|
||||
if (_decryptor == null)
|
||||
throw new CryptographicException (Locale.GetText ("missing decryptor"));
|
||||
// TODO: check for <issuer> element
|
||||
// TODO: check for <license> element
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,19 +87,6 @@ namespace System.Security.Cryptography.Xml {
|
||||
public AttributeNames () {}
|
||||
}
|
||||
|
||||
public class AlgorithmNamespaces {
|
||||
public const string XmlDsigBase64Transform = "http://www.w3.org/2000/09/xmldsig#base64";
|
||||
public const string XmlDsigC14NTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
|
||||
public const string XmlDsigC14NWithCommentsTransform = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
|
||||
public const string XmlDsigEnvelopedSignatureTransform = "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
|
||||
public const string XmlDsigXPathTransform = "http://www.w3.org/TR/1999/REC-xpath-19991116";
|
||||
public const string XmlDsigXsltTransform = "http://www.w3.org/TR/1999/REC-xslt-19991116";
|
||||
public const string XmlDsigExcC14NTransform = "http://www.w3.org/2001/10/xml-exc-c14n#";
|
||||
public const string XmlDsigExcC14NWithCommentsTransform = "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
|
||||
public const string XmlDecryptionTransform = "http://www.w3.org/2002/07/decrypt#XML";
|
||||
public const string XmlLicenseTransform = "urn:mpeg:mpeg21:2003:01-REL-R-NS:licenseTransform";
|
||||
}
|
||||
|
||||
public class Uri {
|
||||
public const string Manifest = "http://www.w3.org/2000/09/xmldsig#Manifest";
|
||||
}
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
//
|
||||
// XmlSignatureStreamReader.cs: Wrap TextReader and eliminate \r
|
||||
//
|
||||
// Author:
|
||||
// Atsushi Enomoto (atsushi@ximian.com)
|
||||
//
|
||||
// (C) 2005 Novell Inc.
|
||||
//
|
||||
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
//
|
||||
// Use it to distinguish 
 and \r. \r is removed, while 
 is not.
|
||||
//
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Security.Cryptography.Xml
|
||||
{
|
||||
internal class XmlSignatureStreamReader : TextReader
|
||||
{
|
||||
TextReader source;
|
||||
int cache = int.MinValue;
|
||||
|
||||
public XmlSignatureStreamReader (TextReader input)
|
||||
{
|
||||
source =input;
|
||||
}
|
||||
|
||||
public override void Close ()
|
||||
{
|
||||
source.Close ();
|
||||
}
|
||||
|
||||
public override int Peek ()
|
||||
{
|
||||
// If source TextReader does not support Peek(),
|
||||
// it does not support too. Or it just returns EOF.
|
||||
if (source.Peek () == -1)
|
||||
return -1;
|
||||
|
||||
if (cache != int.MinValue)
|
||||
return cache;
|
||||
cache = source.Read ();
|
||||
if (cache != '\r')
|
||||
return cache;
|
||||
// cache must be '\r' here.
|
||||
if (source.Peek () != '\n')
|
||||
return '\r';
|
||||
// Now Peek() returns '\n', so clear cache.
|
||||
cache = int.MinValue;
|
||||
return '\n';
|
||||
}
|
||||
|
||||
public override int Read ()
|
||||
{
|
||||
if (cache != int.MinValue) {
|
||||
int ret = cache;
|
||||
cache = int.MinValue;
|
||||
return ret;
|
||||
}
|
||||
int i = source.Read ();
|
||||
if (i != '\r')
|
||||
return i;
|
||||
// read one more char (after '\r')
|
||||
cache = source.Read ();
|
||||
if (cache != '\n')
|
||||
return '\r';
|
||||
cache = int.MinValue;
|
||||
return '\n';
|
||||
}
|
||||
|
||||
public override int ReadBlock (
|
||||
[In, Out] char [] buffer, int index, int count)
|
||||
{
|
||||
char [] tmp = new char [count];
|
||||
source.ReadBlock (tmp, 0, count);
|
||||
int j = index;
|
||||
for (int i = 0; i < count; j++) {
|
||||
if (tmp [i] == '\r') {
|
||||
if (++i < tmp.Length && tmp [i] == '\n')
|
||||
buffer [j] = tmp [i++];
|
||||
else
|
||||
buffer [j] = '\r';
|
||||
}
|
||||
else
|
||||
buffer [j] = tmp [i];
|
||||
}
|
||||
while (j < count) {
|
||||
int d = Read ();
|
||||
if (d < 0)
|
||||
break;
|
||||
buffer [j++] = (char) d;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
// I have no idea what to do here, but I don't think it
|
||||
// makes sense.
|
||||
public override string ReadLine ()
|
||||
{
|
||||
return source.ReadLine ();
|
||||
}
|
||||
|
||||
public override string ReadToEnd ()
|
||||
{
|
||||
return source.ReadToEnd ().Replace ("\r\n", "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user