2 // ExtendedKeyUsageExtension.cs: Handles X.509 ExtendedKeyUsage extensions.
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Collections
;
35 using Mono
.Security
.X509
;
37 namespace Mono
.Security
.X509
.Extensions
{
40 * id-ce-extKeyUsage OBJECT IDENTIFIER ::= { id-ce 37 }
42 * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId
44 * KeyPurposeId ::= OBJECT IDENTIFIER
47 public class ExtendedKeyUsageExtension
: X509Extension
{
49 private ArrayList keyPurpose
;
51 public ExtendedKeyUsageExtension () : base ()
53 extnOid
= "2.5.29.37";
54 keyPurpose
= new ArrayList ();
57 public ExtendedKeyUsageExtension (ASN1 asn1
) : base (asn1
)
61 public ExtendedKeyUsageExtension (X509Extension extension
) : base (extension
)
65 protected override void Decode ()
67 keyPurpose
= new ArrayList ();
68 ASN1 sequence
= new ASN1 (extnValue
.Value
);
69 if (sequence
.Tag
!= 0x30)
70 throw new ArgumentException ("Invalid ExtendedKeyUsage extension");
71 // for every policy OID
72 for (int i
=0; i
< sequence
.Count
; i
++)
73 keyPurpose
.Add (ASN1Convert
.ToOid (sequence
[i
]));
76 protected override void Encode ()
78 ASN1 seq
= new ASN1 (0x30);
79 foreach (string oid
in keyPurpose
) {
80 seq
.Add (ASN1Convert
.FromOid (oid
));
83 extnValue
= new ASN1 (0x04);
87 public ArrayList KeyPurpose
{
88 get { return keyPurpose; }
91 public override string Name
{
92 get { return "Extended Key Usage"; }
95 // serverAuth 1.3.6.1.5.5.7.3.1
96 // clientAuth 1.3.6.1.5.5.7.3.2
97 // codeSigning 1.3.6.1.5.5.7.3.3
98 // emailProtection 1.3.6.1.5.5.7.3.4
99 // timeStamping 1.3.6.1.5.5.7.3.8
100 // OCSPSigning 1.3.6.1.5.5.7.3.9
101 public override string ToString ()
103 StringBuilder sb
= new StringBuilder ();
104 foreach (string s
in keyPurpose
) {
106 case "1.3.6.1.5.5.7.3.1":
107 sb
.Append ("Server Authentication");
109 case "1.3.6.1.5.5.7.3.2":
110 sb
.Append ("Client Authentication");
112 case "1.3.6.1.5.5.7.3.3":
113 sb
.Append ("Code Signing");
115 case "1.3.6.1.5.5.7.3.4":
116 sb
.Append ("Email Protection");
118 case "1.3.6.1.5.5.7.3.8":
119 sb
.Append ("Time Stamping");
121 case "1.3.6.1.5.5.7.3.9":
122 sb
.Append ("OCSP Signing");
125 sb
.Append ("unknown");
128 sb
.AppendFormat (" ({0}){1}", s
, Environment
.NewLine
);
130 return sb
.ToString ();