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