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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# This file is being contributed to of pyasn1-modules software.
#
# Created by Russ Housley without assistance from the asn1ate tool.
# Modified by Russ Housley to add support for opentypes.
#
# Copyright (c) 2019, Vigil Security, LLC
# License: http://snmplabs.com/pyasn1/license.html
#
# CMS Key Package Receipt and Error Content Types
#
# ASN.1 source from:
# https://www.rfc-editor.org/rfc/rfc7191.txt
from pyasn1.type import constraint
from pyasn1.type import namedtype
from pyasn1.type import namedval
from pyasn1.type import opentype
from pyasn1.type import tag
from pyasn1.type import univ
from pyasn1_modules import rfc5280
from pyasn1_modules import rfc5652
MAX = float('inf')
DistinguishedName = rfc5280.DistinguishedName
# SingleAttribute is the same as Attribute in RFC 5652, except that the
# attrValues SET must have one and only one member
class AttributeValue(univ.Any):
pass
class AttributeValues(univ.SetOf):
pass
AttributeValues.componentType = AttributeValue()
AttributeValues.sizeSpec = univ.Set.sizeSpec + constraint.ValueSizeConstraint(1, 1)
class SingleAttribute(univ.Sequence):
pass
SingleAttribute.componentType = namedtype.NamedTypes(
namedtype.NamedType('attrType', univ.ObjectIdentifier()),
namedtype.NamedType('attrValues', AttributeValues(),
openType=opentype.OpenType('attrType', rfc5652.cmsAttributesMap)
)
)
# SIR Entity Name
class SIREntityNameType(univ.ObjectIdentifier):
pass
class SIREntityNameValue(univ.Any):
pass
class SIREntityName(univ.Sequence):
pass
SIREntityName.componentType = namedtype.NamedTypes(
namedtype.NamedType('sirenType', SIREntityNameType()),
namedtype.NamedType('sirenValue', univ.OctetString())
# CONTAINING the DER-encoded SIREntityNameValue
)
class SIREntityNames(univ.SequenceOf):
pass
SIREntityNames.componentType = SIREntityName()
SIREntityNames.sizeSpec=constraint.ValueSizeConstraint(1, MAX)
id_dn = univ.ObjectIdentifier('2.16.840.1.101.2.1.16.0')
class siren_dn(SIREntityName):
def __init__(self):
SIREntityName.__init__(self)
self['sirenType'] = id_dn
# Key Package Error CMS Content Type
class EnumeratedErrorCode(univ.Enumerated):
pass
# Error codes with values <= 33 are aligned with RFC 5934
EnumeratedErrorCode.namedValues = namedval.NamedValues(
('decodeFailure', 1),
('badContentInfo', 2),
('badSignedData', 3),
('badEncapContent', 4),
('badCertificate', 5),
('badSignerInfo', 6),
('badSignedAttrs', 7),
('badUnsignedAttrs', 8),
('missingContent', 9),
('noTrustAnchor', 10),
('notAuthorized', 11),
('badDigestAlgorithm', 12),
('badSignatureAlgorithm', 13),
('unsupportedKeySize', 14),
('unsupportedParameters', 15),
('signatureFailure', 16),
('insufficientMemory', 17),
('incorrectTarget', 23),
('missingSignature', 29),
('resourcesBusy', 30),
('versionNumberMismatch', 31),
('revokedCertificate', 33),
('ambiguousDecrypt', 60),
('noDecryptKey', 61),
('badEncryptedData', 62),
('badEnvelopedData', 63),
('badAuthenticatedData', 64),
('badAuthEnvelopedData', 65),
('badKeyAgreeRecipientInfo', 66),
('badKEKRecipientInfo', 67),
('badEncryptContent', 68),
('badEncryptAlgorithm', 69),
('missingCiphertext', 70),
('decryptFailure', 71),
('badMACAlgorithm', 72),
('badAuthAttrs', 73),
('badUnauthAttrs', 74),
('invalidMAC', 75),
('mismatchedDigestAlg', 76),
('missingCertificate', 77),
('tooManySigners', 78),
('missingSignedAttributes', 79),
('derEncodingNotUsed', 80),
('missingContentHints', 81),
('invalidAttributeLocation', 82),
('badMessageDigest', 83),
('badKeyPackage', 84),
('badAttributes', 85),
('attributeComparisonFailure', 86),
('unsupportedSymmetricKeyPackage', 87),
('unsupportedAsymmetricKeyPackage', 88),
('constraintViolation', 89),
('ambiguousDefaultValue', 90),
('noMatchingRecipientInfo', 91),
('unsupportedKeyWrapAlgorithm', 92),
('badKeyTransRecipientInfo', 93),
('other', 127)
)
class ErrorCodeChoice(univ.Choice):
pass
ErrorCodeChoice.componentType = namedtype.NamedTypes(
namedtype.NamedType('enum', EnumeratedErrorCode()),
namedtype.NamedType('oid', univ.ObjectIdentifier())
)
class KeyPkgID(univ.OctetString):
pass
class KeyPkgIdentifier(univ.Choice):
pass
KeyPkgIdentifier.componentType = namedtype.NamedTypes(
namedtype.NamedType('pkgID', KeyPkgID()),
namedtype.NamedType('attribute', SingleAttribute())
)
class KeyPkgVersion(univ.Integer):
pass
KeyPkgVersion.namedValues = namedval.NamedValues(
('v1', 1),
('v2', 2)
)
KeyPkgVersion.subtypeSpec = constraint.ValueRangeConstraint(1, 65535)
id_ct_KP_keyPackageError = univ.ObjectIdentifier('2.16.840.1.101.2.1.2.78.6')
class KeyPackageError(univ.Sequence):
pass
KeyPackageError.componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('version', KeyPkgVersion().subtype(value='v2')),
namedtype.OptionalNamedType('errorOf', KeyPkgIdentifier().subtype(
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
namedtype.NamedType('errorBy', SIREntityName()),
namedtype.NamedType('errorCode', ErrorCodeChoice())
)
# Key Package Receipt CMS Content Type
id_ct_KP_keyPackageReceipt = univ.ObjectIdentifier('2.16.840.1.101.2.1.2.78.3')
class KeyPackageReceipt(univ.Sequence):
pass
KeyPackageReceipt.componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('version', KeyPkgVersion().subtype(value='v2')),
namedtype.NamedType('receiptOf', KeyPkgIdentifier()),
namedtype.NamedType('receivedBy', SIREntityName())
)
# Key Package Receipt Request Attribute
class KeyPkgReceiptReq(univ.Sequence):
pass
KeyPkgReceiptReq.componentType = namedtype.NamedTypes(
namedtype.DefaultedNamedType('encryptReceipt', univ.Boolean().subtype(value=0)),
namedtype.OptionalNamedType('receiptsFrom', SIREntityNames().subtype(
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
namedtype.NamedType('receiptsTo', SIREntityNames())
)
id_aa_KP_keyPkgIdAndReceiptReq = univ.ObjectIdentifier('2.16.840.1.101.2.1.5.65')
class KeyPkgIdentifierAndReceiptReq(univ.Sequence):
pass
KeyPkgIdentifierAndReceiptReq.componentType = namedtype.NamedTypes(
namedtype.NamedType('pkgID', KeyPkgID()),
namedtype.OptionalNamedType('receiptReq', KeyPkgReceiptReq())
)
# Map of Attribute Type OIDs to Attributes are added to
# the ones that are in rfc5652.py
_cmsAttributesMapUpdate = {
id_aa_KP_keyPkgIdAndReceiptReq: KeyPkgIdentifierAndReceiptReq(),
}
rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)
# Map of CMC Content Type OIDs to CMC Content Types are added to
# the ones that are in rfc5652.py
_cmsContentTypesMapUpdate = {
id_ct_KP_keyPackageError: KeyPackageError(),
id_ct_KP_keyPackageReceipt: KeyPackageReceipt(),
}
rfc5652.cmsContentTypesMap.update(_cmsContentTypesMapUpdate)
|