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.

rfc3709.py 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. # Logotypes in X.509 Certificates
  11. #
  12. # ASN.1 source from:
  13. # https://www.rfc-editor.org/rfc/rfc3709.txt
  14. #
  15. from pyasn1.type import char
  16. from pyasn1.type import constraint
  17. from pyasn1.type import namedtype
  18. from pyasn1.type import namedval
  19. from pyasn1.type import tag
  20. from pyasn1.type import univ
  21. from pyasn1_modules import rfc5280
  22. MAX = float('inf')
  23. class HashAlgAndValue(univ.Sequence):
  24. pass
  25. HashAlgAndValue.componentType = namedtype.NamedTypes(
  26. namedtype.NamedType('hashAlg', rfc5280.AlgorithmIdentifier()),
  27. namedtype.NamedType('hashValue', univ.OctetString())
  28. )
  29. class LogotypeDetails(univ.Sequence):
  30. pass
  31. LogotypeDetails.componentType = namedtype.NamedTypes(
  32. namedtype.NamedType('mediaType', char.IA5String()),
  33. namedtype.NamedType('logotypeHash', univ.SequenceOf(
  34. componentType=HashAlgAndValue()).subtype(
  35. sizeSpec=constraint.ValueSizeConstraint(1, MAX))),
  36. namedtype.NamedType('logotypeURI', univ.SequenceOf(
  37. componentType=char.IA5String()).subtype(
  38. sizeSpec=constraint.ValueSizeConstraint(1, MAX)))
  39. )
  40. class LogotypeAudioInfo(univ.Sequence):
  41. pass
  42. LogotypeAudioInfo.componentType = namedtype.NamedTypes(
  43. namedtype.NamedType('fileSize', univ.Integer()),
  44. namedtype.NamedType('playTime', univ.Integer()),
  45. namedtype.NamedType('channels', univ.Integer()),
  46. namedtype.OptionalNamedType('sampleRate', univ.Integer().subtype(
  47. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
  48. namedtype.OptionalNamedType('language', char.IA5String().subtype(
  49. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
  50. )
  51. class LogotypeAudio(univ.Sequence):
  52. pass
  53. LogotypeAudio.componentType = namedtype.NamedTypes(
  54. namedtype.NamedType('audioDetails', LogotypeDetails()),
  55. namedtype.OptionalNamedType('audioInfo', LogotypeAudioInfo())
  56. )
  57. class LogotypeImageType(univ.Integer):
  58. pass
  59. LogotypeImageType.namedValues = namedval.NamedValues(
  60. ('grayScale', 0),
  61. ('color', 1)
  62. )
  63. class LogotypeImageResolution(univ.Choice):
  64. pass
  65. LogotypeImageResolution.componentType = namedtype.NamedTypes(
  66. namedtype.NamedType('numBits',
  67. univ.Integer().subtype(implicitTag=tag.Tag(
  68. tag.tagClassContext, tag.tagFormatSimple, 1))),
  69. namedtype.NamedType('tableSize',
  70. univ.Integer().subtype(implicitTag=tag.Tag(
  71. tag.tagClassContext, tag.tagFormatSimple, 2)))
  72. )
  73. class LogotypeImageInfo(univ.Sequence):
  74. pass
  75. LogotypeImageInfo.componentType = namedtype.NamedTypes(
  76. namedtype.DefaultedNamedType('type', LogotypeImageType().subtype(
  77. implicitTag=tag.Tag(tag.tagClassContext,
  78. tag.tagFormatSimple, 0)).subtype(value='color')),
  79. namedtype.NamedType('fileSize', univ.Integer()),
  80. namedtype.NamedType('xSize', univ.Integer()),
  81. namedtype.NamedType('ySize', univ.Integer()),
  82. namedtype.OptionalNamedType('resolution', LogotypeImageResolution()),
  83. namedtype.OptionalNamedType('language', char.IA5String().subtype(
  84. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
  85. )
  86. class LogotypeImage(univ.Sequence):
  87. pass
  88. LogotypeImage.componentType = namedtype.NamedTypes(
  89. namedtype.NamedType('imageDetails', LogotypeDetails()),
  90. namedtype.OptionalNamedType('imageInfo', LogotypeImageInfo())
  91. )
  92. class LogotypeData(univ.Sequence):
  93. pass
  94. LogotypeData.componentType = namedtype.NamedTypes(
  95. namedtype.OptionalNamedType('image', univ.SequenceOf(
  96. componentType=LogotypeImage())),
  97. namedtype.OptionalNamedType('audio', univ.SequenceOf(
  98. componentType=LogotypeAudio()).subtype(
  99. implicitTag=tag.Tag(tag.tagClassContext,
  100. tag.tagFormatSimple, 1)))
  101. )
  102. class LogotypeReference(univ.Sequence):
  103. pass
  104. LogotypeReference.componentType = namedtype.NamedTypes(
  105. namedtype.NamedType('refStructHash', univ.SequenceOf(
  106. componentType=HashAlgAndValue()).subtype(
  107. sizeSpec=constraint.ValueSizeConstraint(1, MAX))),
  108. namedtype.NamedType('refStructURI', univ.SequenceOf(
  109. componentType=char.IA5String()).subtype(
  110. sizeSpec=constraint.ValueSizeConstraint(1, MAX)))
  111. )
  112. class LogotypeInfo(univ.Choice):
  113. pass
  114. LogotypeInfo.componentType = namedtype.NamedTypes(
  115. namedtype.NamedType('direct',
  116. LogotypeData().subtype(implicitTag=tag.Tag(tag.tagClassContext,
  117. tag.tagFormatConstructed, 0))),
  118. namedtype.NamedType('indirect', LogotypeReference().subtype(
  119. implicitTag=tag.Tag(tag.tagClassContext,
  120. tag.tagFormatConstructed, 1)))
  121. )
  122. # Other logotype type and associated object identifiers
  123. id_logo_background = univ.ObjectIdentifier('1.3.6.1.5.5.7.20.2')
  124. id_logo_loyalty = univ.ObjectIdentifier('1.3.6.1.5.5.7.20.1')
  125. class OtherLogotypeInfo(univ.Sequence):
  126. pass
  127. OtherLogotypeInfo.componentType = namedtype.NamedTypes(
  128. namedtype.NamedType('logotypeType', univ.ObjectIdentifier()),
  129. namedtype.NamedType('info', LogotypeInfo())
  130. )
  131. # Logotype Certificate Extension
  132. id_pe_logotype = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.12')
  133. class LogotypeExtn(univ.Sequence):
  134. pass
  135. LogotypeExtn.componentType = namedtype.NamedTypes(
  136. namedtype.OptionalNamedType('communityLogos', univ.SequenceOf(
  137. componentType=LogotypeInfo()).subtype(
  138. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  139. namedtype.OptionalNamedType('issuerLogo', LogotypeInfo().subtype(
  140. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
  141. namedtype.OptionalNamedType('subjectLogo', LogotypeInfo().subtype(
  142. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
  143. namedtype.OptionalNamedType('otherLogos', univ.SequenceOf(
  144. componentType=OtherLogotypeInfo()).subtype(explicitTag=tag.Tag(
  145. tag.tagClassContext, tag.tagFormatSimple, 3)))
  146. )
  147. # Map of Certificate Extension OIDs to Extensions added to the
  148. # ones that are in rfc5280.py
  149. _certificateExtensionsMapUpdate = {
  150. id_pe_logotype: LogotypeExtn(),
  151. }
  152. rfc5280.certificateExtensionsMap.update(_certificateExtensionsMapUpdate)