rfc6010.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. # Modified by Russ Housley to add maps for use with opentypes.
  6. #
  7. # Copyright (c) 2019, Vigil Security, LLC
  8. # License: http://snmplabs.com/pyasn1/license.html
  9. #
  10. # Certificate Extension for CMS Content Constraints (CCC)
  11. #
  12. # ASN.1 source from:
  13. # https://www.rfc-editor.org/rfc/rfc6010.txt
  14. #
  15. from pyasn1.type import constraint
  16. from pyasn1.type import namedtype
  17. from pyasn1.type import namedval
  18. from pyasn1.type import univ
  19. from pyasn1_modules import rfc5280
  20. MAX = float('inf')
  21. AttributeType = rfc5280.AttributeType
  22. AttributeValue = rfc5280.AttributeValue
  23. id_ct_anyContentType = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1.0')
  24. class AttrConstraint(univ.Sequence):
  25. pass
  26. AttrConstraint.componentType = namedtype.NamedTypes(
  27. namedtype.NamedType('attrType', AttributeType()),
  28. namedtype.NamedType('attrValues', univ.SetOf(
  29. componentType=AttributeValue()).subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))
  30. )
  31. class AttrConstraintList(univ.SequenceOf):
  32. pass
  33. AttrConstraintList.componentType = AttrConstraint()
  34. AttrConstraintList.subtypeSpec=constraint.ValueSizeConstraint(1, MAX)
  35. class ContentTypeGeneration(univ.Enumerated):
  36. pass
  37. ContentTypeGeneration.namedValues = namedval.NamedValues(
  38. ('canSource', 0),
  39. ('cannotSource', 1)
  40. )
  41. class ContentTypeConstraint(univ.Sequence):
  42. pass
  43. ContentTypeConstraint.componentType = namedtype.NamedTypes(
  44. namedtype.NamedType('contentType', univ.ObjectIdentifier()),
  45. namedtype.DefaultedNamedType('canSource', ContentTypeGeneration().subtype(value='canSource')),
  46. namedtype.OptionalNamedType('attrConstraints', AttrConstraintList())
  47. )
  48. # CMS Content Constraints (CCC) Extension and Object Identifier
  49. id_pe_cmsContentConstraints = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.18')
  50. class CMSContentConstraints(univ.SequenceOf):
  51. pass
  52. CMSContentConstraints.componentType = ContentTypeConstraint()
  53. CMSContentConstraints.subtypeSpec=constraint.ValueSizeConstraint(1, MAX)
  54. # Map of Certificate Extension OIDs to Extensions
  55. # To be added to the ones that are in rfc5280.py
  56. _certificateExtensionsMap = {
  57. id_pe_cmsContentConstraints: CMSContentConstraints(),
  58. }
  59. rfc5280.certificateExtensionsMap.update(_certificateExtensionsMap)