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# Certificate Extension for CMS Content Constraints (CCC)
11#
12# ASN.1 source from:
13# https://www.rfc-editor.org/rfc/rfc6010.txt
14#
15
16from pyasn1.type import constraint
17from pyasn1.type import namedtype
18from pyasn1.type import namedval
19from pyasn1.type import univ
20
21from pyasn1_modules import rfc5280
22
23MAX = float('inf')
24
25
26AttributeType = rfc5280.AttributeType
27
28AttributeValue = rfc5280.AttributeValue
29
30
31id_ct_anyContentType = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1.0')
32
33
34class AttrConstraint(univ.Sequence):
35    pass
36
37AttrConstraint.componentType = namedtype.NamedTypes(
38    namedtype.NamedType('attrType', AttributeType()),
39    namedtype.NamedType('attrValues', univ.SetOf(
40        componentType=AttributeValue()).subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))
41)
42
43
44class AttrConstraintList(univ.SequenceOf):
45    pass
46
47AttrConstraintList.componentType = AttrConstraint()
48AttrConstraintList.subtypeSpec=constraint.ValueSizeConstraint(1, MAX)
49
50
51class ContentTypeGeneration(univ.Enumerated):
52    pass
53
54ContentTypeGeneration.namedValues = namedval.NamedValues(
55    ('canSource', 0),
56    ('cannotSource', 1)
57)
58
59
60class ContentTypeConstraint(univ.Sequence):
61    pass
62
63ContentTypeConstraint.componentType = namedtype.NamedTypes(
64    namedtype.NamedType('contentType', univ.ObjectIdentifier()),
65    namedtype.DefaultedNamedType('canSource', ContentTypeGeneration().subtype(value='canSource')),
66    namedtype.OptionalNamedType('attrConstraints', AttrConstraintList())
67)
68
69
70# CMS Content Constraints (CCC) Extension and Object Identifier
71
72id_pe_cmsContentConstraints = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.18')
73
74class CMSContentConstraints(univ.SequenceOf):
75    pass
76
77CMSContentConstraints.componentType = ContentTypeConstraint()
78CMSContentConstraints.subtypeSpec=constraint.ValueSizeConstraint(1, MAX)
79
80
81# Map of Certificate Extension OIDs to Extensions
82# To be added to the ones that are in rfc5280.py
83
84_certificateExtensionsMap = {
85    id_pe_cmsContentConstraints: CMSContentConstraints(),
86}
87
88rfc5280.certificateExtensionsMap.update(_certificateExtensionsMap)
89