You've already forked linux-packaging-mono
Imported Upstream version 5.12.0.220
Former-commit-id: c477e03582759447177c6d4bf412cd2355aad476
This commit is contained in:
parent
8bd104cef2
commit
8fc30896db
@@ -1,285 +0,0 @@
|
||||
//
|
||||
// KeyInfoX509Data.cs - KeyInfoX509Data implementation for XML Signature
|
||||
//
|
||||
// Authors:
|
||||
// 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-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.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class KeyInfoX509Data : KeyInfoClause {
|
||||
|
||||
private byte[] x509crl;
|
||||
private ArrayList IssuerSerialList;
|
||||
private ArrayList SubjectKeyIdList;
|
||||
private ArrayList SubjectNameList;
|
||||
private ArrayList X509CertificateList;
|
||||
|
||||
public KeyInfoX509Data ()
|
||||
{
|
||||
}
|
||||
|
||||
public KeyInfoX509Data (byte[] rgbCert)
|
||||
{
|
||||
AddCertificate (new X509Certificate (rgbCert));
|
||||
}
|
||||
|
||||
public KeyInfoX509Data (X509Certificate cert)
|
||||
{
|
||||
AddCertificate (cert);
|
||||
}
|
||||
|
||||
#if SECURITY_DEP
|
||||
public KeyInfoX509Data (X509Certificate cert, X509IncludeOption includeOption)
|
||||
{
|
||||
if (cert == null)
|
||||
throw new ArgumentNullException ("cert");
|
||||
|
||||
switch (includeOption) {
|
||||
case X509IncludeOption.None:
|
||||
case X509IncludeOption.EndCertOnly:
|
||||
AddCertificate (cert);
|
||||
break;
|
||||
case X509IncludeOption.ExcludeRoot:
|
||||
AddCertificatesChainFrom (cert, false);
|
||||
break;
|
||||
case X509IncludeOption.WholeChain:
|
||||
AddCertificatesChainFrom (cert, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// this gets complicated because we must:
|
||||
// 1. build the chain using a X509Certificate2 class;
|
||||
// 2. test for root using the Mono.Security.X509.X509Certificate class;
|
||||
// 3. add the certificates as X509Certificate instances;
|
||||
private void AddCertificatesChainFrom (X509Certificate cert, bool root)
|
||||
{
|
||||
X509Chain chain = new X509Chain ();
|
||||
chain.Build (new X509Certificate2 (cert));
|
||||
foreach (X509ChainElement ce in chain.ChainElements) {
|
||||
byte[] rawdata = ce.Certificate.RawData;
|
||||
if (!root) {
|
||||
// exclude root
|
||||
Mono.Security.X509.X509Certificate mx = new Mono.Security.X509.X509Certificate (rawdata);
|
||||
if (mx.IsSelfSigned)
|
||||
rawdata = null;
|
||||
}
|
||||
|
||||
if (rawdata != null)
|
||||
AddCertificate (new X509Certificate (rawdata));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public ArrayList Certificates {
|
||||
get { return X509CertificateList; }
|
||||
}
|
||||
|
||||
public byte[] CRL {
|
||||
get { return x509crl; }
|
||||
set { x509crl = value; }
|
||||
}
|
||||
|
||||
public ArrayList IssuerSerials {
|
||||
get { return IssuerSerialList; }
|
||||
}
|
||||
|
||||
public ArrayList SubjectKeyIds {
|
||||
get { return SubjectKeyIdList; }
|
||||
}
|
||||
|
||||
public ArrayList SubjectNames {
|
||||
get { return SubjectNameList; }
|
||||
}
|
||||
|
||||
public void AddCertificate (X509Certificate certificate)
|
||||
{
|
||||
if (certificate == null)
|
||||
throw new ArgumentNullException ("certificate");
|
||||
if (X509CertificateList == null)
|
||||
X509CertificateList = new ArrayList ();
|
||||
X509CertificateList.Add (certificate);
|
||||
}
|
||||
|
||||
public void AddIssuerSerial (string issuerName, string serialNumber)
|
||||
{
|
||||
if (issuerName == null)
|
||||
throw new ArgumentException ("issuerName");
|
||||
if (IssuerSerialList == null)
|
||||
IssuerSerialList = new ArrayList ();
|
||||
|
||||
X509IssuerSerial xis = new X509IssuerSerial (issuerName, serialNumber);
|
||||
IssuerSerialList.Add (xis);
|
||||
}
|
||||
|
||||
public void AddSubjectKeyId (byte[] subjectKeyId)
|
||||
{
|
||||
if (SubjectKeyIdList == null)
|
||||
SubjectKeyIdList = new ArrayList ();
|
||||
|
||||
SubjectKeyIdList.Add (subjectKeyId);
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
public void AddSubjectKeyId (string subjectKeyId)
|
||||
{
|
||||
if (SubjectKeyIdList == null)
|
||||
SubjectKeyIdList = new ArrayList ();
|
||||
|
||||
byte[] id = null;
|
||||
if (subjectKeyId != null)
|
||||
id = Convert.FromBase64String (subjectKeyId);
|
||||
SubjectKeyIdList.Add (id);
|
||||
}
|
||||
|
||||
public void AddSubjectName (string subjectName)
|
||||
{
|
||||
if (SubjectNameList == null)
|
||||
SubjectNameList = new ArrayList ();
|
||||
|
||||
SubjectNameList.Add (subjectName);
|
||||
}
|
||||
|
||||
public override XmlElement GetXml ()
|
||||
{
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.X509Data, XmlSignature.NamespaceURI);
|
||||
// FIXME: hack to match MS implementation
|
||||
xel.SetAttribute ("xmlns", XmlSignature.NamespaceURI);
|
||||
// <X509IssuerSerial>
|
||||
if ((IssuerSerialList != null) && (IssuerSerialList.Count > 0)) {
|
||||
foreach (X509IssuerSerial iser in IssuerSerialList) {
|
||||
XmlElement isl = document.CreateElement (XmlSignature.ElementNames.X509IssuerSerial, XmlSignature.NamespaceURI);
|
||||
XmlElement xin = document.CreateElement (XmlSignature.ElementNames.X509IssuerName, XmlSignature.NamespaceURI);
|
||||
xin.InnerText = iser.IssuerName;
|
||||
isl.AppendChild (xin);
|
||||
XmlElement xsn = document.CreateElement (XmlSignature.ElementNames.X509SerialNumber, XmlSignature.NamespaceURI);
|
||||
xsn.InnerText = iser.SerialNumber;
|
||||
isl.AppendChild (xsn);
|
||||
xel.AppendChild (isl);
|
||||
}
|
||||
}
|
||||
// <X509SKI>
|
||||
if ((SubjectKeyIdList != null) && (SubjectKeyIdList.Count > 0)) {
|
||||
foreach (byte[] skid in SubjectKeyIdList) {
|
||||
XmlElement ski = document.CreateElement (XmlSignature.ElementNames.X509SKI, XmlSignature.NamespaceURI);
|
||||
ski.InnerText = Convert.ToBase64String (skid);
|
||||
xel.AppendChild (ski);
|
||||
}
|
||||
}
|
||||
// <X509SubjectName>
|
||||
if ((SubjectNameList != null) && (SubjectNameList.Count > 0)) {
|
||||
foreach (string subject in SubjectNameList) {
|
||||
XmlElement sn = document.CreateElement (XmlSignature.ElementNames.X509SubjectName, XmlSignature.NamespaceURI);
|
||||
sn.InnerText = subject;
|
||||
xel.AppendChild (sn);
|
||||
}
|
||||
}
|
||||
// <X509Certificate>
|
||||
if ((X509CertificateList != null) && (X509CertificateList.Count > 0)) {
|
||||
foreach (X509Certificate x509 in X509CertificateList) {
|
||||
XmlElement cert = document.CreateElement (XmlSignature.ElementNames.X509Certificate, XmlSignature.NamespaceURI);
|
||||
cert.InnerText = Convert.ToBase64String (x509.GetRawCertData ());
|
||||
xel.AppendChild (cert);
|
||||
}
|
||||
}
|
||||
// only one <X509CRL>
|
||||
if (x509crl != null) {
|
||||
XmlElement crl = document.CreateElement (XmlSignature.ElementNames.X509CRL, XmlSignature.NamespaceURI);
|
||||
crl.InnerText = Convert.ToBase64String (x509crl);
|
||||
xel.AppendChild (crl);
|
||||
}
|
||||
return xel;
|
||||
}
|
||||
|
||||
public override void LoadXml (XmlElement element)
|
||||
{
|
||||
if (element == null)
|
||||
throw new ArgumentNullException ("element");
|
||||
|
||||
if (IssuerSerialList != null)
|
||||
IssuerSerialList.Clear ();
|
||||
if (SubjectKeyIdList != null)
|
||||
SubjectKeyIdList.Clear ();
|
||||
if (SubjectNameList != null)
|
||||
SubjectNameList.Clear ();
|
||||
if (X509CertificateList != null)
|
||||
X509CertificateList.Clear ();
|
||||
x509crl = null;
|
||||
|
||||
if ((element.LocalName != XmlSignature.ElementNames.X509Data) || (element.NamespaceURI != XmlSignature.NamespaceURI))
|
||||
throw new CryptographicException ("element");
|
||||
|
||||
XmlElement [] xnl = null;
|
||||
// <X509IssuerSerial>
|
||||
xnl = XmlSignature.GetChildElements (element, XmlSignature.ElementNames.X509IssuerSerial);
|
||||
if (xnl != null) {
|
||||
for (int i=0; i < xnl.Length; i++) {
|
||||
XmlElement xel = (XmlElement) xnl[i];
|
||||
XmlElement issuer = XmlSignature.GetChildElement (xel, XmlSignature.ElementNames.X509IssuerName, XmlSignature.NamespaceURI);
|
||||
XmlElement serial = XmlSignature.GetChildElement (xel, XmlSignature.ElementNames.X509SerialNumber, XmlSignature.NamespaceURI);
|
||||
AddIssuerSerial (issuer.InnerText, serial.InnerText);
|
||||
}
|
||||
}
|
||||
// <X509SKI>
|
||||
xnl = XmlSignature.GetChildElements (element, XmlSignature.ElementNames.X509SKI);
|
||||
if (xnl != null) {
|
||||
for (int i=0; i < xnl.Length; i++) {
|
||||
byte[] skid = Convert.FromBase64String (xnl[i].InnerXml);
|
||||
AddSubjectKeyId (skid);
|
||||
}
|
||||
}
|
||||
// <X509SubjectName>
|
||||
xnl = XmlSignature.GetChildElements (element, XmlSignature.ElementNames.X509SubjectName);
|
||||
if (xnl != null) {
|
||||
for (int i=0; i < xnl.Length; i++) {
|
||||
AddSubjectName (xnl[i].InnerXml);
|
||||
}
|
||||
}
|
||||
// <X509Certificate>
|
||||
xnl = XmlSignature.GetChildElements (element, XmlSignature.ElementNames.X509Certificate);
|
||||
if (xnl != null) {
|
||||
for (int i=0; i < xnl.Length; i++) {
|
||||
byte[] cert = Convert.FromBase64String (xnl[i].InnerXml);
|
||||
AddCertificate (new X509Certificate (cert));
|
||||
}
|
||||
}
|
||||
// only one <X509CRL>
|
||||
XmlElement x509el = XmlSignature.GetChildElement (element, XmlSignature.ElementNames.X509CRL, XmlSignature.NamespaceURI);
|
||||
if (x509el != null) {
|
||||
x509crl = Convert.FromBase64String (x509el.InnerXml);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
//
|
||||
// Manifest.cs - Manifest implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@ximian.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.Collections;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
internal class Manifest {
|
||||
|
||||
private ArrayList references;
|
||||
private string id;
|
||||
private XmlElement element;
|
||||
|
||||
public Manifest ()
|
||||
{
|
||||
references = new ArrayList ();
|
||||
}
|
||||
|
||||
public Manifest (XmlElement xel) : this ()
|
||||
{
|
||||
LoadXml (xel);
|
||||
}
|
||||
|
||||
public string Id {
|
||||
get { return id; }
|
||||
set {
|
||||
element = null;
|
||||
id = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList References {
|
||||
get { return references; }
|
||||
}
|
||||
|
||||
public void AddReference (Reference reference)
|
||||
{
|
||||
references.Add (reference);
|
||||
}
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
if (element != null)
|
||||
return element;
|
||||
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI);
|
||||
if (id != null)
|
||||
xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
|
||||
|
||||
// we add References afterward so we don't end up with extraneous
|
||||
// xmlns="..." in each reference elements.
|
||||
foreach (Reference r in references) {
|
||||
XmlNode xn = r.GetXml ();
|
||||
XmlNode newNode = 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.Manifest) || (value.NamespaceURI != XmlSignature.NamespaceURI))
|
||||
throw new CryptographicException ();
|
||||
|
||||
id = GetAttribute (value, XmlSignature.AttributeNames.Id);
|
||||
|
||||
for (int i = 0; i < value.ChildNodes.Count; i++) {
|
||||
XmlNode n = value.ChildNodes [i];
|
||||
if (n.NodeType == XmlNodeType.Element &&
|
||||
n.LocalName == XmlSignature.ElementNames.Reference &&
|
||||
n.NamespaceURI == XmlSignature.NamespaceURI) {
|
||||
Reference r = new Reference ();
|
||||
r.LoadXml ((XmlElement) n);
|
||||
AddReference (r);
|
||||
}
|
||||
}
|
||||
element = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
//
|
||||
// Signature.cs - Signature implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.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.Security.Cryptography;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class Signature {
|
||||
static XmlNamespaceManager dsigNsmgr;
|
||||
|
||||
static Signature ()
|
||||
{
|
||||
dsigNsmgr = new XmlNamespaceManager (new NameTable ());
|
||||
dsigNsmgr.AddNamespace ("xd", XmlSignature.NamespaceURI);
|
||||
}
|
||||
|
||||
private ArrayList list;
|
||||
private SignedInfo info;
|
||||
private KeyInfo key;
|
||||
private string id;
|
||||
private byte[] signature;
|
||||
private XmlElement element;
|
||||
|
||||
public Signature ()
|
||||
{
|
||||
list = new ArrayList ();
|
||||
}
|
||||
|
||||
public string Id {
|
||||
get { return id; }
|
||||
set {
|
||||
element = null;
|
||||
id = value;
|
||||
}
|
||||
}
|
||||
|
||||
public KeyInfo KeyInfo {
|
||||
get { return key; }
|
||||
set {
|
||||
element = null;
|
||||
key = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IList ObjectList {
|
||||
get { return list; }
|
||||
set { list = ArrayList.Adapter (value); }
|
||||
}
|
||||
|
||||
public byte[] SignatureValue {
|
||||
get { return signature; }
|
||||
set {
|
||||
element = null;
|
||||
signature = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SignedInfo SignedInfo {
|
||||
get { return info; }
|
||||
set {
|
||||
element = null;
|
||||
info = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddObject (DataObject dataObject)
|
||||
{
|
||||
list.Add (dataObject);
|
||||
}
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
return GetXml (null);
|
||||
}
|
||||
|
||||
internal XmlElement GetXml (XmlDocument document)
|
||||
{
|
||||
if (element != null)
|
||||
return element;
|
||||
|
||||
if (info == null)
|
||||
throw new CryptographicException ("SignedInfo");
|
||||
if (signature == null)
|
||||
throw new CryptographicException ("SignatureValue");
|
||||
|
||||
if (document == null)
|
||||
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);
|
||||
|
||||
// LAMESPEC: This library is totally useless against eXtensibly Marked-up document.
|
||||
int i = NextElementPos (value.ChildNodes, 0, XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI, true);
|
||||
XmlElement sinfo = (XmlElement) value.ChildNodes [i];
|
||||
info = new SignedInfo ();
|
||||
info.LoadXml (sinfo);
|
||||
|
||||
i = NextElementPos (value.ChildNodes, ++i, XmlSignature.ElementNames.SignatureValue, XmlSignature.NamespaceURI, true);
|
||||
XmlElement sigValue = (XmlElement) value.ChildNodes [i];
|
||||
signature = Convert.FromBase64String (sigValue.InnerText);
|
||||
|
||||
// signature isn't required: <element ref="ds:KeyInfo" minOccurs="0"/>
|
||||
i = NextElementPos (value.ChildNodes, ++i, XmlSignature.ElementNames.KeyInfo, XmlSignature.NamespaceURI, false);
|
||||
if (i > 0) {
|
||||
XmlElement kinfo = (XmlElement) value.ChildNodes [i];
|
||||
key = new KeyInfo ();
|
||||
key.LoadXml (kinfo);
|
||||
}
|
||||
|
||||
XmlNodeList xnl = value.SelectNodes ("xd:Object", dsigNsmgr);
|
||||
foreach (XmlElement xn in xnl) {
|
||||
DataObject obj = new DataObject ();
|
||||
obj.LoadXml (xn);
|
||||
AddObject (obj);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new CryptographicException ("Malformed element: Signature.");
|
||||
|
||||
// if invalid
|
||||
if (info == null)
|
||||
throw new CryptographicException ("SignedInfo");
|
||||
if (signature == null)
|
||||
throw new CryptographicException ("SignatureValue");
|
||||
}
|
||||
|
||||
private int NextElementPos (XmlNodeList nl, int pos, string name, string ns, bool required)
|
||||
{
|
||||
while (pos < nl.Count) {
|
||||
if (nl [pos].NodeType == XmlNodeType.Element) {
|
||||
if (nl [pos].LocalName != name || nl [pos].NamespaceURI != ns) {
|
||||
if (required)
|
||||
throw new CryptographicException ("Malformed element " + name);
|
||||
else
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
return pos;
|
||||
}
|
||||
else
|
||||
pos++;
|
||||
}
|
||||
if (required)
|
||||
throw new CryptographicException ("Malformed element " + name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
//
|
||||
// SignedInfo.cs - SignedInfo implementation for XML Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot <sebastien@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-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.Runtime.InteropServices;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public class SignedInfo : ICollection, IEnumerable {
|
||||
|
||||
private ArrayList references;
|
||||
private string c14nMethod;
|
||||
private string id;
|
||||
private string signatureMethod;
|
||||
private string signatureLength;
|
||||
private XmlElement element;
|
||||
|
||||
public SignedInfo()
|
||||
{
|
||||
references = new ArrayList ();
|
||||
c14nMethod = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
|
||||
}
|
||||
|
||||
public string CanonicalizationMethod {
|
||||
get { return c14nMethod; }
|
||||
set {
|
||||
c14nMethod = value;
|
||||
element = null;
|
||||
}
|
||||
}
|
||||
|
||||
[ComVisible (false)]
|
||||
[MonoTODO]
|
||||
public Transform CanonicalizationMethodObject {
|
||||
get { throw new NotImplementedException (); }
|
||||
}
|
||||
|
||||
// documented as not supported (and throwing exception)
|
||||
public int Count {
|
||||
get { throw new NotSupportedException (); }
|
||||
}
|
||||
|
||||
public string Id {
|
||||
get { return id; }
|
||||
set {
|
||||
element = null;
|
||||
id = value;
|
||||
}
|
||||
}
|
||||
|
||||
// documented as not supported (and throwing exception)
|
||||
public bool IsReadOnly {
|
||||
get { throw new NotSupportedException (); }
|
||||
}
|
||||
|
||||
// documented as not supported (and throwing exception)
|
||||
public bool IsSynchronized {
|
||||
get { throw new NotSupportedException (); }
|
||||
}
|
||||
|
||||
// Manipulating this array never affects GetXml() when
|
||||
// LoadXml() was used.
|
||||
// (Actually, there is no way to detect modification.)
|
||||
public ArrayList References {
|
||||
get { return references; }
|
||||
}
|
||||
|
||||
public string SignatureLength {
|
||||
get { return signatureLength; }
|
||||
set {
|
||||
element = null;
|
||||
signatureLength = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string SignatureMethod {
|
||||
get { return signatureMethod; }
|
||||
set {
|
||||
element = null;
|
||||
signatureMethod = value;
|
||||
}
|
||||
}
|
||||
|
||||
// documented as not supported (and throwing exception)
|
||||
public object SyncRoot {
|
||||
get { throw new NotSupportedException (); }
|
||||
}
|
||||
|
||||
public void AddReference (Reference reference)
|
||||
{
|
||||
references.Add (reference);
|
||||
}
|
||||
|
||||
// documented as not supported (and throwing exception)
|
||||
public void CopyTo (Array array, int index)
|
||||
{
|
||||
throw new NotSupportedException ();
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator ()
|
||||
{
|
||||
return references.GetEnumerator ();
|
||||
}
|
||||
|
||||
public XmlElement GetXml ()
|
||||
{
|
||||
if (element != null)
|
||||
return element;
|
||||
|
||||
if (signatureMethod == null)
|
||||
throw new CryptographicException ("SignatureMethod");
|
||||
if (references.Count == 0)
|
||||
throw new CryptographicException ("References empty");
|
||||
|
||||
XmlDocument document = new XmlDocument ();
|
||||
XmlElement xel = document.CreateElement (XmlSignature.ElementNames.SignedInfo, XmlSignature.NamespaceURI);
|
||||
if (id != null)
|
||||
xel.SetAttribute (XmlSignature.AttributeNames.Id, id);
|
||||
|
||||
if (c14nMethod != null) {
|
||||
XmlElement c14n = document.CreateElement (XmlSignature.ElementNames.CanonicalizationMethod, XmlSignature.NamespaceURI);
|
||||
c14n.SetAttribute (XmlSignature.AttributeNames.Algorithm, c14nMethod);
|
||||
xel.AppendChild (c14n);
|
||||
}
|
||||
if (signatureMethod != null) {
|
||||
XmlElement sm = document.CreateElement (XmlSignature.ElementNames.SignatureMethod, XmlSignature.NamespaceURI);
|
||||
sm.SetAttribute (XmlSignature.AttributeNames.Algorithm, signatureMethod);
|
||||
if (signatureLength != null) {
|
||||
XmlElement hmac = document.CreateElement (XmlSignature.ElementNames.HMACOutputLength, XmlSignature.NamespaceURI);
|
||||
hmac.InnerText = signatureLength;
|
||||
sm.AppendChild (hmac);
|
||||
}
|
||||
xel.AppendChild (sm);
|
||||
}
|
||||
|
||||
// This check is only done when element is created here.
|
||||
if (references.Count == 0)
|
||||
throw new CryptographicException ("At least one Reference element is required in SignedInfo.");
|
||||
|
||||
// we add References afterward so we don't end up with extraneous
|
||||
// xmlns="..." in each reference elements.
|
||||
foreach (Reference r in references) {
|
||||
XmlNode xn = r.GetXml ();
|
||||
XmlNode newNode = 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.SignedInfo) || (value.NamespaceURI != XmlSignature.NamespaceURI))
|
||||
throw new CryptographicException ();
|
||||
|
||||
id = GetAttribute (value, XmlSignature.AttributeNames.Id);
|
||||
c14nMethod = XmlSignature.GetAttributeFromElement (value, XmlSignature.AttributeNames.Algorithm, XmlSignature.ElementNames.CanonicalizationMethod);
|
||||
|
||||
XmlElement sm = XmlSignature.GetChildElement (value, XmlSignature.ElementNames.SignatureMethod, XmlSignature.NamespaceURI);
|
||||
if (sm != null) {
|
||||
signatureMethod = sm.GetAttribute (XmlSignature.AttributeNames.Algorithm);
|
||||
XmlElement length = XmlSignature.GetChildElement (sm, XmlSignature.ElementNames.HMACOutputLength, XmlSignature.NamespaceURI);
|
||||
if (length != null) {
|
||||
signatureLength = length.InnerText;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < value.ChildNodes.Count; i++) {
|
||||
XmlNode n = value.ChildNodes [i];
|
||||
if (n.NodeType == XmlNodeType.Element &&
|
||||
n.LocalName == XmlSignature.ElementNames.Reference &&
|
||||
n.NamespaceURI == XmlSignature.NamespaceURI) {
|
||||
Reference r = new Reference ();
|
||||
r.LoadXml ((XmlElement) n);
|
||||
AddReference (r);
|
||||
}
|
||||
}
|
||||
element = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// X509IssuerSerial.cs - X509IssuerSerial implementation for XML Encryption
|
||||
//
|
||||
// Author:
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
// Sebastien Pouliot <sebastien@ximian.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.
|
||||
//
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
public
|
||||
struct X509IssuerSerial {
|
||||
|
||||
private string _issuerName;
|
||||
private string _serialNumber;
|
||||
|
||||
internal X509IssuerSerial (string issuer, string serial)
|
||||
{
|
||||
_issuerName = issuer;
|
||||
_serialNumber = serial;
|
||||
}
|
||||
|
||||
public string IssuerName {
|
||||
get { return _issuerName; }
|
||||
set { _issuerName = value; }
|
||||
}
|
||||
|
||||
public string SerialNumber {
|
||||
get { return _serialNumber; }
|
||||
set { _serialNumber = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
//
|
||||
// XmlSignature.cs: Handles Xml Signature
|
||||
//
|
||||
// Author:
|
||||
// Sebastien Pouliot (spouliot@motus.com)
|
||||
// Atsushi Enomoto (atsushi@ximian.com)
|
||||
// Tim Coleman (tim@timcoleman.com)
|
||||
//
|
||||
// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
|
||||
// Copyright (C) Tim Coleman, 2004
|
||||
// (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;
|
||||
using System.Collections;
|
||||
using System.Xml;
|
||||
|
||||
namespace System.Security.Cryptography.Xml {
|
||||
|
||||
// following the design of WSE
|
||||
internal class XmlSignature {
|
||||
|
||||
public class ElementNames {
|
||||
|
||||
public const string CanonicalizationMethod = "CanonicalizationMethod";
|
||||
public const string DigestMethod = "DigestMethod";
|
||||
public const string DigestValue = "DigestValue";
|
||||
public const string DSAKeyValue = "DSAKeyValue";
|
||||
public const string EncryptedKey = "EncryptedKey";
|
||||
public const string HMACOutputLength = "HMACOutputLength";
|
||||
public const string KeyInfo = "KeyInfo";
|
||||
public const string KeyName = "KeyName";
|
||||
public const string KeyValue = "KeyValue";
|
||||
public const string Manifest = "Manifest";
|
||||
public const string Object = "Object";
|
||||
public const string Reference = "Reference";
|
||||
public const string RetrievalMethod = "RetrievalMethod";
|
||||
public const string RSAKeyValue = "RSAKeyValue";
|
||||
public const string Signature = "Signature";
|
||||
public const string SignatureMethod = "SignatureMethod";
|
||||
public const string SignatureValue = "SignatureValue";
|
||||
public const string SignedInfo = "SignedInfo";
|
||||
public const string Transform = "Transform";
|
||||
public const string Transforms = "Transforms";
|
||||
public const string X509Data = "X509Data";
|
||||
public const string X509IssuerSerial = "X509IssuerSerial";
|
||||
public const string X509IssuerName = "X509IssuerName";
|
||||
public const string X509SerialNumber = "X509SerialNumber";
|
||||
public const string X509SKI = "X509SKI";
|
||||
public const string X509SubjectName = "X509SubjectName";
|
||||
public const string X509Certificate = "X509Certificate";
|
||||
public const string X509CRL = "X509CRL";
|
||||
|
||||
public ElementNames () {}
|
||||
}
|
||||
|
||||
public class AttributeNames {
|
||||
|
||||
public const string Algorithm = "Algorithm";
|
||||
public const string Encoding = "Encoding";
|
||||
public const string Id = "Id";
|
||||
public const string MimeType = "MimeType";
|
||||
public const string Type = "Type";
|
||||
public const string URI = "URI";
|
||||
|
||||
public AttributeNames () {}
|
||||
}
|
||||
|
||||
public class Uri {
|
||||
public const string Manifest = "http://www.w3.org/2000/09/xmldsig#Manifest";
|
||||
}
|
||||
|
||||
public const string NamespaceURI = "http://www.w3.org/2000/09/xmldsig#";
|
||||
public const string Prefix = "ds";
|
||||
|
||||
public XmlSignature ()
|
||||
{
|
||||
}
|
||||
|
||||
public static XmlElement GetChildElement (XmlElement xel, string element, string ns)
|
||||
{
|
||||
for (int i = 0; i < xel.ChildNodes.Count; i++) {
|
||||
XmlNode n = xel.ChildNodes [i];
|
||||
if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == ns)
|
||||
return n as XmlElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetAttributeFromElement (XmlElement xel, string attribute, string element)
|
||||
{
|
||||
XmlElement el = GetChildElement (xel, element, XmlSignature.NamespaceURI);
|
||||
return el != null ? el.GetAttribute (attribute) : null;
|
||||
}
|
||||
|
||||
public static XmlElement [] GetChildElements (XmlElement xel, string element)
|
||||
{
|
||||
ArrayList al = new ArrayList ();
|
||||
for (int i = 0; i < xel.ChildNodes.Count; i++) {
|
||||
XmlNode n = xel.ChildNodes [i];
|
||||
if (n.NodeType == XmlNodeType.Element && n.LocalName == element && n.NamespaceURI == XmlSignature.NamespaceURI)
|
||||
al.Add (n);
|
||||
}
|
||||
return al.ToArray (typeof (XmlElement)) as XmlElement [];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user