forked from snowflakedb/snowflake-connector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfc6960.py
179 lines (145 loc) · 6.49 KB
/
rfc6960.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- coding: utf-8 -*-
#
# X.509 Internet Public Key Infrastructure Online Certificate Status
# Protocol - OCSP
#
# ASN.1 source from
# https://tools.ietf.org/html/rfc6960
#
from pyasn1.type import (univ, namedtype, tag, namedval, useful)
from pyasn1_modules import rfc2459
class Version(univ.Integer):
namedValues = namedval.NamedValues(
('v1', 0)
)
class CertID(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('hashAlgorithm', rfc2459.AlgorithmIdentifier()),
namedtype.NamedType('issuerNameHash', univ.OctetString()),
namedtype.NamedType('issuerKeyHash', univ.OctetString()),
namedtype.NamedType('serialNumber', rfc2459.CertificateSerialNumber()))
class Request(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('reqCert', CertID()),
namedtype.OptionalNamedType(
'singleRequestExtensions',
rfc2459.Extensions().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 0))))
class TBSRequest(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType(
'version', Version(0).subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.OptionalNamedType(
'requestorName',
rfc2459.GeneralName().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 1))),
namedtype.NamedType('requestList',
univ.SequenceOf(componentType=Request())),
namedtype.OptionalNamedType(
'requestExtensions',
rfc2459.Extensions().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 2))))
class Certs(univ.SequenceOf):
componentType = rfc2459.Certificate()
class Signature(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('signatureAlgorithm',
rfc2459.AlgorithmIdentifier()),
namedtype.NamedType('signature', univ.BitString()),
namedtype.NamedType(
'certs', Certs().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 0))))
class OCSPRequest(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('tbsRequest', TBSRequest()),
namedtype.OptionalNamedType(
'optionalSignature', Signature().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 0))))
# OCSP Response
class OCSPResponseStatus(univ.Enumerated):
namedValues = namedval.NamedValues(
('successful', 0),
('malformedRequest', 1),
('internalError', 2),
('tryLater', 3),
# ('not-used', 4),
('sigRequired', 5),
('unauthorized', 6)
)
class ResponseBytes(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('responseType', univ.ObjectIdentifier()),
namedtype.NamedType('response', univ.OctetString())
)
class OCSPResponse(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('responseStatus', OCSPResponseStatus()),
namedtype.OptionalNamedType('responseBytes', ResponseBytes().subtype(
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))))
KeyHash = univ.OctetString
UnknownInfo = univ.Null
class RevokedInfo(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('revocationTime', useful.GeneralizedTime()),
namedtype.OptionalNamedType(
'revocationReason',
rfc2459.CRLReason().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 0))))
class CertStatus(univ.Choice):
componentType = namedtype.NamedTypes(
namedtype.NamedType('good', univ.Null().subtype(
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('revoked', RevokedInfo().subtype(
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
namedtype.NamedType('unknown', UnknownInfo().subtype(
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))))
class SingleResponse(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('certID', CertID()),
namedtype.NamedType('certStatus', CertStatus()),
namedtype.NamedType('thisUpdate', useful.GeneralizedTime()),
namedtype.OptionalNamedType(
'nextUpdate',
useful.GeneralizedTime().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.OptionalNamedType(
'singleExtensions',
rfc2459.Extensions().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 1))))
class ResponderID(univ.Choice):
componentType = namedtype.NamedTypes(
namedtype.NamedType('byName', rfc2459.Name().subtype(
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
namedtype.NamedType('byKey', KeyHash().subtype(
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))))
class ResponseData(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('version', Version(0).subtype(
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('responderID', ResponderID()),
namedtype.NamedType('producedAt', useful.GeneralizedTime()),
namedtype.NamedType('responses',
univ.SequenceOf(componentType=SingleResponse())),
namedtype.OptionalNamedType(
'responseExtensions',
rfc2459.Extensions().subtype(
explicitTag=tag.Tag(
tag.tagClassContext, tag.tagFormatSimple, 1))))
class BasicOCSPResponse(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('tbsResponseData', ResponseData()),
namedtype.NamedType('signatureAlgorithm',
rfc2459.AlgorithmIdentifier()),
namedtype.NamedType('signature', univ.BitString()),
namedtype.OptionalNamedType('certs', Certs().subtype(
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))))