2 // XmlSignature.cs: Handles Xml Signature
5 // Sebastien Pouliot (spouliot@motus.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
7 // Tim Coleman (tim@timcoleman.com)
9 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
10 // Copyright (C) Tim Coleman, 2004
11 // (C) 2004 Novell Inc.
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System
.Collections
;
39 namespace System
.Security
.Cryptography
.Xml
{
41 // following the design of WSE
42 internal class XmlSignature
{
44 public class ElementNames
{
46 public const string CanonicalizationMethod
= "CanonicalizationMethod";
47 public const string DigestMethod
= "DigestMethod";
48 public const string DigestValue
= "DigestValue";
49 public const string DSAKeyValue
= "DSAKeyValue";
51 public const string EncryptedKey
= "EncryptedKey";
53 public const string HMACOutputLength
= "HMACOutputLength";
54 public const string KeyInfo
= "KeyInfo";
55 public const string KeyName
= "KeyName";
56 public const string KeyValue
= "KeyValue";
57 public const string Manifest
= "Manifest";
58 public const string Object
= "Object";
59 public const string Reference
= "Reference";
61 // RetrievalMethod vs RetrievalElement -> BUG in MS Framework 1.0
62 public const string RetrievalMethod
= "RetrievalElement";
64 public const string RetrievalMethod
= "RetrievalMethod";
66 public const string RSAKeyValue
= "RSAKeyValue";
67 public const string Signature
= "Signature";
68 public const string SignatureMethod
= "SignatureMethod";
69 public const string SignatureValue
= "SignatureValue";
70 public const string SignedInfo
= "SignedInfo";
71 public const string Transform
= "Transform";
72 public const string Transforms
= "Transforms";
73 public const string X509Data
= "X509Data";
74 public const string X509IssuerSerial
= "X509IssuerSerial";
75 public const string X509IssuerName
= "X509IssuerName";
76 public const string X509SerialNumber
= "X509SerialNumber";
77 public const string X509SKI
= "X509SKI";
78 public const string X509SubjectName
= "X509SubjectName";
79 public const string X509Certificate
= "X509Certificate";
80 public const string X509CRL
= "X509CRL";
82 public ElementNames () {}
85 public class AttributeNames
{
87 public const string Algorithm
= "Algorithm";
88 public const string Encoding
= "Encoding";
89 public const string Id
= "Id";
90 public const string MimeType
= "MimeType";
91 public const string Type
= "Type";
92 public const string URI
= "URI";
94 public AttributeNames () {}
97 public class AlgorithmNamespaces
{
98 public const string XmlDsigBase64Transform
= "http://www.w3.org/2000/09/xmldsig#base64";
99 public const string XmlDsigC14NTransform
= "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
100 public const string XmlDsigC14NWithCommentsTransform
= "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
101 public const string XmlDsigEnvelopedSignatureTransform
= "http://www.w3.org/2000/09/xmldsig#enveloped-signature";
102 public const string XmlDsigXPathTransform
= "http://www.w3.org/TR/1999/REC-xpath-19991116";
103 public const string XmlDsigXsltTransform
= "http://www.w3.org/TR/1999/REC-xslt-19991116";
105 public const string XmlDsigExcC14NTransform
= "http://www.w3.org/2001/10/xml-exc-c14n#";
106 public const string XmlDsigExcC14NWithCommentsTransform
= "http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
107 public const string XmlDecryptionTransform
= "http://www.w3.org/2002/07/decrypt#XML";
112 public const string Manifest
= "http://www.w3.org/2000/09/xmldsig#Manifest";
115 public const string NamespaceURI
= "http://www.w3.org/2000/09/xmldsig#";
116 public const string Prefix
= "ds";
118 public XmlSignature ()
122 public static XmlElement
GetChildElement (XmlElement xel
, string element
, string ns
)
124 for (int i
= 0; i
< xel
.ChildNodes
.Count
; i
++) {
125 XmlNode n
= xel
.ChildNodes
[i
];
126 if (n
.NodeType
== XmlNodeType
.Element
&& n
.LocalName
== element
&& n
.NamespaceURI
== ns
)
127 return n
as XmlElement
;
132 public static string GetAttributeFromElement (XmlElement xel
, string attribute
, string element
)
134 XmlElement el
= GetChildElement (xel
, element
, XmlSignature
.NamespaceURI
);
135 return el
!= null ? el
.GetAttribute (attribute
) : null;
138 public static XmlElement
[] GetChildElements (XmlElement xel
, string element
)
140 ArrayList al
= new ArrayList ();
141 for (int i
= 0; i
< xel
.ChildNodes
.Count
; i
++) {
142 XmlNode n
= xel
.ChildNodes
[i
];
143 if (n
.NodeType
== XmlNodeType
.Element
&& n
.LocalName
== element
&& n
.NamespaceURI
== XmlSignature
.NamespaceURI
)
146 return al
.ToArray (typeof (XmlElement
)) as XmlElement
[];