update readme (#21797)
[mono-project.git] / mcs / class / Mono.Security / Mono.Security.X509.Extensions / CRLDistributionPointsExtension.cs
blob04a7bd1fcd3b6a2bd57b2dc2a16114236021f460
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.Generic;
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 public class DistributionPoint {
77 public string Name { get; private set; }
78 public ReasonFlags Reasons { get; private set; }
79 public string CRLIssuer { get; private set; }
81 public DistributionPoint (string dp, ReasonFlags reasons, string issuer)
83 Name = dp;
84 Reasons = reasons;
85 CRLIssuer = issuer;
88 public DistributionPoint (ASN1 dp)
90 for (int i = 0; i < dp.Count; i++) {
91 ASN1 el = dp[i];
92 switch (el.Tag) {
93 case 0xA0: // DistributionPointName OPTIONAL
94 for (int j = 0; j < el.Count; j++) {
95 ASN1 dpn = el [j];
96 if (dpn.Tag == 0xA0) {
97 Name = new GeneralNames (dpn).ToString ();
100 break;
101 case 0xA1: // ReasonFlags OPTIONAL
102 break;
103 case 0xA2: // RelativeDistinguishedName
104 break;
110 [Flags]
111 public enum ReasonFlags
113 Unused = 0,
114 KeyCompromise = 1,
115 CACompromise = 2,
116 AffiliationChanged = 3,
117 Superseded = 4,
118 CessationOfOperation = 5,
119 CertificateHold = 6,
120 PrivilegeWithdrawn = 7,
121 AACompromise = 8
124 private List<DistributionPoint> dps;
126 public CRLDistributionPointsExtension () : base ()
128 extnOid = "2.5.29.31";
129 dps = new List<DistributionPoint> ();
132 public CRLDistributionPointsExtension (ASN1 asn1)
133 : base (asn1)
137 public CRLDistributionPointsExtension (X509Extension extension)
138 : base (extension)
142 protected override void Decode ()
144 dps = new List<DistributionPoint> ();
145 ASN1 sequence = new ASN1 (extnValue.Value);
146 if (sequence.Tag != 0x30)
147 throw new ArgumentException ("Invalid CRLDistributionPoints extension");
148 // for every distribution point
149 for (int i=0; i < sequence.Count; i++) {
150 dps.Add (new DistributionPoint (sequence [i]));
154 public override string Name {
155 get { return "CRL Distribution Points"; }
158 public IEnumerable<DistributionPoint> DistributionPoints {
159 get { return dps; }
162 public override string ToString ()
164 StringBuilder sb = new StringBuilder ();
165 int i = 1;
166 foreach (DistributionPoint dp in dps) {
167 sb.Append ("[");
168 sb.Append (i++);
169 sb.Append ("]CRL Distribution Point");
170 sb.Append (Environment.NewLine);
171 sb.Append ("\tDistribution Point Name:");
172 sb.Append ("\t\tFull Name:");
173 sb.Append (Environment.NewLine);
174 sb.Append ("\t\t\t");
175 sb.Append (dp.Name);
176 sb.Append (Environment.NewLine);
178 return sb.ToString ();