rfc2459.py 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Updated by Russ Housley to resolve the TODO regarding the Certificate
  5. # Policies Certificate Extension.
  6. #
  7. # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
  8. # License: http://snmplabs.com/pyasn1/license.html
  9. #
  10. # X.509 message syntax
  11. #
  12. # ASN.1 source from:
  13. # http://www.trl.ibm.com/projects/xml/xss4j/data/asn1/grammars/x509.asn
  14. # http://www.ietf.org/rfc/rfc2459.txt
  15. #
  16. # Sample captures from:
  17. # http://wiki.wireshark.org/SampleCaptures/
  18. #
  19. from pyasn1.type import char
  20. from pyasn1.type import constraint
  21. from pyasn1.type import namedtype
  22. from pyasn1.type import namedval
  23. from pyasn1.type import opentype
  24. from pyasn1.type import tag
  25. from pyasn1.type import univ
  26. from pyasn1.type import useful
  27. MAX = float('inf')
  28. #
  29. # PKIX1Explicit88
  30. #
  31. # Upper Bounds
  32. ub_name = univ.Integer(32768)
  33. ub_common_name = univ.Integer(64)
  34. ub_locality_name = univ.Integer(128)
  35. ub_state_name = univ.Integer(128)
  36. ub_organization_name = univ.Integer(64)
  37. ub_organizational_unit_name = univ.Integer(64)
  38. ub_title = univ.Integer(64)
  39. ub_match = univ.Integer(128)
  40. ub_emailaddress_length = univ.Integer(128)
  41. ub_common_name_length = univ.Integer(64)
  42. ub_country_name_alpha_length = univ.Integer(2)
  43. ub_country_name_numeric_length = univ.Integer(3)
  44. ub_domain_defined_attributes = univ.Integer(4)
  45. ub_domain_defined_attribute_type_length = univ.Integer(8)
  46. ub_domain_defined_attribute_value_length = univ.Integer(128)
  47. ub_domain_name_length = univ.Integer(16)
  48. ub_extension_attributes = univ.Integer(256)
  49. ub_e163_4_number_length = univ.Integer(15)
  50. ub_e163_4_sub_address_length = univ.Integer(40)
  51. ub_generation_qualifier_length = univ.Integer(3)
  52. ub_given_name_length = univ.Integer(16)
  53. ub_initials_length = univ.Integer(5)
  54. ub_integer_options = univ.Integer(256)
  55. ub_numeric_user_id_length = univ.Integer(32)
  56. ub_organization_name_length = univ.Integer(64)
  57. ub_organizational_unit_name_length = univ.Integer(32)
  58. ub_organizational_units = univ.Integer(4)
  59. ub_pds_name_length = univ.Integer(16)
  60. ub_pds_parameter_length = univ.Integer(30)
  61. ub_pds_physical_address_lines = univ.Integer(6)
  62. ub_postal_code_length = univ.Integer(16)
  63. ub_surname_length = univ.Integer(40)
  64. ub_terminal_id_length = univ.Integer(24)
  65. ub_unformatted_address_length = univ.Integer(180)
  66. ub_x121_address_length = univ.Integer(16)
  67. class UniversalString(char.UniversalString):
  68. pass
  69. class BMPString(char.BMPString):
  70. pass
  71. class UTF8String(char.UTF8String):
  72. pass
  73. id_pkix = univ.ObjectIdentifier('1.3.6.1.5.5.7')
  74. id_pe = univ.ObjectIdentifier('1.3.6.1.5.5.7.1')
  75. id_qt = univ.ObjectIdentifier('1.3.6.1.5.5.7.2')
  76. id_kp = univ.ObjectIdentifier('1.3.6.1.5.5.7.3')
  77. id_ad = univ.ObjectIdentifier('1.3.6.1.5.5.7.48')
  78. id_qt_cps = univ.ObjectIdentifier('1.3.6.1.5.5.7.2.1')
  79. id_qt_unotice = univ.ObjectIdentifier('1.3.6.1.5.5.7.2.2')
  80. id_ad_ocsp = univ.ObjectIdentifier('1.3.6.1.5.5.7.48.1')
  81. id_ad_caIssuers = univ.ObjectIdentifier('1.3.6.1.5.5.7.48.2')
  82. id_at = univ.ObjectIdentifier('2.5.4')
  83. id_at_name = univ.ObjectIdentifier('2.5.4.41')
  84. # preserve misspelled variable for compatibility
  85. id_at_sutname = id_at_surname = univ.ObjectIdentifier('2.5.4.4')
  86. id_at_givenName = univ.ObjectIdentifier('2.5.4.42')
  87. id_at_initials = univ.ObjectIdentifier('2.5.4.43')
  88. id_at_generationQualifier = univ.ObjectIdentifier('2.5.4.44')
  89. class X520name(univ.Choice):
  90. componentType = namedtype.NamedTypes(
  91. namedtype.NamedType('teletexString',
  92. char.TeletexString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_name))),
  93. namedtype.NamedType('printableString',
  94. char.PrintableString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_name))),
  95. namedtype.NamedType('universalString',
  96. char.UniversalString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_name))),
  97. namedtype.NamedType('utf8String',
  98. char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_name))),
  99. namedtype.NamedType('bmpString',
  100. char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_name)))
  101. )
  102. id_at_commonName = univ.ObjectIdentifier('2.5.4.3')
  103. class X520CommonName(univ.Choice):
  104. componentType = namedtype.NamedTypes(
  105. namedtype.NamedType('teletexString', char.TeletexString().subtype(
  106. subtypeSpec=constraint.ValueSizeConstraint(1, ub_common_name))),
  107. namedtype.NamedType('printableString', char.PrintableString().subtype(
  108. subtypeSpec=constraint.ValueSizeConstraint(1, ub_common_name))),
  109. namedtype.NamedType('universalString', char.UniversalString().subtype(
  110. subtypeSpec=constraint.ValueSizeConstraint(1, ub_common_name))),
  111. namedtype.NamedType('utf8String',
  112. char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_common_name))),
  113. namedtype.NamedType('bmpString',
  114. char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_common_name)))
  115. )
  116. id_at_localityName = univ.ObjectIdentifier('2.5.4.7')
  117. class X520LocalityName(univ.Choice):
  118. componentType = namedtype.NamedTypes(
  119. namedtype.NamedType('teletexString', char.TeletexString().subtype(
  120. subtypeSpec=constraint.ValueSizeConstraint(1, ub_locality_name))),
  121. namedtype.NamedType('printableString', char.PrintableString().subtype(
  122. subtypeSpec=constraint.ValueSizeConstraint(1, ub_locality_name))),
  123. namedtype.NamedType('universalString', char.UniversalString().subtype(
  124. subtypeSpec=constraint.ValueSizeConstraint(1, ub_locality_name))),
  125. namedtype.NamedType('utf8String',
  126. char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_locality_name))),
  127. namedtype.NamedType('bmpString',
  128. char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_locality_name)))
  129. )
  130. id_at_stateOrProvinceName = univ.ObjectIdentifier('2.5.4.8')
  131. class X520StateOrProvinceName(univ.Choice):
  132. componentType = namedtype.NamedTypes(
  133. namedtype.NamedType('teletexString',
  134. char.TeletexString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_state_name))),
  135. namedtype.NamedType('printableString', char.PrintableString().subtype(
  136. subtypeSpec=constraint.ValueSizeConstraint(1, ub_state_name))),
  137. namedtype.NamedType('universalString', char.UniversalString().subtype(
  138. subtypeSpec=constraint.ValueSizeConstraint(1, ub_state_name))),
  139. namedtype.NamedType('utf8String',
  140. char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_state_name))),
  141. namedtype.NamedType('bmpString',
  142. char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_state_name)))
  143. )
  144. id_at_organizationName = univ.ObjectIdentifier('2.5.4.10')
  145. class X520OrganizationName(univ.Choice):
  146. componentType = namedtype.NamedTypes(
  147. namedtype.NamedType('teletexString', char.TeletexString().subtype(
  148. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organization_name))),
  149. namedtype.NamedType('printableString', char.PrintableString().subtype(
  150. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organization_name))),
  151. namedtype.NamedType('universalString', char.UniversalString().subtype(
  152. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organization_name))),
  153. namedtype.NamedType('utf8String', char.UTF8String().subtype(
  154. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organization_name))),
  155. namedtype.NamedType('bmpString', char.BMPString().subtype(
  156. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organization_name)))
  157. )
  158. id_at_organizationalUnitName = univ.ObjectIdentifier('2.5.4.11')
  159. class X520OrganizationalUnitName(univ.Choice):
  160. componentType = namedtype.NamedTypes(
  161. namedtype.NamedType('teletexString', char.TeletexString().subtype(
  162. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organizational_unit_name))),
  163. namedtype.NamedType('printableString', char.PrintableString().subtype(
  164. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organizational_unit_name))),
  165. namedtype.NamedType('universalString', char.UniversalString().subtype(
  166. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organizational_unit_name))),
  167. namedtype.NamedType('utf8String', char.UTF8String().subtype(
  168. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organizational_unit_name))),
  169. namedtype.NamedType('bmpString', char.BMPString().subtype(
  170. subtypeSpec=constraint.ValueSizeConstraint(1, ub_organizational_unit_name)))
  171. )
  172. id_at_title = univ.ObjectIdentifier('2.5.4.12')
  173. class X520Title(univ.Choice):
  174. componentType = namedtype.NamedTypes(
  175. namedtype.NamedType('teletexString',
  176. char.TeletexString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_title))),
  177. namedtype.NamedType('printableString',
  178. char.PrintableString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_title))),
  179. namedtype.NamedType('universalString',
  180. char.UniversalString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_title))),
  181. namedtype.NamedType('utf8String',
  182. char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_title))),
  183. namedtype.NamedType('bmpString',
  184. char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, ub_title)))
  185. )
  186. id_at_dnQualifier = univ.ObjectIdentifier('2.5.4.46')
  187. class X520dnQualifier(char.PrintableString):
  188. pass
  189. id_at_countryName = univ.ObjectIdentifier('2.5.4.6')
  190. class X520countryName(char.PrintableString):
  191. subtypeSpec = char.PrintableString.subtypeSpec + constraint.ValueSizeConstraint(2, 2)
  192. pkcs_9 = univ.ObjectIdentifier('1.2.840.113549.1.9')
  193. emailAddress = univ.ObjectIdentifier('1.2.840.113549.1.9.1')
  194. class Pkcs9email(char.IA5String):
  195. subtypeSpec = char.IA5String.subtypeSpec + constraint.ValueSizeConstraint(1, ub_emailaddress_length)
  196. # ----
  197. class DSAPrivateKey(univ.Sequence):
  198. """PKIX compliant DSA private key structure"""
  199. componentType = namedtype.NamedTypes(
  200. namedtype.NamedType('version', univ.Integer(namedValues=namedval.NamedValues(('v1', 0)))),
  201. namedtype.NamedType('p', univ.Integer()),
  202. namedtype.NamedType('q', univ.Integer()),
  203. namedtype.NamedType('g', univ.Integer()),
  204. namedtype.NamedType('public', univ.Integer()),
  205. namedtype.NamedType('private', univ.Integer())
  206. )
  207. # ----
  208. class DirectoryString(univ.Choice):
  209. componentType = namedtype.NamedTypes(
  210. namedtype.NamedType('teletexString',
  211. char.TeletexString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
  212. namedtype.NamedType('printableString',
  213. char.PrintableString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
  214. namedtype.NamedType('universalString',
  215. char.UniversalString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
  216. namedtype.NamedType('utf8String',
  217. char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
  218. namedtype.NamedType('bmpString', char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
  219. namedtype.NamedType('ia5String', char.IA5String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))
  220. # hm, this should not be here!? XXX
  221. )
  222. # certificate and CRL specific structures begin here
  223. class AlgorithmIdentifier(univ.Sequence):
  224. componentType = namedtype.NamedTypes(
  225. namedtype.NamedType('algorithm', univ.ObjectIdentifier()),
  226. namedtype.OptionalNamedType('parameters', univ.Any())
  227. )
  228. # Algorithm OIDs and parameter structures
  229. pkcs_1 = univ.ObjectIdentifier('1.2.840.113549.1.1')
  230. rsaEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.1')
  231. md2WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.2')
  232. md5WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.4')
  233. sha1WithRSAEncryption = univ.ObjectIdentifier('1.2.840.113549.1.1.5')
  234. id_dsa_with_sha1 = univ.ObjectIdentifier('1.2.840.10040.4.3')
  235. class Dss_Sig_Value(univ.Sequence):
  236. componentType = namedtype.NamedTypes(
  237. namedtype.NamedType('r', univ.Integer()),
  238. namedtype.NamedType('s', univ.Integer())
  239. )
  240. dhpublicnumber = univ.ObjectIdentifier('1.2.840.10046.2.1')
  241. class ValidationParms(univ.Sequence):
  242. componentType = namedtype.NamedTypes(
  243. namedtype.NamedType('seed', univ.BitString()),
  244. namedtype.NamedType('pgenCounter', univ.Integer())
  245. )
  246. class DomainParameters(univ.Sequence):
  247. componentType = namedtype.NamedTypes(
  248. namedtype.NamedType('p', univ.Integer()),
  249. namedtype.NamedType('g', univ.Integer()),
  250. namedtype.NamedType('q', univ.Integer()),
  251. namedtype.NamedType('j', univ.Integer()),
  252. namedtype.OptionalNamedType('validationParms', ValidationParms())
  253. )
  254. id_dsa = univ.ObjectIdentifier('1.2.840.10040.4.1')
  255. class Dss_Parms(univ.Sequence):
  256. componentType = namedtype.NamedTypes(
  257. namedtype.NamedType('p', univ.Integer()),
  258. namedtype.NamedType('q', univ.Integer()),
  259. namedtype.NamedType('g', univ.Integer())
  260. )
  261. # x400 address syntax starts here
  262. teletex_domain_defined_attributes = univ.Integer(6)
  263. class TeletexDomainDefinedAttribute(univ.Sequence):
  264. componentType = namedtype.NamedTypes(
  265. namedtype.NamedType('type', char.TeletexString().subtype(
  266. subtypeSpec=constraint.ValueSizeConstraint(1, ub_domain_defined_attribute_type_length))),
  267. namedtype.NamedType('value', char.TeletexString())
  268. )
  269. class TeletexDomainDefinedAttributes(univ.SequenceOf):
  270. componentType = TeletexDomainDefinedAttribute()
  271. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, ub_domain_defined_attributes)
  272. terminal_type = univ.Integer(23)
  273. class TerminalType(univ.Integer):
  274. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(0, ub_integer_options)
  275. namedValues = namedval.NamedValues(
  276. ('telex', 3),
  277. ('teletelex', 4),
  278. ('g3-facsimile', 5),
  279. ('g4-facsimile', 6),
  280. ('ia5-terminal', 7),
  281. ('videotex', 8)
  282. )
  283. class PresentationAddress(univ.Sequence):
  284. componentType = namedtype.NamedTypes(
  285. namedtype.OptionalNamedType('pSelector', univ.OctetString().subtype(
  286. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  287. namedtype.OptionalNamedType('sSelector', univ.OctetString().subtype(
  288. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  289. namedtype.OptionalNamedType('tSelector', univ.OctetString().subtype(
  290. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  291. namedtype.OptionalNamedType('nAddresses', univ.SetOf(componentType=univ.OctetString()).subtype(
  292. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3),
  293. subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
  294. )
  295. extended_network_address = univ.Integer(22)
  296. class E163_4_address(univ.Sequence):
  297. componentType = namedtype.NamedTypes(
  298. namedtype.NamedType('number', char.NumericString().subtype(
  299. subtypeSpec=constraint.ValueSizeConstraint(1, ub_e163_4_number_length),
  300. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  301. namedtype.OptionalNamedType('sub-address', char.NumericString().subtype(
  302. subtypeSpec=constraint.ValueSizeConstraint(1, ub_e163_4_sub_address_length),
  303. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  304. )
  305. class ExtendedNetworkAddress(univ.Choice):
  306. componentType = namedtype.NamedTypes(
  307. namedtype.NamedType('e163-4-address', E163_4_address()),
  308. namedtype.NamedType('psap-address', PresentationAddress().subtype(
  309. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
  310. )
  311. class PDSParameter(univ.Set):
  312. componentType = namedtype.NamedTypes(
  313. namedtype.OptionalNamedType('printable-string', char.PrintableString().subtype(
  314. subtypeSpec=constraint.ValueSizeConstraint(1, ub_pds_parameter_length))),
  315. namedtype.OptionalNamedType('teletex-string', char.TeletexString().subtype(
  316. subtypeSpec=constraint.ValueSizeConstraint(1, ub_pds_parameter_length)))
  317. )
  318. local_postal_attributes = univ.Integer(21)
  319. class LocalPostalAttributes(PDSParameter):
  320. pass
  321. class UniquePostalName(PDSParameter):
  322. pass
  323. unique_postal_name = univ.Integer(20)
  324. poste_restante_address = univ.Integer(19)
  325. class PosteRestanteAddress(PDSParameter):
  326. pass
  327. post_office_box_address = univ.Integer(18)
  328. class PostOfficeBoxAddress(PDSParameter):
  329. pass
  330. street_address = univ.Integer(17)
  331. class StreetAddress(PDSParameter):
  332. pass
  333. class UnformattedPostalAddress(univ.Set):
  334. componentType = namedtype.NamedTypes(
  335. namedtype.OptionalNamedType('printable-address', univ.SequenceOf(componentType=char.PrintableString().subtype(
  336. subtypeSpec=constraint.ValueSizeConstraint(1, ub_pds_parameter_length)).subtype(
  337. subtypeSpec=constraint.ValueSizeConstraint(1, ub_pds_physical_address_lines)))),
  338. namedtype.OptionalNamedType('teletex-string', char.TeletexString().subtype(
  339. subtypeSpec=constraint.ValueSizeConstraint(1, ub_unformatted_address_length)))
  340. )
  341. physical_delivery_office_name = univ.Integer(10)
  342. class PhysicalDeliveryOfficeName(PDSParameter):
  343. pass
  344. physical_delivery_office_number = univ.Integer(11)
  345. class PhysicalDeliveryOfficeNumber(PDSParameter):
  346. pass
  347. extension_OR_address_components = univ.Integer(12)
  348. class ExtensionORAddressComponents(PDSParameter):
  349. pass
  350. physical_delivery_personal_name = univ.Integer(13)
  351. class PhysicalDeliveryPersonalName(PDSParameter):
  352. pass
  353. physical_delivery_organization_name = univ.Integer(14)
  354. class PhysicalDeliveryOrganizationName(PDSParameter):
  355. pass
  356. extension_physical_delivery_address_components = univ.Integer(15)
  357. class ExtensionPhysicalDeliveryAddressComponents(PDSParameter):
  358. pass
  359. unformatted_postal_address = univ.Integer(16)
  360. postal_code = univ.Integer(9)
  361. class PostalCode(univ.Choice):
  362. componentType = namedtype.NamedTypes(
  363. namedtype.NamedType('numeric-code', char.NumericString().subtype(
  364. subtypeSpec=constraint.ValueSizeConstraint(1, ub_postal_code_length))),
  365. namedtype.NamedType('printable-code', char.PrintableString().subtype(
  366. subtypeSpec=constraint.ValueSizeConstraint(1, ub_postal_code_length)))
  367. )
  368. class PhysicalDeliveryCountryName(univ.Choice):
  369. componentType = namedtype.NamedTypes(
  370. namedtype.NamedType('x121-dcc-code', char.NumericString().subtype(
  371. subtypeSpec=constraint.ValueSizeConstraint(ub_country_name_numeric_length,
  372. ub_country_name_numeric_length))),
  373. namedtype.NamedType('iso-3166-alpha2-code', char.PrintableString().subtype(
  374. subtypeSpec=constraint.ValueSizeConstraint(ub_country_name_alpha_length, ub_country_name_alpha_length)))
  375. )
  376. class PDSName(char.PrintableString):
  377. subtypeSpec = char.PrintableString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_pds_name_length)
  378. physical_delivery_country_name = univ.Integer(8)
  379. class TeletexOrganizationalUnitName(char.TeletexString):
  380. subtypeSpec = char.TeletexString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_organizational_unit_name_length)
  381. pds_name = univ.Integer(7)
  382. teletex_organizational_unit_names = univ.Integer(5)
  383. class TeletexOrganizationalUnitNames(univ.SequenceOf):
  384. componentType = TeletexOrganizationalUnitName()
  385. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, ub_organizational_units)
  386. teletex_personal_name = univ.Integer(4)
  387. class TeletexPersonalName(univ.Set):
  388. componentType = namedtype.NamedTypes(
  389. namedtype.NamedType('surname', char.TeletexString().subtype(
  390. subtypeSpec=constraint.ValueSizeConstraint(1, ub_surname_length),
  391. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  392. namedtype.OptionalNamedType('given-name', char.TeletexString().subtype(
  393. subtypeSpec=constraint.ValueSizeConstraint(1, ub_given_name_length),
  394. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  395. namedtype.OptionalNamedType('initials', char.TeletexString().subtype(
  396. subtypeSpec=constraint.ValueSizeConstraint(1, ub_initials_length),
  397. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  398. namedtype.OptionalNamedType('generation-qualifier', char.TeletexString().subtype(
  399. subtypeSpec=constraint.ValueSizeConstraint(1, ub_generation_qualifier_length),
  400. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))
  401. )
  402. teletex_organization_name = univ.Integer(3)
  403. class TeletexOrganizationName(char.TeletexString):
  404. subtypeSpec = char.TeletexString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_organization_name_length)
  405. teletex_common_name = univ.Integer(2)
  406. class TeletexCommonName(char.TeletexString):
  407. subtypeSpec = char.TeletexString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_common_name_length)
  408. class CommonName(char.PrintableString):
  409. subtypeSpec = char.PrintableString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_common_name_length)
  410. common_name = univ.Integer(1)
  411. class ExtensionAttribute(univ.Sequence):
  412. componentType = namedtype.NamedTypes(
  413. namedtype.NamedType('extension-attribute-type', univ.Integer().subtype(
  414. subtypeSpec=constraint.ValueSizeConstraint(0, ub_extension_attributes),
  415. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  416. namedtype.NamedType('extension-attribute-value',
  417. univ.Any().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  418. )
  419. class ExtensionAttributes(univ.SetOf):
  420. componentType = ExtensionAttribute()
  421. sizeSpec = univ.SetOf.sizeSpec + constraint.ValueSizeConstraint(1, ub_extension_attributes)
  422. class BuiltInDomainDefinedAttribute(univ.Sequence):
  423. componentType = namedtype.NamedTypes(
  424. namedtype.NamedType('type', char.PrintableString().subtype(
  425. subtypeSpec=constraint.ValueSizeConstraint(1, ub_domain_defined_attribute_type_length))),
  426. namedtype.NamedType('value', char.PrintableString().subtype(
  427. subtypeSpec=constraint.ValueSizeConstraint(1, ub_domain_defined_attribute_value_length)))
  428. )
  429. class BuiltInDomainDefinedAttributes(univ.SequenceOf):
  430. componentType = BuiltInDomainDefinedAttribute()
  431. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, ub_domain_defined_attributes)
  432. class OrganizationalUnitName(char.PrintableString):
  433. subtypeSpec = char.PrintableString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_organizational_unit_name_length)
  434. class OrganizationalUnitNames(univ.SequenceOf):
  435. componentType = OrganizationalUnitName()
  436. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, ub_organizational_units)
  437. class PersonalName(univ.Set):
  438. componentType = namedtype.NamedTypes(
  439. namedtype.NamedType('surname', char.PrintableString().subtype(
  440. subtypeSpec=constraint.ValueSizeConstraint(1, ub_surname_length),
  441. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  442. namedtype.OptionalNamedType('given-name', char.PrintableString().subtype(
  443. subtypeSpec=constraint.ValueSizeConstraint(1, ub_given_name_length),
  444. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  445. namedtype.OptionalNamedType('initials', char.PrintableString().subtype(
  446. subtypeSpec=constraint.ValueSizeConstraint(1, ub_initials_length),
  447. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  448. namedtype.OptionalNamedType('generation-qualifier', char.PrintableString().subtype(
  449. subtypeSpec=constraint.ValueSizeConstraint(1, ub_generation_qualifier_length),
  450. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))
  451. )
  452. class NumericUserIdentifier(char.NumericString):
  453. subtypeSpec = char.NumericString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_numeric_user_id_length)
  454. class OrganizationName(char.PrintableString):
  455. subtypeSpec = char.PrintableString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_organization_name_length)
  456. class PrivateDomainName(univ.Choice):
  457. componentType = namedtype.NamedTypes(
  458. namedtype.NamedType('numeric', char.NumericString().subtype(
  459. subtypeSpec=constraint.ValueSizeConstraint(1, ub_domain_name_length))),
  460. namedtype.NamedType('printable', char.PrintableString().subtype(
  461. subtypeSpec=constraint.ValueSizeConstraint(1, ub_domain_name_length)))
  462. )
  463. class TerminalIdentifier(char.PrintableString):
  464. subtypeSpec = char.PrintableString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_terminal_id_length)
  465. class X121Address(char.NumericString):
  466. subtypeSpec = char.NumericString.subtypeSpec + constraint.ValueSizeConstraint(1, ub_x121_address_length)
  467. class NetworkAddress(X121Address):
  468. pass
  469. class AdministrationDomainName(univ.Choice):
  470. tagSet = univ.Choice.tagSet.tagExplicitly(
  471. tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 2)
  472. )
  473. componentType = namedtype.NamedTypes(
  474. namedtype.NamedType('numeric', char.NumericString().subtype(
  475. subtypeSpec=constraint.ValueSizeConstraint(0, ub_domain_name_length))),
  476. namedtype.NamedType('printable', char.PrintableString().subtype(
  477. subtypeSpec=constraint.ValueSizeConstraint(0, ub_domain_name_length)))
  478. )
  479. class CountryName(univ.Choice):
  480. tagSet = univ.Choice.tagSet.tagExplicitly(
  481. tag.Tag(tag.tagClassApplication, tag.tagFormatConstructed, 1)
  482. )
  483. componentType = namedtype.NamedTypes(
  484. namedtype.NamedType('x121-dcc-code', char.NumericString().subtype(
  485. subtypeSpec=constraint.ValueSizeConstraint(ub_country_name_numeric_length,
  486. ub_country_name_numeric_length))),
  487. namedtype.NamedType('iso-3166-alpha2-code', char.PrintableString().subtype(
  488. subtypeSpec=constraint.ValueSizeConstraint(ub_country_name_alpha_length, ub_country_name_alpha_length)))
  489. )
  490. class BuiltInStandardAttributes(univ.Sequence):
  491. componentType = namedtype.NamedTypes(
  492. namedtype.OptionalNamedType('country-name', CountryName()),
  493. namedtype.OptionalNamedType('administration-domain-name', AdministrationDomainName()),
  494. namedtype.OptionalNamedType('network-address', NetworkAddress().subtype(
  495. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  496. namedtype.OptionalNamedType('terminal-identifier', TerminalIdentifier().subtype(
  497. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  498. namedtype.OptionalNamedType('private-domain-name', PrivateDomainName().subtype(
  499. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  500. namedtype.OptionalNamedType('organization-name', OrganizationName().subtype(
  501. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
  502. namedtype.OptionalNamedType('numeric-user-identifier', NumericUserIdentifier().subtype(
  503. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))),
  504. namedtype.OptionalNamedType('personal-name', PersonalName().subtype(
  505. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 5))),
  506. namedtype.OptionalNamedType('organizational-unit-names', OrganizationalUnitNames().subtype(
  507. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 6)))
  508. )
  509. class ORAddress(univ.Sequence):
  510. componentType = namedtype.NamedTypes(
  511. namedtype.NamedType('built-in-standard-attributes', BuiltInStandardAttributes()),
  512. namedtype.OptionalNamedType('built-in-domain-defined-attributes', BuiltInDomainDefinedAttributes()),
  513. namedtype.OptionalNamedType('extension-attributes', ExtensionAttributes())
  514. )
  515. #
  516. # PKIX1Implicit88
  517. #
  518. id_ce_invalidityDate = univ.ObjectIdentifier('2.5.29.24')
  519. class InvalidityDate(useful.GeneralizedTime):
  520. pass
  521. id_holdinstruction_none = univ.ObjectIdentifier('2.2.840.10040.2.1')
  522. id_holdinstruction_callissuer = univ.ObjectIdentifier('2.2.840.10040.2.2')
  523. id_holdinstruction_reject = univ.ObjectIdentifier('2.2.840.10040.2.3')
  524. holdInstruction = univ.ObjectIdentifier('2.2.840.10040.2')
  525. id_ce_holdInstructionCode = univ.ObjectIdentifier('2.5.29.23')
  526. class HoldInstructionCode(univ.ObjectIdentifier):
  527. pass
  528. id_ce_cRLReasons = univ.ObjectIdentifier('2.5.29.21')
  529. class CRLReason(univ.Enumerated):
  530. namedValues = namedval.NamedValues(
  531. ('unspecified', 0),
  532. ('keyCompromise', 1),
  533. ('cACompromise', 2),
  534. ('affiliationChanged', 3),
  535. ('superseded', 4),
  536. ('cessationOfOperation', 5),
  537. ('certificateHold', 6),
  538. ('removeFromCRL', 8)
  539. )
  540. id_ce_cRLNumber = univ.ObjectIdentifier('2.5.29.20')
  541. class CRLNumber(univ.Integer):
  542. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(0, MAX)
  543. class BaseCRLNumber(CRLNumber):
  544. pass
  545. id_kp_serverAuth = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.1')
  546. id_kp_clientAuth = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.2')
  547. id_kp_codeSigning = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.3')
  548. id_kp_emailProtection = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.4')
  549. id_kp_ipsecEndSystem = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.5')
  550. id_kp_ipsecTunnel = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.6')
  551. id_kp_ipsecUser = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.7')
  552. id_kp_timeStamping = univ.ObjectIdentifier('1.3.6.1.5.5.7.3.8')
  553. id_pe_authorityInfoAccess = univ.ObjectIdentifier('1.3.6.1.5.5.7.1.1')
  554. id_ce_extKeyUsage = univ.ObjectIdentifier('2.5.29.37')
  555. class KeyPurposeId(univ.ObjectIdentifier):
  556. pass
  557. class ExtKeyUsageSyntax(univ.SequenceOf):
  558. componentType = KeyPurposeId()
  559. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  560. class ReasonFlags(univ.BitString):
  561. namedValues = namedval.NamedValues(
  562. ('unused', 0),
  563. ('keyCompromise', 1),
  564. ('cACompromise', 2),
  565. ('affiliationChanged', 3),
  566. ('superseded', 4),
  567. ('cessationOfOperation', 5),
  568. ('certificateHold', 6)
  569. )
  570. class SkipCerts(univ.Integer):
  571. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueSizeConstraint(0, MAX)
  572. id_ce_policyConstraints = univ.ObjectIdentifier('2.5.29.36')
  573. class PolicyConstraints(univ.Sequence):
  574. componentType = namedtype.NamedTypes(
  575. namedtype.OptionalNamedType('requireExplicitPolicy', SkipCerts().subtype(
  576. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  577. namedtype.OptionalNamedType('inhibitPolicyMapping', SkipCerts().subtype(
  578. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  579. )
  580. id_ce_basicConstraints = univ.ObjectIdentifier('2.5.29.19')
  581. class BasicConstraints(univ.Sequence):
  582. componentType = namedtype.NamedTypes(
  583. namedtype.DefaultedNamedType('cA', univ.Boolean(False)),
  584. namedtype.OptionalNamedType('pathLenConstraint',
  585. univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, MAX)))
  586. )
  587. id_ce_subjectDirectoryAttributes = univ.ObjectIdentifier('2.5.29.9')
  588. class EDIPartyName(univ.Sequence):
  589. componentType = namedtype.NamedTypes(
  590. namedtype.OptionalNamedType('nameAssigner', DirectoryString().subtype(
  591. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  592. namedtype.NamedType('partyName',
  593. DirectoryString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  594. )
  595. id_ce_deltaCRLIndicator = univ.ObjectIdentifier('2.5.29.27')
  596. class BaseDistance(univ.Integer):
  597. subtypeSpec = univ.Integer.subtypeSpec + constraint.ValueRangeConstraint(0, MAX)
  598. id_ce_cRLDistributionPoints = univ.ObjectIdentifier('2.5.29.31')
  599. id_ce_issuingDistributionPoint = univ.ObjectIdentifier('2.5.29.28')
  600. id_ce_nameConstraints = univ.ObjectIdentifier('2.5.29.30')
  601. class DisplayText(univ.Choice):
  602. componentType = namedtype.NamedTypes(
  603. namedtype.NamedType('visibleString',
  604. char.VisibleString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 200))),
  605. namedtype.NamedType('bmpString', char.BMPString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 200))),
  606. namedtype.NamedType('utf8String', char.UTF8String().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 200)))
  607. )
  608. class NoticeReference(univ.Sequence):
  609. componentType = namedtype.NamedTypes(
  610. namedtype.NamedType('organization', DisplayText()),
  611. namedtype.NamedType('noticeNumbers', univ.SequenceOf(componentType=univ.Integer()))
  612. )
  613. class UserNotice(univ.Sequence):
  614. componentType = namedtype.NamedTypes(
  615. namedtype.OptionalNamedType('noticeRef', NoticeReference()),
  616. namedtype.OptionalNamedType('explicitText', DisplayText())
  617. )
  618. class CPSuri(char.IA5String):
  619. pass
  620. class PolicyQualifierId(univ.ObjectIdentifier):
  621. subtypeSpec = univ.ObjectIdentifier.subtypeSpec + constraint.SingleValueConstraint(id_qt_cps, id_qt_unotice)
  622. class CertPolicyId(univ.ObjectIdentifier):
  623. pass
  624. class PolicyQualifierInfo(univ.Sequence):
  625. componentType = namedtype.NamedTypes(
  626. namedtype.NamedType('policyQualifierId', PolicyQualifierId()),
  627. namedtype.NamedType('qualifier', univ.Any())
  628. )
  629. id_ce_certificatePolicies = univ.ObjectIdentifier('2.5.29.32')
  630. class PolicyInformation(univ.Sequence):
  631. componentType = namedtype.NamedTypes(
  632. namedtype.NamedType('policyIdentifier', CertPolicyId()),
  633. namedtype.OptionalNamedType('policyQualifiers', univ.SequenceOf(componentType=PolicyQualifierInfo()).subtype(
  634. subtypeSpec=constraint.ValueSizeConstraint(1, MAX)))
  635. )
  636. class CertificatePolicies(univ.SequenceOf):
  637. componentType = PolicyInformation()
  638. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  639. id_ce_policyMappings = univ.ObjectIdentifier('2.5.29.33')
  640. class PolicyMapping(univ.Sequence):
  641. componentType = namedtype.NamedTypes(
  642. namedtype.NamedType('issuerDomainPolicy', CertPolicyId()),
  643. namedtype.NamedType('subjectDomainPolicy', CertPolicyId())
  644. )
  645. class PolicyMappings(univ.SequenceOf):
  646. componentType = PolicyMapping()
  647. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  648. id_ce_privateKeyUsagePeriod = univ.ObjectIdentifier('2.5.29.16')
  649. class PrivateKeyUsagePeriod(univ.Sequence):
  650. componentType = namedtype.NamedTypes(
  651. namedtype.OptionalNamedType('notBefore', useful.GeneralizedTime().subtype(
  652. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  653. namedtype.OptionalNamedType('notAfter', useful.GeneralizedTime().subtype(
  654. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  655. )
  656. id_ce_keyUsage = univ.ObjectIdentifier('2.5.29.15')
  657. class KeyUsage(univ.BitString):
  658. namedValues = namedval.NamedValues(
  659. ('digitalSignature', 0),
  660. ('nonRepudiation', 1),
  661. ('keyEncipherment', 2),
  662. ('dataEncipherment', 3),
  663. ('keyAgreement', 4),
  664. ('keyCertSign', 5),
  665. ('cRLSign', 6),
  666. ('encipherOnly', 7),
  667. ('decipherOnly', 8)
  668. )
  669. id_ce = univ.ObjectIdentifier('2.5.29')
  670. id_ce_authorityKeyIdentifier = univ.ObjectIdentifier('2.5.29.35')
  671. class KeyIdentifier(univ.OctetString):
  672. pass
  673. id_ce_subjectKeyIdentifier = univ.ObjectIdentifier('2.5.29.14')
  674. class SubjectKeyIdentifier(KeyIdentifier):
  675. pass
  676. id_ce_certificateIssuer = univ.ObjectIdentifier('2.5.29.29')
  677. id_ce_subjectAltName = univ.ObjectIdentifier('2.5.29.17')
  678. id_ce_issuerAltName = univ.ObjectIdentifier('2.5.29.18')
  679. class AttributeValue(univ.Any):
  680. pass
  681. class AttributeType(univ.ObjectIdentifier):
  682. pass
  683. certificateAttributesMap = {}
  684. class AttributeTypeAndValue(univ.Sequence):
  685. componentType = namedtype.NamedTypes(
  686. namedtype.NamedType('type', AttributeType()),
  687. namedtype.NamedType('value', AttributeValue(),
  688. openType=opentype.OpenType('type', certificateAttributesMap))
  689. )
  690. class Attribute(univ.Sequence):
  691. componentType = namedtype.NamedTypes(
  692. namedtype.NamedType('type', AttributeType()),
  693. namedtype.NamedType('vals', univ.SetOf(componentType=AttributeValue()))
  694. )
  695. class SubjectDirectoryAttributes(univ.SequenceOf):
  696. componentType = Attribute()
  697. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  698. class RelativeDistinguishedName(univ.SetOf):
  699. componentType = AttributeTypeAndValue()
  700. class RDNSequence(univ.SequenceOf):
  701. componentType = RelativeDistinguishedName()
  702. class Name(univ.Choice):
  703. componentType = namedtype.NamedTypes(
  704. namedtype.NamedType('', RDNSequence())
  705. )
  706. class CertificateSerialNumber(univ.Integer):
  707. pass
  708. class AnotherName(univ.Sequence):
  709. componentType = namedtype.NamedTypes(
  710. namedtype.NamedType('type-id', univ.ObjectIdentifier()),
  711. namedtype.NamedType('value',
  712. univ.Any().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
  713. )
  714. class GeneralName(univ.Choice):
  715. componentType = namedtype.NamedTypes(
  716. namedtype.NamedType('otherName',
  717. AnotherName().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  718. namedtype.NamedType('rfc822Name',
  719. char.IA5String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  720. namedtype.NamedType('dNSName',
  721. char.IA5String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  722. namedtype.NamedType('x400Address',
  723. ORAddress().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
  724. namedtype.NamedType('directoryName',
  725. Name().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))),
  726. namedtype.NamedType('ediPartyName',
  727. EDIPartyName().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 5))),
  728. namedtype.NamedType('uniformResourceIdentifier',
  729. char.IA5String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 6))),
  730. namedtype.NamedType('iPAddress', univ.OctetString().subtype(
  731. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7))),
  732. namedtype.NamedType('registeredID', univ.ObjectIdentifier().subtype(
  733. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 8)))
  734. )
  735. class GeneralNames(univ.SequenceOf):
  736. componentType = GeneralName()
  737. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  738. class AccessDescription(univ.Sequence):
  739. componentType = namedtype.NamedTypes(
  740. namedtype.NamedType('accessMethod', univ.ObjectIdentifier()),
  741. namedtype.NamedType('accessLocation', GeneralName())
  742. )
  743. class AuthorityInfoAccessSyntax(univ.SequenceOf):
  744. componentType = AccessDescription()
  745. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  746. class AuthorityKeyIdentifier(univ.Sequence):
  747. componentType = namedtype.NamedTypes(
  748. namedtype.OptionalNamedType('keyIdentifier', KeyIdentifier().subtype(
  749. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  750. namedtype.OptionalNamedType('authorityCertIssuer', GeneralNames().subtype(
  751. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  752. namedtype.OptionalNamedType('authorityCertSerialNumber', CertificateSerialNumber().subtype(
  753. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
  754. )
  755. class DistributionPointName(univ.Choice):
  756. componentType = namedtype.NamedTypes(
  757. namedtype.NamedType('fullName', GeneralNames().subtype(
  758. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  759. namedtype.NamedType('nameRelativeToCRLIssuer', RelativeDistinguishedName().subtype(
  760. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  761. )
  762. class DistributionPoint(univ.Sequence):
  763. componentType = namedtype.NamedTypes(
  764. namedtype.OptionalNamedType('distributionPoint', DistributionPointName().subtype(
  765. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  766. namedtype.OptionalNamedType('reasons', ReasonFlags().subtype(
  767. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  768. namedtype.OptionalNamedType('cRLIssuer', GeneralNames().subtype(
  769. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)))
  770. )
  771. class CRLDistPointsSyntax(univ.SequenceOf):
  772. componentType = DistributionPoint()
  773. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  774. class IssuingDistributionPoint(univ.Sequence):
  775. componentType = namedtype.NamedTypes(
  776. namedtype.OptionalNamedType('distributionPoint', DistributionPointName().subtype(
  777. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  778. namedtype.NamedType('onlyContainsUserCerts', univ.Boolean(False).subtype(
  779. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  780. namedtype.NamedType('onlyContainsCACerts', univ.Boolean(False).subtype(
  781. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  782. namedtype.OptionalNamedType('onlySomeReasons', ReasonFlags().subtype(
  783. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))),
  784. namedtype.NamedType('indirectCRL', univ.Boolean(False).subtype(
  785. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4)))
  786. )
  787. class GeneralSubtree(univ.Sequence):
  788. componentType = namedtype.NamedTypes(
  789. namedtype.NamedType('base', GeneralName()),
  790. namedtype.DefaultedNamedType('minimum', BaseDistance(0).subtype(
  791. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  792. namedtype.OptionalNamedType('maximum', BaseDistance().subtype(
  793. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  794. )
  795. class GeneralSubtrees(univ.SequenceOf):
  796. componentType = GeneralSubtree()
  797. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  798. class NameConstraints(univ.Sequence):
  799. componentType = namedtype.NamedTypes(
  800. namedtype.OptionalNamedType('permittedSubtrees', GeneralSubtrees().subtype(
  801. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  802. namedtype.OptionalNamedType('excludedSubtrees', GeneralSubtrees().subtype(
  803. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  804. )
  805. class CertificateIssuer(GeneralNames):
  806. pass
  807. class SubjectAltName(GeneralNames):
  808. pass
  809. class IssuerAltName(GeneralNames):
  810. pass
  811. certificateExtensionsMap = {}
  812. class Extension(univ.Sequence):
  813. componentType = namedtype.NamedTypes(
  814. namedtype.NamedType('extnID', univ.ObjectIdentifier()),
  815. namedtype.DefaultedNamedType('critical', univ.Boolean('False')),
  816. namedtype.NamedType('extnValue', univ.OctetString(),
  817. openType=opentype.OpenType('extnID', certificateExtensionsMap))
  818. )
  819. class Extensions(univ.SequenceOf):
  820. componentType = Extension()
  821. sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
  822. class SubjectPublicKeyInfo(univ.Sequence):
  823. componentType = namedtype.NamedTypes(
  824. namedtype.NamedType('algorithm', AlgorithmIdentifier()),
  825. namedtype.NamedType('subjectPublicKey', univ.BitString())
  826. )
  827. class UniqueIdentifier(univ.BitString):
  828. pass
  829. class Time(univ.Choice):
  830. componentType = namedtype.NamedTypes(
  831. namedtype.NamedType('utcTime', useful.UTCTime()),
  832. namedtype.NamedType('generalTime', useful.GeneralizedTime())
  833. )
  834. class Validity(univ.Sequence):
  835. componentType = namedtype.NamedTypes(
  836. namedtype.NamedType('notBefore', Time()),
  837. namedtype.NamedType('notAfter', Time())
  838. )
  839. class Version(univ.Integer):
  840. namedValues = namedval.NamedValues(
  841. ('v1', 0), ('v2', 1), ('v3', 2)
  842. )
  843. class TBSCertificate(univ.Sequence):
  844. componentType = namedtype.NamedTypes(
  845. namedtype.DefaultedNamedType('version', Version('v1').subtype(
  846. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  847. namedtype.NamedType('serialNumber', CertificateSerialNumber()),
  848. namedtype.NamedType('signature', AlgorithmIdentifier()),
  849. namedtype.NamedType('issuer', Name()),
  850. namedtype.NamedType('validity', Validity()),
  851. namedtype.NamedType('subject', Name()),
  852. namedtype.NamedType('subjectPublicKeyInfo', SubjectPublicKeyInfo()),
  853. namedtype.OptionalNamedType('issuerUniqueID', UniqueIdentifier().subtype(
  854. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  855. namedtype.OptionalNamedType('subjectUniqueID', UniqueIdentifier().subtype(
  856. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  857. namedtype.OptionalNamedType('extensions', Extensions().subtype(
  858. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))
  859. )
  860. class Certificate(univ.Sequence):
  861. componentType = namedtype.NamedTypes(
  862. namedtype.NamedType('tbsCertificate', TBSCertificate()),
  863. namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()),
  864. namedtype.NamedType('signatureValue', univ.BitString())
  865. )
  866. # CRL structures
  867. class RevokedCertificate(univ.Sequence):
  868. componentType = namedtype.NamedTypes(
  869. namedtype.NamedType('userCertificate', CertificateSerialNumber()),
  870. namedtype.NamedType('revocationDate', Time()),
  871. namedtype.OptionalNamedType('crlEntryExtensions', Extensions())
  872. )
  873. class TBSCertList(univ.Sequence):
  874. componentType = namedtype.NamedTypes(
  875. namedtype.OptionalNamedType('version', Version()),
  876. namedtype.NamedType('signature', AlgorithmIdentifier()),
  877. namedtype.NamedType('issuer', Name()),
  878. namedtype.NamedType('thisUpdate', Time()),
  879. namedtype.OptionalNamedType('nextUpdate', Time()),
  880. namedtype.OptionalNamedType('revokedCertificates', univ.SequenceOf(componentType=RevokedCertificate())),
  881. namedtype.OptionalNamedType('crlExtensions', Extensions().subtype(
  882. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
  883. )
  884. class CertificateList(univ.Sequence):
  885. componentType = namedtype.NamedTypes(
  886. namedtype.NamedType('tbsCertList', TBSCertList()),
  887. namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()),
  888. namedtype.NamedType('signature', univ.BitString())
  889. )
  890. # map of AttributeType -> AttributeValue
  891. _certificateAttributesMapUpdate = {
  892. id_at_name: X520name(),
  893. id_at_surname: X520name(),
  894. id_at_givenName: X520name(),
  895. id_at_initials: X520name(),
  896. id_at_generationQualifier: X520name(),
  897. id_at_commonName: X520CommonName(),
  898. id_at_localityName: X520LocalityName(),
  899. id_at_stateOrProvinceName: X520StateOrProvinceName(),
  900. id_at_organizationName: X520OrganizationName(),
  901. id_at_organizationalUnitName: X520OrganizationalUnitName(),
  902. id_at_title: X520Title(),
  903. id_at_dnQualifier: X520dnQualifier(),
  904. id_at_countryName: X520countryName(),
  905. emailAddress: Pkcs9email(),
  906. }
  907. certificateAttributesMap.update(_certificateAttributesMapUpdate)
  908. # map of Certificate Extension OIDs to Extensions
  909. _certificateExtensionsMapUpdate = {
  910. id_ce_authorityKeyIdentifier: AuthorityKeyIdentifier(),
  911. id_ce_subjectKeyIdentifier: SubjectKeyIdentifier(),
  912. id_ce_keyUsage: KeyUsage(),
  913. id_ce_privateKeyUsagePeriod: PrivateKeyUsagePeriod(),
  914. id_ce_certificatePolicies: CertificatePolicies(),
  915. id_ce_policyMappings: PolicyMappings(),
  916. id_ce_subjectAltName: SubjectAltName(),
  917. id_ce_issuerAltName: IssuerAltName(),
  918. id_ce_subjectDirectoryAttributes: SubjectDirectoryAttributes(),
  919. id_ce_basicConstraints: BasicConstraints(),
  920. id_ce_nameConstraints: NameConstraints(),
  921. id_ce_policyConstraints: PolicyConstraints(),
  922. id_ce_extKeyUsage: ExtKeyUsageSyntax(),
  923. id_ce_cRLDistributionPoints: CRLDistPointsSyntax(),
  924. id_pe_authorityInfoAccess: AuthorityInfoAccessSyntax(),
  925. id_ce_cRLNumber: univ.Integer(),
  926. id_ce_deltaCRLIndicator: BaseCRLNumber(),
  927. id_ce_issuingDistributionPoint: IssuingDistributionPoint(),
  928. id_ce_cRLReasons: CRLReason(),
  929. id_ce_holdInstructionCode: univ.ObjectIdentifier(),
  930. id_ce_invalidityDate: useful.GeneralizedTime(),
  931. id_ce_certificateIssuer: GeneralNames(),
  932. }
  933. certificateExtensionsMap.update(_certificateExtensionsMapUpdate)