1#
2# This file is part of pyasn1-modules software.
3#
4# Created by Russ Housley with assistance from asn1ate v.0.6.0.
5# Modified by Russ Housley to add maps for use with opentypes.
6#
7# Copyright (c) 2019, Vigil Security, LLC
8# License: http://snmplabs.com/pyasn1/license.html
9#
10# Logotypes in X.509 Certificates
11#
12# ASN.1 source from:
13# https://www.rfc-editor.org/rfc/rfc3709.txt
14#
15
16from pyasn1.type import char
17from pyasn1.type import constraint
18from pyasn1.type import namedtype
19from pyasn1.type import namedval
20from pyasn1.type import tag
21from pyasn1.type import univ
22
23from pyasn1_modules import rfc5280
24from pyasn1_modules import rfc6170
25
26MAX = float('inf')
27
28
29class HashAlgAndValue(univ.Sequence):
30    pass
31
32HashAlgAndValue.componentType = namedtype.NamedTypes(
33    namedtype.NamedType('hashAlg', rfc5280.AlgorithmIdentifier()),
34    namedtype.NamedType('hashValue', univ.OctetString())
35)
36
37
38class LogotypeDetails(univ.Sequence):
39    pass
40
41LogotypeDetails.componentType = namedtype.NamedTypes(
42    namedtype.NamedType('mediaType', char.IA5String()),
43    namedtype.NamedType('logotypeHash', univ.SequenceOf(
44        componentType=HashAlgAndValue()).subtype(
45            sizeSpec=constraint.ValueSizeConstraint(1, MAX))),
46    namedtype.NamedType('logotypeURI', univ.SequenceOf(
47        componentType=char.IA5String()).subtype(
48            sizeSpec=constraint.ValueSizeConstraint(1, MAX)))
49)
50
51
52class LogotypeAudioInfo(univ.Sequence):
53    pass
54
55LogotypeAudioInfo.componentType = namedtype.NamedTypes(
56    namedtype.NamedType('fileSize', univ.Integer()),
57    namedtype.NamedType('playTime', univ.Integer()),
58    namedtype.NamedType('channels', univ.Integer()),
59    namedtype.OptionalNamedType('sampleRate', univ.Integer().subtype(
60        implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
61    namedtype.OptionalNamedType('language', char.IA5String().subtype(
62        implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
63)
64
65
66class LogotypeAudio(univ.Sequence):
67    pass
68
69LogotypeAudio.componentType = namedtype.NamedTypes(
70    namedtype.NamedType('audioDetails', LogotypeDetails()),
71    namedtype.OptionalNamedType('audioInfo', LogotypeAudioInfo())
72)
73
74
75class LogotypeImageType(univ.Integer):
76    pass
77
78LogotypeImageType.namedValues = namedval.NamedValues(
79    ('grayScale', 0),
80    ('color', 1)
81)
82
83
84class LogotypeImageResolution(univ.Choice):
85    pass
86
87LogotypeImageResolution.componentType = namedtype.NamedTypes(
88    namedtype.NamedType('numBits',
89        univ.Integer().subtype(implicitTag=tag.Tag(
90            tag.tagClassContext, tag.tagFormatSimple, 1))),
91    namedtype.NamedType('tableSize',
92        univ.Integer().subtype(implicitTag=tag.Tag(
93            tag.tagClassContext, tag.tagFormatSimple, 2)))
94)
95
96
97class LogotypeImageInfo(univ.Sequence):
98    pass
99
100LogotypeImageInfo.componentType = namedtype.NamedTypes(
101    namedtype.DefaultedNamedType('type', LogotypeImageType().subtype(
102        implicitTag=tag.Tag(tag.tagClassContext,
103            tag.tagFormatSimple, 0)).subtype(value='color')),
104    namedtype.NamedType('fileSize', univ.Integer()),
105    namedtype.NamedType('xSize', univ.Integer()),
106    namedtype.NamedType('ySize', univ.Integer()),
107    namedtype.OptionalNamedType('resolution', LogotypeImageResolution()),
108    namedtype.OptionalNamedType('language', char.IA5String().subtype(
109        implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
110)
111
112
113class LogotypeImage(univ.Sequence):
114    pass
115
116LogotypeImage.componentType = namedtype.NamedTypes(
117    namedtype.NamedType('imageDetails', LogotypeDetails()),
118    namedtype.OptionalNamedType('imageInfo', LogotypeImageInfo())
119)
120
121
122class LogotypeData(univ.Sequence):
123    pass
124
125LogotypeData.componentType = namedtype.NamedTypes(
126    namedtype.OptionalNamedType('image', univ.SequenceOf(
127        componentType=LogotypeImage())),
128    namedtype.OptionalNamedType('audio', univ.SequenceOf(
129        componentType=LogotypeAudio()).subtype(
130            implicitTag=tag.Tag(tag.tagClassContext,
131            tag.tagFormatSimple, 1)))
132)
133
134
135class LogotypeReference(univ.Sequence):
136    pass
137
138LogotypeReference.componentType = namedtype.NamedTypes(
139    namedtype.NamedType('refStructHash', univ.SequenceOf(
140        componentType=HashAlgAndValue()).subtype(
141            sizeSpec=constraint.ValueSizeConstraint(1, MAX))),
142    namedtype.NamedType('refStructURI', univ.SequenceOf(
143        componentType=char.IA5String()).subtype(
144            sizeSpec=constraint.ValueSizeConstraint(1, MAX)))
145)
146
147
148class LogotypeInfo(univ.Choice):
149    pass
150
151LogotypeInfo.componentType = namedtype.NamedTypes(
152    namedtype.NamedType('direct',
153        LogotypeData().subtype(implicitTag=tag.Tag(tag.tagClassContext,
154            tag.tagFormatConstructed, 0))),
155    namedtype.NamedType('indirect', LogotypeReference().subtype(
156        implicitTag=tag.Tag(tag.tagClassContext,
157             tag.tagFormatConstructed, 1)))
158)
159
160# Other logotype type and associated object identifiers
161
162id_logo_background = univ.ObjectIdentifier('1.3.6.1.5.5.7.20.2')
163
164id_logo_loyalty = univ.ObjectIdentifier('1.3.6.1.5.5.7.20.1')
165
166id_logo_certImage = rfc6170.id_logo_certImage
167
168
169class OtherLogotypeInfo(univ.Sequence):
170    pass
171
172OtherLogotypeInfo.componentType = namedtype.NamedTypes(
173    namedtype.NamedType('logotypeType', univ.ObjectIdentifier()),
174    namedtype.NamedType('info', LogotypeInfo())
175)
176
177
178# Logotype Certificate Extension
179
180id_pe_logotype = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.12')
181
182
183class LogotypeExtn(univ.Sequence):
184    pass
185
186LogotypeExtn.componentType = namedtype.NamedTypes(
187    namedtype.OptionalNamedType('communityLogos', univ.SequenceOf(
188        componentType=LogotypeInfo()).subtype(
189            explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
190    namedtype.OptionalNamedType('issuerLogo', LogotypeInfo().subtype(
191        explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
192    namedtype.OptionalNamedType('subjectLogo', LogotypeInfo().subtype(
193        explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
194    namedtype.OptionalNamedType('otherLogos', univ.SequenceOf(
195        componentType=OtherLogotypeInfo()).subtype(explicitTag=tag.Tag(
196            tag.tagClassContext, tag.tagFormatSimple, 3)))
197)
198
199
200# Map of Certificate Extension OIDs to Extensions added to the
201# ones that are in rfc5280.py
202
203_certificateExtensionsMapUpdate = {
204    id_pe_logotype: LogotypeExtn(),
205}
206
207rfc5280.certificateExtensionsMap.update(_certificateExtensionsMapUpdate)
208