Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
rfc6664.py148 linesDownload Raw Back to pyasn1_modules
1#2# This file is part of pyasn1-modules software.3#4# Created by Russ Housley with some assistance from asn1ate v.0.6.0.5#6# Copyright (c) 2019, Vigil Security, LLC7# License: http://snmplabs.com/pyasn1/license.html8#9# S/MIME Capabilities for Public Key Definitions10#11# ASN.1 source from:12# https://www.rfc-editor.org/rfc/rfc6664.txt13#14 15from pyasn1.type import constraint16from pyasn1.type import namedtype17from pyasn1.type import tag18from pyasn1.type import univ19 20from pyasn1_modules import rfc528021from pyasn1_modules import rfc575122from pyasn1_modules import rfc548023from pyasn1_modules import rfc405524from pyasn1_modules import rfc327925 26MAX = float('inf')27 28 29# Imports from RFC 528030 31AlgorithmIdentifier = rfc5280.AlgorithmIdentifier32 33 34# Imports from RFC 327935 36dhpublicnumber = rfc3279.dhpublicnumber37 38Dss_Parms = rfc3279.Dss_Parms39 40id_dsa = rfc3279.id_dsa41 42id_ecPublicKey = rfc3279.id_ecPublicKey43 44rsaEncryption = rfc3279.rsaEncryption45 46 47# Imports from RFC 405548 49id_mgf1 = rfc4055.id_mgf150 51id_RSAES_OAEP = rfc4055.id_RSAES_OAEP52 53id_RSASSA_PSS = rfc4055.id_RSASSA_PSS54 55 56# Imports from RFC 548057 58ECParameters = rfc5480.ECParameters59 60id_ecDH = rfc5480.id_ecDH61 62id_ecMQV = rfc5480.id_ecMQV63 64 65# RSA66 67class RSAKeySize(univ.Integer):68    # suggested values are 1024, 2048, 3072, 4096, 7680, 8192, and 15360;69    # however, the integer value is not limited to these suggestions70    pass71 72 73class RSAKeyCapabilities(univ.Sequence):74    componentType = namedtype.NamedTypes(75        namedtype.NamedType('minKeySize', RSAKeySize()),76        namedtype.OptionalNamedType('maxKeySize', RSAKeySize())77    )78 79 80class RsaSsa_Pss_sig_caps(univ.Sequence):81    componentType = namedtype.NamedTypes(82        namedtype.NamedType('hashAlg', AlgorithmIdentifier()),83        namedtype.OptionalNamedType('maskAlg', AlgorithmIdentifier()),84        namedtype.DefaultedNamedType('trailerField', univ.Integer().subtype(value=1))85    )86 87 88# Diffie-Hellman and DSA89 90class DSAKeySize(univ.Integer):91    subtypeSpec = constraint.SingleValueConstraint(1024, 2048, 3072, 7680, 15360)92 93 94class DSAKeyCapabilities(univ.Choice):95    componentType = namedtype.NamedTypes(96        namedtype.NamedType('keySizes', univ.Sequence(componentType=namedtype.NamedTypes(97            namedtype.NamedType('minKeySize',98                DSAKeySize()),99            namedtype.OptionalNamedType('maxKeySize',100                DSAKeySize()),101            namedtype.OptionalNamedType('maxSizeP',102                univ.Integer().subtype(explicitTag=tag.Tag(103                    tag.tagClassContext, tag.tagFormatSimple, 1))),104            namedtype.OptionalNamedType('maxSizeQ',105                univ.Integer().subtype(explicitTag=tag.Tag(106                    tag.tagClassContext, tag.tagFormatSimple, 2))),107            namedtype.OptionalNamedType('maxSizeG',108                univ.Integer().subtype(explicitTag=tag.Tag(109                    tag.tagClassContext, tag.tagFormatSimple, 3)))110        )).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),111        namedtype.NamedType('keyParams',112            Dss_Parms().subtype(explicitTag=tag.Tag(113                tag.tagClassContext, tag.tagFormatConstructed, 1)))114    )115 116 117# Elliptic Curve118 119class EC_SMimeCaps(univ.SequenceOf):120    componentType = ECParameters()121    subtypeSpec=constraint.ValueSizeConstraint(1, MAX)122 123 124# Update the SMIMECapabilities Attribute Map in rfc5751.py125#126# The map can either include an entry for scap-sa-rsaSSA-PSS or 127# scap-pk-rsaSSA-PSS, but not both.  One is associated with the128# public key and the other is associated with the signature129# algorithm; however, they use the same OID.  If you need the130# other one in your application, copy the map into a local dict,131# adjust as needed, and pass the local dict to the decoder with132# openTypes=your_local_map.133 134_smimeCapabilityMapUpdate = {135    rsaEncryption: RSAKeyCapabilities(),136    id_RSASSA_PSS: RSAKeyCapabilities(),137    # id_RSASSA_PSS: RsaSsa_Pss_sig_caps(),138    id_RSAES_OAEP: RSAKeyCapabilities(),139    id_dsa: DSAKeyCapabilities(),140    dhpublicnumber: DSAKeyCapabilities(),141    id_ecPublicKey: EC_SMimeCaps(),142    id_ecDH: EC_SMimeCaps(),143    id_ecMQV: EC_SMimeCaps(),144    id_mgf1: AlgorithmIdentifier(),145}146 147rfc5751.smimeCapabilityMap.update(_smimeCapabilityMapUpdate)148 
codekingpro/portable-devtools · Team Ai