Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pyasn1_modules/rfc2315.py: 100%
89 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:04 +0000
« prev ^ index » next coverage.py v7.2.2, created at 2023-03-26 06:04 +0000
1#
2# This file is part of pyasn1-modules software.
3#
4# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
5# License: http://snmplabs.com/pyasn1/license.html
6#
7# PKCS#7 message syntax
8#
9# ASN.1 source from:
10# https://opensource.apple.com/source/Security/Security-55179.1/libsecurity_asn1/asn1/pkcs7.asn.auto.html
11#
12# Sample captures from:
13# openssl crl2pkcs7 -nocrl -certfile cert1.cer -out outfile.p7b
14#
15from pyasn1_modules.rfc2459 import *
18class Attribute(univ.Sequence):
19 componentType = namedtype.NamedTypes(
20 namedtype.NamedType('type', AttributeType()),
21 namedtype.NamedType('values', univ.SetOf(componentType=AttributeValue()))
22 )
25class AttributeValueAssertion(univ.Sequence):
26 componentType = namedtype.NamedTypes(
27 namedtype.NamedType('attributeType', AttributeType()),
28 namedtype.NamedType('attributeValue', AttributeValue(),
29 openType=opentype.OpenType('type', certificateAttributesMap))
30 )
33pkcs_7 = univ.ObjectIdentifier('1.2.840.113549.1.7')
34data = univ.ObjectIdentifier('1.2.840.113549.1.7.1')
35signedData = univ.ObjectIdentifier('1.2.840.113549.1.7.2')
36envelopedData = univ.ObjectIdentifier('1.2.840.113549.1.7.3')
37signedAndEnvelopedData = univ.ObjectIdentifier('1.2.840.113549.1.7.4')
38digestedData = univ.ObjectIdentifier('1.2.840.113549.1.7.5')
39encryptedData = univ.ObjectIdentifier('1.2.840.113549.1.7.6')
42class ContentType(univ.ObjectIdentifier):
43 pass
46class ContentEncryptionAlgorithmIdentifier(AlgorithmIdentifier):
47 pass
50class EncryptedContent(univ.OctetString):
51 pass
54contentTypeMap = {}
57class EncryptedContentInfo(univ.Sequence):
58 componentType = namedtype.NamedTypes(
59 namedtype.NamedType('contentType', ContentType()),
60 namedtype.NamedType('contentEncryptionAlgorithm', ContentEncryptionAlgorithmIdentifier()),
61 namedtype.OptionalNamedType(
62 'encryptedContent', EncryptedContent().subtype(
63 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
64 ),
65 openType=opentype.OpenType('contentType', contentTypeMap)
66 )
67 )
70class Version(univ.Integer): # overrides x509.Version
71 pass
74class EncryptedData(univ.Sequence):
75 componentType = namedtype.NamedTypes(
76 namedtype.NamedType('version', Version()),
77 namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo())
78 )
81class DigestAlgorithmIdentifier(AlgorithmIdentifier):
82 pass
85class DigestAlgorithmIdentifiers(univ.SetOf):
86 componentType = DigestAlgorithmIdentifier()
89class Digest(univ.OctetString):
90 pass
93class ContentInfo(univ.Sequence):
94 componentType = namedtype.NamedTypes(
95 namedtype.NamedType('contentType', ContentType()),
96 namedtype.OptionalNamedType(
97 'content',
98 univ.Any().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)),
99 openType=opentype.OpenType('contentType', contentTypeMap)
100 )
101 )
104class DigestedData(univ.Sequence):
105 componentType = namedtype.NamedTypes(
106 namedtype.NamedType('version', Version()),
107 namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
108 namedtype.NamedType('contentInfo', ContentInfo()),
109 namedtype.NamedType('digest', Digest())
110 )
113class IssuerAndSerialNumber(univ.Sequence):
114 componentType = namedtype.NamedTypes(
115 namedtype.NamedType('issuer', Name()),
116 namedtype.NamedType('serialNumber', CertificateSerialNumber())
117 )
120class KeyEncryptionAlgorithmIdentifier(AlgorithmIdentifier):
121 pass
124class EncryptedKey(univ.OctetString):
125 pass
128class RecipientInfo(univ.Sequence):
129 componentType = namedtype.NamedTypes(
130 namedtype.NamedType('version', Version()),
131 namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()),
132 namedtype.NamedType('keyEncryptionAlgorithm', KeyEncryptionAlgorithmIdentifier()),
133 namedtype.NamedType('encryptedKey', EncryptedKey())
134 )
137class RecipientInfos(univ.SetOf):
138 componentType = RecipientInfo()
141class Attributes(univ.SetOf):
142 componentType = Attribute()
145class ExtendedCertificateInfo(univ.Sequence):
146 componentType = namedtype.NamedTypes(
147 namedtype.NamedType('version', Version()),
148 namedtype.NamedType('certificate', Certificate()),
149 namedtype.NamedType('attributes', Attributes())
150 )
153class SignatureAlgorithmIdentifier(AlgorithmIdentifier):
154 pass
157class Signature(univ.BitString):
158 pass
161class ExtendedCertificate(univ.Sequence):
162 componentType = namedtype.NamedTypes(
163 namedtype.NamedType('extendedCertificateInfo', ExtendedCertificateInfo()),
164 namedtype.NamedType('signatureAlgorithm', SignatureAlgorithmIdentifier()),
165 namedtype.NamedType('signature', Signature())
166 )
169class ExtendedCertificateOrCertificate(univ.Choice):
170 componentType = namedtype.NamedTypes(
171 namedtype.NamedType('certificate', Certificate()),
172 namedtype.NamedType('extendedCertificate', ExtendedCertificate().subtype(
173 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
174 )
177class ExtendedCertificatesAndCertificates(univ.SetOf):
178 componentType = ExtendedCertificateOrCertificate()
181class SerialNumber(univ.Integer):
182 pass
185class CRLEntry(univ.Sequence):
186 componentType = namedtype.NamedTypes(
187 namedtype.NamedType('userCertificate', SerialNumber()),
188 namedtype.NamedType('revocationDate', useful.UTCTime())
189 )
192class TBSCertificateRevocationList(univ.Sequence):
193 componentType = namedtype.NamedTypes(
194 namedtype.NamedType('signature', AlgorithmIdentifier()),
195 namedtype.NamedType('issuer', Name()),
196 namedtype.NamedType('lastUpdate', useful.UTCTime()),
197 namedtype.NamedType('nextUpdate', useful.UTCTime()),
198 namedtype.OptionalNamedType('revokedCertificates', univ.SequenceOf(componentType=CRLEntry()))
199 )
202class CertificateRevocationList(univ.Sequence):
203 componentType = namedtype.NamedTypes(
204 namedtype.NamedType('tbsCertificateRevocationList', TBSCertificateRevocationList()),
205 namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()),
206 namedtype.NamedType('signature', univ.BitString())
207 )
210class CertificateRevocationLists(univ.SetOf):
211 componentType = CertificateRevocationList()
214class DigestEncryptionAlgorithmIdentifier(AlgorithmIdentifier):
215 pass
218class EncryptedDigest(univ.OctetString):
219 pass
222class SignerInfo(univ.Sequence):
223 componentType = namedtype.NamedTypes(
224 namedtype.NamedType('version', Version()),
225 namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()),
226 namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
227 namedtype.OptionalNamedType('authenticatedAttributes', Attributes().subtype(
228 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
229 namedtype.NamedType('digestEncryptionAlgorithm', DigestEncryptionAlgorithmIdentifier()),
230 namedtype.NamedType('encryptedDigest', EncryptedDigest()),
231 namedtype.OptionalNamedType('unauthenticatedAttributes', Attributes().subtype(
232 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
233 )
236class SignerInfos(univ.SetOf):
237 componentType = SignerInfo()
240class SignedAndEnvelopedData(univ.Sequence):
241 componentType = namedtype.NamedTypes(
242 namedtype.NamedType('version', Version()),
243 namedtype.NamedType('recipientInfos', RecipientInfos()),
244 namedtype.NamedType('digestAlgorithms', DigestAlgorithmIdentifiers()),
245 namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo()),
246 namedtype.OptionalNamedType('certificates', ExtendedCertificatesAndCertificates().subtype(
247 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
248 namedtype.OptionalNamedType('crls', CertificateRevocationLists().subtype(
249 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
250 namedtype.NamedType('signerInfos', SignerInfos())
251 )
254class EnvelopedData(univ.Sequence):
255 componentType = namedtype.NamedTypes(
256 namedtype.NamedType('version', Version()),
257 namedtype.NamedType('recipientInfos', RecipientInfos()),
258 namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo())
259 )
262class DigestInfo(univ.Sequence):
263 componentType = namedtype.NamedTypes(
264 namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
265 namedtype.NamedType('digest', Digest())
266 )
269class SignedData(univ.Sequence):
270 componentType = namedtype.NamedTypes(
271 namedtype.NamedType('version', Version()),
272 namedtype.OptionalNamedType('digestAlgorithms', DigestAlgorithmIdentifiers()),
273 namedtype.NamedType('contentInfo', ContentInfo()),
274 namedtype.OptionalNamedType('certificates', ExtendedCertificatesAndCertificates().subtype(
275 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
276 namedtype.OptionalNamedType('crls', CertificateRevocationLists().subtype(
277 implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
278 namedtype.OptionalNamedType('signerInfos', SignerInfos())
279 )
282class Data(univ.OctetString):
283 pass
285_contentTypeMapUpdate = {
286 data: Data(),
287 signedData: SignedData(),
288 envelopedData: EnvelopedData(),
289 signedAndEnvelopedData: SignedAndEnvelopedData(),
290 digestedData: DigestedData(),
291 encryptedData: EncryptedData()
292}
294contentTypeMap.update(_contentTypeMapUpdate)