rfc2459.py 44 KB

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