Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
rfc5126.py578 linesDownload Raw Back to pyasn1_modules
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, LLC7# License: http://snmplabs.com/pyasn1/license.html8#9# CMS Advanced Electronic Signatures (CAdES)10#11# ASN.1 source from:12# https://www.rfc-editor.org/rfc/rfc5126.txt13#14 15from pyasn1.type import char16from pyasn1.type import constraint17from pyasn1.type import namedtype18from pyasn1.type import opentype19from pyasn1.type import tag20from pyasn1.type import useful21from pyasn1.type import univ22 23from pyasn1_modules import rfc528024from pyasn1_modules import rfc565225from pyasn1_modules import rfc503526from pyasn1_modules import rfc575527from pyasn1_modules import rfc696028from pyasn1_modules import rfc316129 30MAX = float('inf')31 32 33# Maps for OpenTypes34 35commitmentQualifierMap = { }36 37sigQualifiersMap = { }38 39otherRevRefMap = { }40 41otherRevValMap = { }42 43 44# Imports from RFC 565245 46ContentInfo = rfc5652.ContentInfo47 48ContentType = rfc5652.ContentType49 50SignedData = rfc5652.SignedData51 52EncapsulatedContentInfo = rfc5652.EncapsulatedContentInfo53 54SignerInfo = rfc5652.SignerInfo55 56MessageDigest = rfc5652.MessageDigest57 58SigningTime = rfc5652.SigningTime59 60Countersignature = rfc5652.Countersignature61 62id_data = rfc5652.id_data63 64id_signedData = rfc5652.id_signedData65 66id_contentType= rfc5652.id_contentType67 68id_messageDigest = rfc5652.id_messageDigest69 70id_signingTime = rfc5652.id_signingTime71 72id_countersignature = rfc5652.id_countersignature73 74 75# Imports from RFC 503576 77SigningCertificate = rfc5035.SigningCertificate78 79IssuerSerial = rfc5035.IssuerSerial80 81ContentReference = rfc5035.ContentReference82 83ContentIdentifier = rfc5035.ContentIdentifier84 85id_aa_contentReference = rfc5035.id_aa_contentReference86 87id_aa_contentIdentifier = rfc5035.id_aa_contentIdentifier88    89id_aa_signingCertificate = rfc5035.id_aa_signingCertificate90 91id_aa_signingCertificateV2 = rfc5035.id_aa_signingCertificateV292 93 94# Imports from RFC 528095 96Certificate = rfc5280.Certificate97 98AlgorithmIdentifier = rfc5280.AlgorithmIdentifier99 100CertificateList = rfc5280.CertificateList101 102Name = rfc5280.Name103 104Attribute = rfc5280.Attribute105 106GeneralNames = rfc5280.GeneralNames107 108GeneralName = rfc5280.GeneralName109 110PolicyInformation = rfc5280.PolicyInformation111 112DirectoryString = rfc5280.DirectoryString113 114 115# Imports from RFC 5755116 117AttributeCertificate = rfc5755.AttributeCertificate118 119 120# Imports from RFC 6960121 122BasicOCSPResponse = rfc6960.BasicOCSPResponse123 124ResponderID = rfc6960.ResponderID125 126 127# Imports from RFC 3161128 129TimeStampToken = rfc3161.TimeStampToken130 131 132# OID used referencing electronic signature mechanisms133 134id_etsi_es_IDUP_Mechanism_v1 = univ.ObjectIdentifier('0.4.0.1733.1.4.1')135 136 137# OtherSigningCertificate - deprecated138 139id_aa_ets_otherSigCert = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.19')140 141 142class OtherHashValue(univ.OctetString):143    pass144 145 146class OtherHashAlgAndValue(univ.Sequence):147    componentType = namedtype.NamedTypes(148        namedtype.NamedType('hashAlgorithm', AlgorithmIdentifier()),149        namedtype.NamedType('hashValue', OtherHashValue())150    )151 152 153class OtherHash(univ.Choice):154    componentType = namedtype.NamedTypes(155        namedtype.NamedType('sha1Hash', OtherHashValue()),156        namedtype.NamedType('otherHash', OtherHashAlgAndValue())157    )158 159 160class OtherCertID(univ.Sequence):161    componentType = namedtype.NamedTypes(162        namedtype.NamedType('otherCertHash', OtherHash()),163        namedtype.OptionalNamedType('issuerSerial', IssuerSerial())164    )165 166 167class OtherSigningCertificate(univ.Sequence):168    componentType = namedtype.NamedTypes(169        namedtype.NamedType('certs',170            univ.SequenceOf(componentType=OtherCertID())),171        namedtype.OptionalNamedType('policies',172            univ.SequenceOf(componentType=PolicyInformation()))173    )174 175 176# Signature Policy Identifier177 178id_aa_ets_sigPolicyId = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.15')179 180 181class SigPolicyId(univ.ObjectIdentifier):182    pass183 184 185class SigPolicyHash(OtherHashAlgAndValue):186    pass187 188 189class SigPolicyQualifierId(univ.ObjectIdentifier):190    pass191 192 193class SigPolicyQualifierInfo(univ.Sequence):194    componentType = namedtype.NamedTypes(195        namedtype.NamedType('sigPolicyQualifierId', SigPolicyQualifierId()),196        namedtype.NamedType('sigQualifier', univ.Any(),197            openType=opentype.OpenType('sigPolicyQualifierId', sigQualifiersMap))198    )199 200 201class SignaturePolicyId(univ.Sequence):202    componentType = namedtype.NamedTypes(203        namedtype.NamedType('sigPolicyId', SigPolicyId()),204        namedtype.NamedType('sigPolicyHash', SigPolicyHash()),205        namedtype.OptionalNamedType('sigPolicyQualifiers',206            univ.SequenceOf(componentType=SigPolicyQualifierInfo()).subtype(207                subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))208    )209 210 211class SignaturePolicyImplied(univ.Null):212    pass213 214 215class SignaturePolicy(univ.Choice):216    componentType = namedtype.NamedTypes(217        namedtype.NamedType('signaturePolicyId', SignaturePolicyId()),218        namedtype.NamedType('signaturePolicyImplied', SignaturePolicyImplied())219    )220 221 222id_spq_ets_unotice = univ.ObjectIdentifier('1.2.840.113549.1.9.16.5.2')223 224 225class DisplayText(univ.Choice):226    componentType = namedtype.NamedTypes(227        namedtype.NamedType('visibleString', char.VisibleString().subtype(228            subtypeSpec=constraint.ValueSizeConstraint(1, 200))),229        namedtype.NamedType('bmpString', char.BMPString().subtype(230            subtypeSpec=constraint.ValueSizeConstraint(1, 200))),231        namedtype.NamedType('utf8String', char.UTF8String().subtype(232            subtypeSpec=constraint.ValueSizeConstraint(1, 200)))233    )234 235 236class NoticeReference(univ.Sequence):237    componentType = namedtype.NamedTypes(238        namedtype.NamedType('organization', DisplayText()),239        namedtype.NamedType('noticeNumbers',240            univ.SequenceOf(componentType=univ.Integer()))241    )242 243class SPUserNotice(univ.Sequence):244    componentType = namedtype.NamedTypes(245        namedtype.OptionalNamedType('noticeRef', NoticeReference()),246        namedtype.OptionalNamedType('explicitText', DisplayText())247    )248 249 250noticeToUser = SigPolicyQualifierInfo()251noticeToUser['sigPolicyQualifierId'] = id_spq_ets_unotice252noticeToUser['sigQualifier'] = SPUserNotice()253 254 255id_spq_ets_uri = univ.ObjectIdentifier('1.2.840.113549.1.9.16.5.1')256 257 258class SPuri(char.IA5String):259    pass260 261 262pointerToSigPolSpec = SigPolicyQualifierInfo()263pointerToSigPolSpec['sigPolicyQualifierId'] = id_spq_ets_uri264pointerToSigPolSpec['sigQualifier'] = SPuri()265 266 267# Commitment Type268 269id_aa_ets_commitmentType = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.16')270 271 272class CommitmentTypeIdentifier(univ.ObjectIdentifier):273    pass274 275 276class CommitmentTypeQualifier(univ.Sequence):277    componentType = namedtype.NamedTypes(278        namedtype.NamedType('commitmentTypeIdentifier',279             CommitmentTypeIdentifier()),280        namedtype.NamedType('qualifier', univ.Any(),281            openType=opentype.OpenType('commitmentTypeIdentifier',282                 commitmentQualifierMap))283    )284 285 286class CommitmentTypeIndication(univ.Sequence):287    componentType = namedtype.NamedTypes(288        namedtype.NamedType('commitmentTypeId', CommitmentTypeIdentifier()),289        namedtype.OptionalNamedType('commitmentTypeQualifier',290            univ.SequenceOf(componentType=CommitmentTypeQualifier()).subtype(291                subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))292    )293 294 295id_cti_ets_proofOfOrigin = univ.ObjectIdentifier('1.2.840.113549.1.9.16.6.1')296 297id_cti_ets_proofOfReceipt = univ.ObjectIdentifier('1.2.840.113549.1.9.16.6.2')298 299id_cti_ets_proofOfDelivery = univ.ObjectIdentifier('1.2.840.113549.1.9.16.6.3')300 301id_cti_ets_proofOfSender = univ.ObjectIdentifier('1.2.840.113549.1.9.16.6.4')302 303id_cti_ets_proofOfApproval = univ.ObjectIdentifier('1.2.840.113549.1.9.16.6.5')304 305id_cti_ets_proofOfCreation = univ.ObjectIdentifier('1.2.840.113549.1.9.16.6.6')306 307 308# Signer Location309 310id_aa_ets_signerLocation = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.17')311 312 313class PostalAddress(univ.SequenceOf):314    componentType = DirectoryString()315    subtypeSpec = constraint.ValueSizeConstraint(1, 6)316 317 318class SignerLocation(univ.Sequence):319    componentType = namedtype.NamedTypes(320        namedtype.OptionalNamedType('countryName',321            DirectoryString().subtype(explicitTag=tag.Tag(322                tag.tagClassContext, tag.tagFormatSimple, 0))),323        namedtype.OptionalNamedType('localityName',324            DirectoryString().subtype(explicitTag=tag.Tag(325                tag.tagClassContext, tag.tagFormatSimple, 1))),326        namedtype.OptionalNamedType('postalAdddress',327            PostalAddress().subtype(explicitTag=tag.Tag(328                tag.tagClassContext, tag.tagFormatSimple, 2)))329    )330 331 332# Signature Timestamp333 334id_aa_signatureTimeStampToken = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.14')335 336 337class SignatureTimeStampToken(TimeStampToken):338    pass339 340 341# Content Timestamp342 343id_aa_ets_contentTimestamp = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.20')344 345 346class ContentTimestamp(TimeStampToken):347    pass348 349 350# Signer Attributes351 352id_aa_ets_signerAttr = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.18')353 354 355class ClaimedAttributes(univ.SequenceOf):356    componentType = Attribute()357 358 359class CertifiedAttributes(AttributeCertificate):360    pass361 362 363class SignerAttribute(univ.SequenceOf):364    componentType = univ.Choice(componentType=namedtype.NamedTypes(365        namedtype.NamedType('claimedAttributes',366            ClaimedAttributes().subtype(explicitTag=tag.Tag(367                tag.tagClassContext, tag.tagFormatSimple, 0))),368        namedtype.NamedType('certifiedAttributes',369            CertifiedAttributes().subtype(explicitTag=tag.Tag(370                tag.tagClassContext, tag.tagFormatSimple, 1)))371    ))372 373 374# Complete Certificate Refs375 376id_aa_ets_certificateRefs = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.21')377 378 379class CompleteCertificateRefs(univ.SequenceOf):380    componentType = OtherCertID()381 382 383# Complete Revocation Refs384 385id_aa_ets_revocationRefs = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.22')386 387 388class CrlIdentifier(univ.Sequence):389    componentType = namedtype.NamedTypes(390        namedtype.NamedType('crlissuer', Name()),391        namedtype.NamedType('crlIssuedTime', useful.UTCTime()),392        namedtype.OptionalNamedType('crlNumber', univ.Integer())393    )394 395 396class CrlValidatedID(univ.Sequence):397    componentType = namedtype.NamedTypes(398        namedtype.NamedType('crlHash', OtherHash()),399        namedtype.OptionalNamedType('crlIdentifier', CrlIdentifier())400    )401 402 403class CRLListID(univ.Sequence):404    componentType = namedtype.NamedTypes(405        namedtype.NamedType('crls',406            univ.SequenceOf(componentType=CrlValidatedID()))407    )408 409 410class OcspIdentifier(univ.Sequence):411    componentType = namedtype.NamedTypes(412        namedtype.NamedType('ocspResponderID', ResponderID()),413        namedtype.NamedType('producedAt', useful.GeneralizedTime())414    )415 416 417class OcspResponsesID(univ.Sequence):418    componentType = namedtype.NamedTypes(419        namedtype.NamedType('ocspIdentifier', OcspIdentifier()),420        namedtype.OptionalNamedType('ocspRepHash', OtherHash())421    )422 423 424class OcspListID(univ.Sequence):425    componentType = namedtype.NamedTypes(426        namedtype.NamedType('ocspResponses',427            univ.SequenceOf(componentType=OcspResponsesID()))428    )429 430 431class OtherRevRefType(univ.ObjectIdentifier):432    pass433 434 435class OtherRevRefs(univ.Sequence):436    componentType = namedtype.NamedTypes(437        namedtype.NamedType('otherRevRefType', OtherRevRefType()),438        namedtype.NamedType('otherRevRefs', univ.Any(),439            openType=opentype.OpenType('otherRevRefType', otherRevRefMap))440    )441 442 443class CrlOcspRef(univ.Sequence):444    componentType = namedtype.NamedTypes(445        namedtype.OptionalNamedType('crlids',446            CRLListID().subtype(explicitTag=tag.Tag(447                tag.tagClassContext, tag.tagFormatConstructed, 0))),448        namedtype.OptionalNamedType('ocspids',449            OcspListID().subtype(explicitTag=tag.Tag(450                tag.tagClassContext, tag.tagFormatConstructed, 1))),451        namedtype.OptionalNamedType('otherRev',452            OtherRevRefs().subtype(explicitTag=tag.Tag(453                tag.tagClassContext, tag.tagFormatConstructed, 2)))454    )455 456 457class CompleteRevocationRefs(univ.SequenceOf):458    componentType = CrlOcspRef()459 460 461# Certificate Values462 463id_aa_ets_certValues = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.23')464 465 466class CertificateValues(univ.SequenceOf):467    componentType = Certificate()468 469 470# Certificate Revocation Values471 472id_aa_ets_revocationValues = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.24')473 474 475class OtherRevValType(univ.ObjectIdentifier):476    pass477 478 479class OtherRevVals(univ.Sequence):480    componentType = namedtype.NamedTypes(481        namedtype.NamedType('otherRevValType', OtherRevValType()),482        namedtype.NamedType('otherRevVals', univ.Any(),483            openType=opentype.OpenType('otherRevValType', otherRevValMap))484    )485 486 487class RevocationValues(univ.Sequence):488    componentType = namedtype.NamedTypes(489        namedtype.OptionalNamedType('crlVals',490            univ.SequenceOf(componentType=CertificateList()).subtype(491                explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),492        namedtype.OptionalNamedType('ocspVals',493            univ.SequenceOf(componentType=BasicOCSPResponse()).subtype(494                explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),495        namedtype.OptionalNamedType('otherRevVals',496            OtherRevVals().subtype(explicitTag=tag.Tag(497                tag.tagClassContext, tag.tagFormatConstructed, 2)))498    )499 500 501# CAdES-C Timestamp502 503id_aa_ets_escTimeStamp = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.25')504 505 506class ESCTimeStampToken(TimeStampToken):507    pass508 509 510# Time-Stamped Certificates and CRLs511 512id_aa_ets_certCRLTimestamp = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.26')513 514 515class TimestampedCertsCRLs(TimeStampToken):516    pass517 518 519# Archive Timestamp520 521id_aa_ets_archiveTimestampV2 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.48')522 523 524class ArchiveTimeStampToken(TimeStampToken):525    pass526 527 528# Attribute certificate references529 530id_aa_ets_attrCertificateRefs = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.44')531 532 533class AttributeCertificateRefs(univ.SequenceOf):534    componentType = OtherCertID()535 536 537# Attribute revocation references538 539id_aa_ets_attrRevocationRefs = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.45')540 541 542class AttributeRevocationRefs(univ.SequenceOf):543    componentType = CrlOcspRef()544 545 546# Update the sigQualifiersMap547 548_sigQualifiersMapUpdate = {549    id_spq_ets_unotice: SPUserNotice(),550    id_spq_ets_uri: SPuri(),551}552 553sigQualifiersMap.update(_sigQualifiersMapUpdate)554 555 556# Update the CMS Attribute Map in rfc5652.py557 558_cmsAttributesMapUpdate = {559    id_aa_ets_otherSigCert: OtherSigningCertificate(),560    id_aa_ets_sigPolicyId: SignaturePolicy(),561    id_aa_ets_commitmentType: CommitmentTypeIndication(),562    id_aa_ets_signerLocation: SignerLocation(),563    id_aa_signatureTimeStampToken: SignatureTimeStampToken(),564    id_aa_ets_contentTimestamp: ContentTimestamp(),565    id_aa_ets_signerAttr: SignerAttribute(),566    id_aa_ets_certificateRefs: CompleteCertificateRefs(),567    id_aa_ets_revocationRefs: CompleteRevocationRefs(),568    id_aa_ets_certValues: CertificateValues(),569    id_aa_ets_revocationValues: RevocationValues(),570    id_aa_ets_escTimeStamp: ESCTimeStampToken(),571    id_aa_ets_certCRLTimestamp: TimestampedCertsCRLs(),572    id_aa_ets_archiveTimestampV2: ArchiveTimeStampToken(),573    id_aa_ets_attrCertificateRefs: AttributeCertificateRefs(),574    id_aa_ets_attrRevocationRefs: AttributeRevocationRefs(),575}576 577rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)578 
codekingpro/portable-devtools · Team Ai