You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc6211.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. # CMS Algorithm Identifier Protection Attribute
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc6211.txt
  13. #
  14. from pyasn1.type import constraint
  15. from pyasn1.type import namedtype
  16. from pyasn1.type import tag
  17. from pyasn1.type import univ
  18. from pyasn1_modules import rfc5652
  19. # Imports from RFC 5652
  20. DigestAlgorithmIdentifier = rfc5652.DigestAlgorithmIdentifier
  21. MessageAuthenticationCodeAlgorithm = rfc5652.MessageAuthenticationCodeAlgorithm
  22. SignatureAlgorithmIdentifier = rfc5652.SignatureAlgorithmIdentifier
  23. # CMS Algorithm Protection attribute
  24. id_aa_cmsAlgorithmProtect = univ.ObjectIdentifier('1.2.840.113549.1.9.52')
  25. class CMSAlgorithmProtection(univ.Sequence):
  26. pass
  27. CMSAlgorithmProtection.componentType = namedtype.NamedTypes(
  28. namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
  29. namedtype.OptionalNamedType('signatureAlgorithm',
  30. SignatureAlgorithmIdentifier().subtype(
  31. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  32. namedtype.OptionalNamedType('macAlgorithm',
  33. MessageAuthenticationCodeAlgorithm().subtype(
  34. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
  35. )
  36. CMSAlgorithmProtection.subtypeSpec = constraint.ConstraintsUnion(
  37. constraint.WithComponentsConstraint(
  38. ('signatureAlgorithm', constraint.ComponentPresentConstraint()),
  39. ('macAlgorithm', constraint.ComponentAbsentConstraint())),
  40. constraint.WithComponentsConstraint(
  41. ('signatureAlgorithm', constraint.ComponentAbsentConstraint()),
  42. ('macAlgorithm', constraint.ComponentPresentConstraint()))
  43. )
  44. aa_cmsAlgorithmProtection = rfc5652.Attribute()
  45. aa_cmsAlgorithmProtection['attrType'] = id_aa_cmsAlgorithmProtect
  46. aa_cmsAlgorithmProtection['attrValues'][0] = CMSAlgorithmProtection()
  47. # Map of Attribute Type OIDs to Attributes are
  48. # added to the ones that are in rfc5652.py
  49. _cmsAttributesMapUpdate = {
  50. id_aa_cmsAlgorithmProtect: CMSAlgorithmProtection(),
  51. }
  52. rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)