blob: 4d0c34a75ff69341380a98dcab49dd1807d9b20a [file] [log] [blame]
wbonde91513e2015-06-03 14:52:18 -04001# coding: utf-8
wbondea25fc22015-06-19 15:07:04 -04002
3"""
4ASN.1 type classes for certificate revocation lists (CRL). Exports the
5following items:
6
7 - CertificateList()
8
9Other type classes are defined that help compose the types listed above.
10"""
11
wbonde91513e2015-06-03 14:52:18 -040012from __future__ import unicode_literals
wbonde91513e2015-06-03 14:52:18 -040013
14from .algos import SignedDigestAlgorithm
15from .core import (
16 Boolean,
17 Enumerated,
18 GeneralizedTime,
19 Integer,
20 ObjectIdentifier,
21 OctetBitString,
22 OctetString,
23 Sequence,
24 SequenceOf,
25)
26from .x509 import (
27 AuthorityKeyIdentifier,
28 CRLDistributionPoints,
29 DistributionPointName,
30 GeneralName,
31 GeneralNames,
32 Name,
33 ReasonFlags,
34 Time,
35)
36
37
38
39# The structures in this file are taken from https://tools.ietf.org/html/rfc5280
40
41
42class Version(Integer):
43 _map = {
44 0: 'v1',
45 1: 'v2',
46 2: 'v3',
47 }
48
49
50class IssuingDistributionPoint(Sequence):
51 _fields = [
52 ('distribution_point', DistributionPointName, {'tag_type': 'explicit', 'tag': 0, 'optional': True}),
53 ('only_contains_user_certs', Boolean, {'tag_type': 'implicit', 'tag': 1, 'default': False}),
54 ('only_contains_ca_certs', Boolean, {'tag_type': 'implicit', 'tag': 2, 'default': False}),
55 ('only_some_reasons', ReasonFlags, {'tag_type': 'implicit', 'tag': 3, 'optional': True}),
56 ('indirect_crl', Boolean, {'tag_type': 'implicit', 'tag': 4, 'default': False}),
57 ('only_contains_attribute_certs', Boolean, {'tag_type': 'implicit', 'tag': 5, 'default': False}),
58 ]
59
60
61class AccessMethod(ObjectIdentifier):
62 _map = {
63 '1.3.6.1.5.5.7.48.1': 'ocsp',
64 '1.3.6.1.5.5.7.48.2': 'ca_issuers',
65 }
66
67
68class AccessDescription(Sequence):
69 _fields = [
70 ('access_method', AccessMethod),
71 ('access_location', GeneralName),
72 ]
73
74
75class AuthorityInfoAccessSyntax(SequenceOf):
76 _child_spec = AccessDescription
77
78
79class TBSCertListExtensionId(ObjectIdentifier):
80 _map = {
81 '2.5.29.18': 'issuer_alt_name',
82 '2.5.29.20': 'crl_number',
83 '2.5.29.27': 'delta_crl_indicator',
84 '2.5.29.28': 'issuing_distribution_point',
85 '2.5.29.35': 'authority_key_identifier',
86 '2.5.29.46': 'freshest_crl',
87 '1.3.6.1.5.5.7.1.1': 'authority_information_access',
88 }
89
90
91class TBSCertListExtension(Sequence):
92 _fields = [
93 ('extn_id', TBSCertListExtensionId),
94 ('critical', Boolean, {'default': False}),
95 ('extn_value', OctetString),
96 ]
97
98 _oid_pair = ('extn_id', 'extn_value')
99 _oid_specs = {
100 'issuer_alt_name': GeneralNames,
101 'crl_number': Integer,
102 'delta_crl_indicator': Integer,
103 'issuing_distribution_point': IssuingDistributionPoint,
104 'authority_key_identifier': AuthorityKeyIdentifier,
105 'freshest_crl': CRLDistributionPoints,
106 'authority_information_access': AuthorityInfoAccessSyntax,
107 }
108
109
110class TBSCertListExtensions(SequenceOf):
111 _child_spec = TBSCertListExtension
112
113
114class CRLReason(Enumerated):
115 _map = {
116 0: 'unspecified',
117 1: 'key_compromise',
118 2: 'ca_compromise',
119 3: 'affiliation_changed',
120 4: 'superseded',
121 5: 'cessation_of_operation',
122 6: 'certificate_hold',
123 8: 'remove_from_crl',
124 9: 'privilege_withdrawn',
125 10: 'aa_compromise',
126 }
127
128
129class CRLEntryExtensionId(ObjectIdentifier):
130 _map = {
131 '2.5.29.21': 'crl_reason',
132 '2.5.29.24': 'invalidity_date',
133 '2.5.29.29': 'certificate_issuer',
134 }
135
136
137class CRLEntryExtension(Sequence):
138 _fields = [
139 ('extn_id', CRLEntryExtensionId),
140 ('critical', Boolean, {'default': False}),
141 ('extn_value', OctetString),
142 ]
143
144 _oid_pair = ('extn_id', 'extn_value')
145 _oid_specs = {
146 'crl_reason': CRLReason,
147 'invalidity_date': GeneralizedTime,
148 'certificate_issuer': GeneralNames,
149 }
150
151
152class CRLEntryExtensions(SequenceOf):
153 _child_spec = CRLEntryExtension
154
155
156class RevokedCertificate(Sequence):
157 _fields = [
158 ('user_certificate', Integer),
159 ('revocation_date', Time),
160 ('crl_entry_extensions', CRLEntryExtensions, {'optional': True}),
161 ]
162
163
164class RevokedCertificates(SequenceOf):
165 _child_spec = RevokedCertificate
166
167
168class TbsCertList(Sequence):
169 _fields = [
170 ('version', Version, {'optional': True}),
171 ('signature', SignedDigestAlgorithm),
172 ('issuer', Name),
173 ('this_update', Time),
174 ('next_update', Time),
175 ('revoked_certificates', RevokedCertificates, {'optional': True}),
176 ('crl_extensions', TBSCertListExtensions, {'tag_type': 'explicit', 'tag': 0, 'optional': True}),
177 ]
178
179
180class CertificateList(Sequence):
181 _fields = [
182 ('tbs_cert_list', TbsCertList),
183 ('signature_algorith', SignedDigestAlgorithm),
184 ('signature', OctetBitString),
185 ]