• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# This file is being contributed to pyasn1-modules software.
2#
3# Created by Russ Housley with assistance from asn1ate v.0.6.0.
4#
5# Copyright (c) 2019, Vigil Security, LLC
6# License: http://snmplabs.com/pyasn1/license.html
7#
8# S/MIME Version 3.2 Message Specification
9#
10# ASN.1 source from:
11# https://www.rfc-editor.org/rfc/rfc5751.txt
12
13from pyasn1.type import namedtype
14from pyasn1.type import opentype
15from pyasn1.type import tag
16from pyasn1.type import univ
17
18from pyasn1_modules import rfc5652
19from pyasn1_modules import rfc8018
20
21
22def _OID(*components):
23    output = []
24    for x in tuple(components):
25        if isinstance(x, univ.ObjectIdentifier):
26            output.extend(list(x))
27        else:
28            output.append(int(x))
29    return univ.ObjectIdentifier(output)
30
31
32# Imports from RFC 5652 and RFC 8018
33
34IssuerAndSerialNumber = rfc5652.IssuerAndSerialNumber
35
36RecipientKeyIdentifier = rfc5652.RecipientKeyIdentifier
37
38SubjectKeyIdentifier = rfc5652.SubjectKeyIdentifier
39
40rc2CBC = rfc8018.rc2CBC
41
42
43# S/MIME Capabilities Attribute
44
45smimeCapabilities = univ.ObjectIdentifier('1.2.840.113549.1.9.15')
46
47
48smimeCapabilityMap = { }
49
50
51class SMIMECapability(univ.Sequence):
52    pass
53
54SMIMECapability.componentType = namedtype.NamedTypes(
55    namedtype.NamedType('capabilityID', univ.ObjectIdentifier()),
56    namedtype.OptionalNamedType('parameters', univ.Any(),
57        openType=opentype.OpenType('capabilityID', smimeCapabilityMap))
58)
59
60
61class SMIMECapabilities(univ.SequenceOf):
62    pass
63
64SMIMECapabilities.componentType = SMIMECapability()
65
66
67class SMIMECapabilitiesParametersForRC2CBC(univ.Integer):
68    # which carries the RC2 Key Length (number of bits)
69    pass
70
71
72# S/MIME Encryption Key Preference Attribute
73
74id_smime = univ.ObjectIdentifier('1.2.840.113549.1.9.16')
75
76id_aa = _OID(id_smime, 2)
77
78id_aa_encrypKeyPref = _OID(id_aa, 11)
79
80
81class SMIMEEncryptionKeyPreference(univ.Choice):
82    pass
83
84SMIMEEncryptionKeyPreference.componentType = namedtype.NamedTypes(
85    namedtype.NamedType('issuerAndSerialNumber',
86        IssuerAndSerialNumber().subtype(implicitTag=tag.Tag(
87            tag.tagClassContext, tag.tagFormatSimple, 0))),
88    namedtype.NamedType('receipentKeyId',
89        # Yes, 'receipentKeyId' is spelled incorrectly, but kept
90        # this way for alignment with the ASN.1 module in the RFC.
91        RecipientKeyIdentifier().subtype(implicitTag=tag.Tag(
92            tag.tagClassContext, tag.tagFormatSimple, 1))),
93    namedtype.NamedType('subjectAltKeyIdentifier',
94        SubjectKeyIdentifier().subtype(implicitTag=tag.Tag(
95            tag.tagClassContext, tag.tagFormatSimple, 2)))
96)
97
98
99# The Prefer Binary Inside SMIMECapabilities attribute
100
101id_cap = _OID(id_smime, 11)
102
103id_cap_preferBinaryInside = _OID(id_cap, 1)
104
105
106# CMS Attribute Map
107
108_cmsAttributesMapUpdate = {
109    smimeCapabilities: SMIMECapabilities(),
110    id_aa_encrypKeyPref: SMIMEEncryptionKeyPreference(),
111}
112
113rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)
114
115
116# SMIMECapabilities Attribute Map
117#
118# Do not include OIDs in the dictionary when the parameters are absent.
119
120_smimeCapabilityMapUpdate = {
121    rc2CBC: SMIMECapabilitiesParametersForRC2CBC(),
122}
123
124smimeCapabilityMap.update(_smimeCapabilityMapUpdate)
125