**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / CRLDistributionPointsExtension.cs
blob7ebaf2190d13eff2f3c8dc54ab01fe2f41ada829
1 //
2 // CRLDistributionPointsExtension.cs: Handles X.509 CRLDistributionPoints extensions.
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2004 Novell (http://www.novell.com)
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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.
31 using System;
32 using System.Collections;
33 using System.Text;
35 using Mono.Security;
36 using Mono.Security.X509;
38 namespace Mono.Security.X509.Extensions {
40 // References:
41 // a. Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile
42 // http://www.ietf.org/rfc/rfc3280.txt
43 // b. 2.5.29.31 - CRL Distribution Points
44 // http://www.alvestrand.no/objectid/2.5.29.31.html
47 * id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 }
49 * CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint
51 * DistributionPoint ::= SEQUENCE {
52 * distributionPoint [0] DistributionPointName OPTIONAL,
53 * reasons [1] ReasonFlags OPTIONAL,
54 * cRLIssuer [2] GeneralNames OPTIONAL
55 * }
57 * DistributionPointName ::= CHOICE {
58 * fullName [0] GeneralNames,
59 * nameRelativeToCRLIssuer [1] RelativeDistinguishedName
60 * }
62 * ReasonFlags ::= BIT STRING {
63 * unused (0),
64 * keyCompromise (1),
65 * cACompromise (2),
66 * affiliationChanged (3),
67 * superseded (4),
68 * cessationOfOperation (5),
69 * certificateHold (6),
70 * privilegeWithdrawn (7),
71 * aACompromise (8) }
74 public class CRLDistributionPointsExtension : X509Extension {
76 internal class DP {
77 public string DistributionPoint;
78 public ReasonFlags Reasons;
79 public string CRLIssuer;
81 public DP (string dp, ReasonFlags reasons, string issuer)
83 DistributionPoint = dp;
84 Reasons = reasons;
85 CRLIssuer = issuer;
89 [Flags]
90 public enum ReasonFlags {
91 Unused = 0,
92 KeyCompromise = 1,
93 CACompromise = 2,
94 AffiliationChanged = 3,
95 Superseded = 4,
96 CessationOfOperation = 5,
97 CertificateHold = 6,
98 PrivilegeWithdrawn = 7,
99 AACompromise = 8
102 private ArrayList dps;
104 public CRLDistributionPointsExtension () : base ()
106 extnOid = "2.5.29.31";
107 dps = new ArrayList ();
110 public CRLDistributionPointsExtension (ASN1 asn1) : base (asn1) {}
112 public CRLDistributionPointsExtension (X509Extension extension) : base (extension) {}
114 protected override void Decode ()
116 dps = new ArrayList ();
117 ASN1 sequence = new ASN1 (extnValue.Value);
118 if (sequence.Tag != 0x30)
119 throw new ArgumentException ("Invalid CRLDistributionPoints extension");
120 // for every distribution point
121 for (int i=0; i < sequence.Count; i++) {
122 dps.Add (null);
126 public override string Name {
127 get { return "CRL Distribution Points"; }
130 public override string ToString ()
132 StringBuilder sb = new StringBuilder ();
133 foreach (DP dp in dps) {
134 sb.Append ("[");
135 sb.Append (dp.Reasons);
136 sb.Append ("]CRL Distribution Point");
137 sb.Append (Environment.NewLine);
138 sb.Append ("\tDistribution Point Name:");
139 sb.Append (dp.DistributionPoint);
140 sb.Append (Environment.NewLine);
141 sb.Append ("\t\tFull Name:");
142 sb.Append (Environment.NewLine);
143 sb.Append ("\t\t\tDirectory Address:");
144 sb.Append (dp.CRLIssuer);
145 sb.Append (Environment.NewLine);
147 return sb.ToString ();