rfc3779.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. # X.509 Extensions for IP Addresses and AS Identifiers
  11. #
  12. # ASN.1 source from:
  13. # https://www.rfc-editor.org/rfc/rfc3779.txt
  14. #
  15. from pyasn1.type import constraint
  16. from pyasn1.type import namedtype
  17. from pyasn1.type import tag
  18. from pyasn1.type import univ
  19. from pyasn1_modules import rfc5280
  20. # IP Address Delegation Extension
  21. id_pe_ipAddrBlocks = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.7')
  22. class IPAddress(univ.BitString):
  23. pass
  24. class IPAddressRange(univ.Sequence):
  25. pass
  26. IPAddressRange.componentType = namedtype.NamedTypes(
  27. namedtype.NamedType('min', IPAddress()),
  28. namedtype.NamedType('max', IPAddress())
  29. )
  30. class IPAddressOrRange(univ.Choice):
  31. pass
  32. IPAddressOrRange.componentType = namedtype.NamedTypes(
  33. namedtype.NamedType('addressPrefix', IPAddress()),
  34. namedtype.NamedType('addressRange', IPAddressRange())
  35. )
  36. class IPAddressChoice(univ.Choice):
  37. pass
  38. IPAddressChoice.componentType = namedtype.NamedTypes(
  39. namedtype.NamedType('inherit', univ.Null()),
  40. namedtype.NamedType('addressesOrRanges', univ.SequenceOf(
  41. componentType=IPAddressOrRange())
  42. )
  43. )
  44. class IPAddressFamily(univ.Sequence):
  45. pass
  46. IPAddressFamily.componentType = namedtype.NamedTypes(
  47. namedtype.NamedType('addressFamily', univ.OctetString().subtype(
  48. subtypeSpec=constraint.ValueSizeConstraint(2, 3))),
  49. namedtype.NamedType('ipAddressChoice', IPAddressChoice())
  50. )
  51. class IPAddrBlocks(univ.SequenceOf):
  52. pass
  53. IPAddrBlocks.componentType = IPAddressFamily()
  54. # Autonomous System Identifier Delegation Extension
  55. id_pe_autonomousSysIds = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.8')
  56. class ASId(univ.Integer):
  57. pass
  58. class ASRange(univ.Sequence):
  59. pass
  60. ASRange.componentType = namedtype.NamedTypes(
  61. namedtype.NamedType('min', ASId()),
  62. namedtype.NamedType('max', ASId())
  63. )
  64. class ASIdOrRange(univ.Choice):
  65. pass
  66. ASIdOrRange.componentType = namedtype.NamedTypes(
  67. namedtype.NamedType('id', ASId()),
  68. namedtype.NamedType('range', ASRange())
  69. )
  70. class ASIdentifierChoice(univ.Choice):
  71. pass
  72. ASIdentifierChoice.componentType = namedtype.NamedTypes(
  73. namedtype.NamedType('inherit', univ.Null()),
  74. namedtype.NamedType('asIdsOrRanges', univ.SequenceOf(
  75. componentType=ASIdOrRange())
  76. )
  77. )
  78. class ASIdentifiers(univ.Sequence):
  79. pass
  80. ASIdentifiers.componentType = namedtype.NamedTypes(
  81. namedtype.OptionalNamedType('asnum', ASIdentifierChoice().subtype(
  82. explicitTag=tag.Tag(tag.tagClassContext,
  83. tag.tagFormatConstructed, 0))),
  84. namedtype.OptionalNamedType('rdi', ASIdentifierChoice().subtype(
  85. explicitTag=tag.Tag(tag.tagClassContext,
  86. tag.tagFormatConstructed, 1)))
  87. )
  88. # Map of Certificate Extension OIDs to Extensions is added to the
  89. # ones that are in rfc5280.py
  90. _certificateExtensionsMapUpdate = {
  91. id_pe_ipAddrBlocks: IPAddrBlocks(),
  92. id_pe_autonomousSysIds: ASIdentifiers(),
  93. }
  94. rfc5280.certificateExtensionsMap.update(_certificateExtensionsMapUpdate)