2 // NetscapeCertTypeExtension.cs: Handles Netscape CertType extensions.
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2004 Novell (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Globalization
;
36 using Mono
.Security
.X509
;
38 namespace Mono
.Security
.X509
.Extensions
{
41 // a. Netscape Certificate Extensions Navigator 3.0 Version
42 // http://wp.netscape.com/eng/security/cert-exts.html
43 // b. Netscape Certificate Extensions Communicator 4.0 Version
44 // http://wp.netscape.com/eng/security/comm4-cert-exts.html
45 // c. 2.16.840.1.113730.1.1 - Netscape certificate type
46 // http://www.alvestrand.no/objectid/2.16.840.1.113730.1.1.html
53 class NetscapeCertTypeExtension
: X509Extension
{
56 * bit-0 SSL client - this cert is certified for SSL client authentication use
57 * bit-1 SSL server - this cert is certified for SSL server authentication use
58 * bit-2 S/MIME - this cert is certified for use by clients(New in PR3)
59 * bit-3 Object Signing - this cert is certified for signing objects such as Java applets and plugins(New in PR3)
60 * bit-4 Reserved - this bit is reserved for future use
61 * bit-5 SSL CA - this cert is certified for issuing certs for SSL use
62 * bit-6 S/MIME CA - this cert is certified for issuing certs for S/MIME use(New in PR3)
63 * bit-7 Object Signing CA - this cert is certified for issuing certs for Object Signing(New in PR3)
66 // note: because nothing is simple in ASN.1 bits are reversed
68 public enum CertTypes
{
75 ObjectSigningCA
= 0x01
80 public NetscapeCertTypeExtension () : base ()
82 extnOid
= "2.16.840.1.113730.1.1";
85 public NetscapeCertTypeExtension (ASN1 asn1
) : base (asn1
)
89 public NetscapeCertTypeExtension (X509Extension extension
) : base (extension
)
93 protected override void Decode ()
95 ASN1 bitString
= new ASN1 (extnValue
.Value
);
96 if (bitString
.Tag
!= 0x03)
97 throw new ArgumentException ("Invalid NetscapeCertType extension");
98 int i
= 1; // byte zero has the number of unused bits (ASN1's BITSTRING)
99 while (i
< bitString
.Value
.Length
)
100 ctbits
= (ctbits
<< 8) + bitString
.Value
[i
++];
103 public override string Name
{
104 get { return "NetscapeCertType"; }
107 /* public CertType Type {
108 get { return ctbits; }
109 set { ctbits = value; }
112 public bool Support (CertTypes usage
)
114 int x
= Convert
.ToInt32 (usage
, CultureInfo
.InvariantCulture
);
115 return ((x
& ctbits
) == x
);
118 public override string ToString ()
120 const string separator
= " , ";
121 StringBuilder sb
= new StringBuilder ();
122 if (Support (CertTypes
.SslClient
))
123 sb
.Append ("SSL Client Authentication");
124 if (Support (CertTypes
.SslServer
)) {
126 sb
.Append (separator
);
127 sb
.Append ("SSL Server Authentication");
129 if (Support (CertTypes
.Smime
)) {
131 sb
.Append (separator
);
134 if (Support (CertTypes
.ObjectSigning
)) {
136 sb
.Append (separator
);
137 sb
.Append ("Object Signing");
139 if (Support (CertTypes
.SslCA
)) {
141 sb
.Append (separator
);
142 sb
.Append ("SSL CA");
144 if (Support (CertTypes
.SmimeCA
)) {
146 sb
.Append (separator
);
147 sb
.Append ("SMIME CA");
149 if (Support (CertTypes
.ObjectSigningCA
)) {
151 sb
.Append (separator
);
152 sb
.Append ("Object Signing CA");
155 sb
.Append (ctbits
.ToString ("X2", CultureInfo
.InvariantCulture
));
157 sb
.Append (Environment
.NewLine
);
158 return sb
.ToString ();