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.

rfc5914.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # This file is being contributed to pyasn1-modules software.
  2. #
  3. # Created by Russ Housley with assistance from asn1ate v.0.6.0.
  4. #
  5. # Copyright (c) 2019, Vigil Security, LLC
  6. # License: http://snmplabs.com/pyasn1/license.html
  7. #
  8. # Trust Anchor Format
  9. #
  10. # ASN.1 source from:
  11. # https://www.rfc-editor.org/rfc/rfc5914.txt
  12. from pyasn1.type import char
  13. from pyasn1.type import constraint
  14. from pyasn1.type import namedtype
  15. from pyasn1.type import namedval
  16. from pyasn1.type import tag
  17. from pyasn1.type import univ
  18. from pyasn1_modules import rfc5280
  19. MAX = float('inf')
  20. Certificate = rfc5280.Certificate
  21. Name = rfc5280.Name
  22. Extensions = rfc5280.Extensions
  23. SubjectPublicKeyInfo = rfc5280.SubjectPublicKeyInfo
  24. TBSCertificate = rfc5280.TBSCertificate
  25. CertificatePolicies = rfc5280.CertificatePolicies
  26. KeyIdentifier = rfc5280.KeyIdentifier
  27. NameConstraints = rfc5280.NameConstraints
  28. class CertPolicyFlags(univ.BitString):
  29. pass
  30. CertPolicyFlags.namedValues = namedval.NamedValues(
  31. ('inhibitPolicyMapping', 0),
  32. ('requireExplicitPolicy', 1),
  33. ('inhibitAnyPolicy', 2)
  34. )
  35. class CertPathControls(univ.Sequence):
  36. pass
  37. CertPathControls.componentType = namedtype.NamedTypes(
  38. namedtype.NamedType('taName', Name()),
  39. namedtype.OptionalNamedType('certificate', Certificate().subtype(
  40. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  41. namedtype.OptionalNamedType('policySet', CertificatePolicies().subtype(
  42. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  43. namedtype.OptionalNamedType('policyFlags', CertPolicyFlags().subtype(
  44. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  45. namedtype.OptionalNamedType('nameConstr', NameConstraints().subtype(
  46. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
  47. namedtype.OptionalNamedType('pathLenConstraint', univ.Integer().subtype(
  48. subtypeSpec=constraint.ValueRangeConstraint(0, MAX)).subtype(
  49. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
  50. )
  51. class TrustAnchorTitle(char.UTF8String):
  52. pass
  53. TrustAnchorTitle.subtypeSpec = constraint.ValueSizeConstraint(1, 64)
  54. class TrustAnchorInfoVersion(univ.Integer):
  55. pass
  56. TrustAnchorInfoVersion.namedValues = namedval.NamedValues(
  57. ('v1', 1)
  58. )
  59. class TrustAnchorInfo(univ.Sequence):
  60. pass
  61. TrustAnchorInfo.componentType = namedtype.NamedTypes(
  62. namedtype.DefaultedNamedType('version', TrustAnchorInfoVersion().subtype(value='v1')),
  63. namedtype.NamedType('pubKey', SubjectPublicKeyInfo()),
  64. namedtype.NamedType('keyId', KeyIdentifier()),
  65. namedtype.OptionalNamedType('taTitle', TrustAnchorTitle()),
  66. namedtype.OptionalNamedType('certPath', CertPathControls()),
  67. namedtype.OptionalNamedType('exts', Extensions().subtype(explicitTag=tag.Tag(
  68. tag.tagClassContext, tag.tagFormatSimple, 1))),
  69. namedtype.OptionalNamedType('taTitleLangTag', char.UTF8String().subtype(
  70. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
  71. )
  72. class TrustAnchorChoice(univ.Choice):
  73. pass
  74. TrustAnchorChoice.componentType = namedtype.NamedTypes(
  75. namedtype.NamedType('certificate', Certificate()),
  76. namedtype.NamedType('tbsCert', TBSCertificate().subtype(
  77. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  78. namedtype.NamedType('taInfo', TrustAnchorInfo().subtype(
  79. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
  80. )
  81. id_ct_trustAnchorList = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1.34')
  82. class TrustAnchorList(univ.SequenceOf):
  83. pass
  84. TrustAnchorList.componentType = TrustAnchorChoice()
  85. TrustAnchorList.subtypeSpec=constraint.ValueSizeConstraint(1, MAX)