• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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#
6# Copyright (c) 2019, Vigil Security, LLC
7# License: http://snmplabs.com/pyasn1/license.html
8#
9# Securing Header Fields with S/MIME
10#
11# ASN.1 source from:
12# https://www.rfc-editor.org/rfc/rfc7508.txt
13# https://www.rfc-editor.org/errata/eid5875
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 univ
21
22from pyasn1_modules import rfc5652
23
24import string
25
26MAX = float('inf')
27
28
29class Algorithm(univ.Enumerated):
30    namedValues = namedval.NamedValues(
31        ('canonAlgorithmSimple', 0),
32        ('canonAlgorithmRelaxed', 1)
33    )
34
35
36class HeaderFieldStatus(univ.Integer):
37    namedValues = namedval.NamedValues(
38        ('duplicated', 0),
39        ('deleted', 1),
40        ('modified', 2)
41    )
42
43
44class HeaderFieldName(char.VisibleString):
45    subtypeSpec = (
46        constraint.PermittedAlphabetConstraint(*string.printable) -
47        constraint.PermittedAlphabetConstraint(':')
48    )
49
50
51class HeaderFieldValue(char.UTF8String):
52    pass
53
54
55class HeaderField(univ.Sequence):
56    componentType = namedtype.NamedTypes(
57        namedtype.NamedType('field-Name', HeaderFieldName()),
58        namedtype.NamedType('field-Value', HeaderFieldValue()),
59        namedtype.DefaultedNamedType('field-Status',
60            HeaderFieldStatus().subtype(value='duplicated'))
61    )
62
63
64class HeaderFields(univ.SequenceOf):
65    componentType = HeaderField()
66    subtypeSpec = constraint.ValueSizeConstraint(1, MAX)
67
68
69class SecureHeaderFields(univ.Set):
70    componentType = namedtype.NamedTypes(
71        namedtype.NamedType('canonAlgorithm', Algorithm()),
72        namedtype.NamedType('secHeaderFields', HeaderFields())
73    )
74
75
76id_aa = univ.ObjectIdentifier((1, 2, 840, 113549, 1, 9, 16, 2, ))
77
78id_aa_secureHeaderFieldsIdentifier = id_aa + (55, )
79
80
81
82# Map of Attribute Type OIDs to Attributes added to the
83# ones that are in rfc5652.py
84
85_cmsAttributesMapUpdate = {
86    id_aa_secureHeaderFieldsIdentifier: SecureHeaderFields(),
87}
88
89rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)
90
91