blob: 8f6a35143492636075e2535f111b1f7d2414fbde (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
//
// CertificatePoliciesExtension.cs: Handles X.509 CertificatePolicies extensions.
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2004 Novell (http://www.novell.com)
//
using System;
using System.Collections;
using System.Text;
using Mono.Security;
using Mono.Security.X509;
namespace Mono.Security.X509.Extensions {
/*
* id-ce-certificatePolicies OBJECT IDENTIFIER ::= { id-ce 32 }
*
* anyPolicy OBJECT IDENTIFIER ::= { id-ce-certificate-policies 0 }
*
* certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
*
* PolicyInformation ::= SEQUENCE {
* policyIdentifier CertPolicyId,
* policyQualifiers SEQUENCE SIZE (1..MAX) OF PolicyQualifierInfo OPTIONAL
* }
*
* CertPolicyId ::= OBJECT IDENTIFIER
*
* PolicyQualifierInfo ::= SEQUENCE {
* policyQualifierId PolicyQualifierId,
* qualifier ANY DEFINED BY policyQualifierId
* }
*
* -- policyQualifierIds for Internet policy qualifiers
* id-qt OBJECT IDENTIFIER ::= { id-pkix 2 }
* id-qt-cps OBJECT IDENTIFIER ::= { id-qt 1 }
* id-qt-unotice OBJECT IDENTIFIER ::= { id-qt 2 }
*
* PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
*
* Qualifier ::= CHOICE {
* cPSuri CPSuri,
* userNotice UserNotice
* }
*
* CPSuri ::= IA5String
*
* UserNotice ::= SEQUENCE {
* noticeRef NoticeReference OPTIONAL,
* explicitText DisplayText OPTIONAL
* }
*
* NoticeReference ::= SEQUENCE {
* organization DisplayText,
* noticeNumbers SEQUENCE OF INTEGER
* }
*
* DisplayText ::= CHOICE {
* ia5String IA5String (SIZE (1..200)),
* visibleString VisibleString (SIZE (1..200)),
* bmpString BMPString (SIZE (1..200)),
* utf8String UTF8String (SIZE (1..200))
* }
*/
// note: partial implementation (only policyIdentifier OID are supported)
public class CertificatePoliciesExtension : X509Extension {
private Hashtable policies;
public CertificatePoliciesExtension () : base ()
{
extnOid = "2.5.29.32";
policies = new Hashtable ();
}
public CertificatePoliciesExtension (ASN1 asn1) : base (asn1)
{
}
public CertificatePoliciesExtension (X509Extension extension) : base (extension)
{
}
protected override void Decode ()
{
policies = new Hashtable ();
ASN1 sequence = new ASN1 (extnValue.Value);
if (sequence.Tag != 0x30)
throw new ArgumentException ("Invalid CertificatePolicies extension");
// for every policy OID
for (int i=0; i < sequence.Count; i++) {
policies.Add (ASN1Convert.ToOid (sequence [i][0]), null);
}
}
public override string Name {
get { return "Certificate Policies"; }
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
int n = 1;
foreach (DictionaryEntry policy in policies) {
sb.Append ("[");
sb.Append (n++);
sb.Append ("]Certificate Policy:");
sb.Append (Environment.NewLine);
sb.Append ("\tPolicyIdentifier=");
sb.Append ((string)policy.Key);
sb.Append (Environment.NewLine);
}
return sb.ToString ();
}
}
}
|