Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc5755.py 12KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley with assistance from asn1ate v.0.6.0.
  5. #
  6. # Copyright (c) 2019, Vigil Security, LLC
  7. # License: http://snmplabs.com/pyasn1/license.html
  8. #
  9. # An Internet Attribute Certificate Profile for Authorization
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc5755.txt
  13. # https://www.rfc-editor.org/rfc/rfc5912.txt (see Section 13)
  14. #
  15. from pyasn1.type import char
  16. from pyasn1.type import constraint
  17. from pyasn1.type import namedtype
  18. from pyasn1.type import namedval
  19. from pyasn1.type import opentype
  20. from pyasn1.type import tag
  21. from pyasn1.type import univ
  22. from pyasn1.type import useful
  23. from pyasn1_modules import rfc5280
  24. from pyasn1_modules import rfc5652
  25. MAX = float('inf')
  26. # Map for Security Category type to value
  27. securityCategoryMap = { }
  28. # Imports from RFC 5652
  29. ContentInfo = rfc5652.ContentInfo
  30. # Imports from RFC 5280
  31. AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
  32. Attribute = rfc5280.Attribute
  33. AuthorityInfoAccessSyntax = rfc5280.AuthorityInfoAccessSyntax
  34. AuthorityKeyIdentifier = rfc5280.AuthorityKeyIdentifier
  35. CertificateSerialNumber = rfc5280.CertificateSerialNumber
  36. CRLDistributionPoints = rfc5280.CRLDistributionPoints
  37. Extensions = rfc5280.Extensions
  38. Extension = rfc5280.Extension
  39. GeneralNames = rfc5280.GeneralNames
  40. GeneralName = rfc5280.GeneralName
  41. UniqueIdentifier = rfc5280.UniqueIdentifier
  42. # Object Identifier arcs
  43. id_pkix = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, ))
  44. id_pe = id_pkix + (1, )
  45. id_kp = id_pkix + (3, )
  46. id_aca = id_pkix + (10, )
  47. id_ad = id_pkix + (48, )
  48. id_at = univ.ObjectIdentifier((2, 5, 4, ))
  49. id_ce = univ.ObjectIdentifier((2, 5, 29, ))
  50. # Attribute Certificate
  51. class AttCertVersion(univ.Integer):
  52. namedValues = namedval.NamedValues(
  53. ('v2', 1)
  54. )
  55. class IssuerSerial(univ.Sequence):
  56. componentType = namedtype.NamedTypes(
  57. namedtype.NamedType('issuer', GeneralNames()),
  58. namedtype.NamedType('serial', CertificateSerialNumber()),
  59. namedtype.OptionalNamedType('issuerUID', UniqueIdentifier())
  60. )
  61. class ObjectDigestInfo(univ.Sequence):
  62. componentType = namedtype.NamedTypes(
  63. namedtype.NamedType('digestedObjectType',
  64. univ.Enumerated(namedValues=namedval.NamedValues(
  65. ('publicKey', 0),
  66. ('publicKeyCert', 1),
  67. ('otherObjectTypes', 2)))),
  68. namedtype.OptionalNamedType('otherObjectTypeID',
  69. univ.ObjectIdentifier()),
  70. namedtype.NamedType('digestAlgorithm',
  71. AlgorithmIdentifier()),
  72. namedtype.NamedType('objectDigest',
  73. univ.BitString())
  74. )
  75. class Holder(univ.Sequence):
  76. componentType = namedtype.NamedTypes(
  77. namedtype.OptionalNamedType('baseCertificateID',
  78. IssuerSerial().subtype(implicitTag=tag.Tag(
  79. tag.tagClassContext, tag.tagFormatConstructed, 0))),
  80. namedtype.OptionalNamedType('entityName',
  81. GeneralNames().subtype(implicitTag=tag.Tag(
  82. tag.tagClassContext, tag.tagFormatSimple, 1))),
  83. namedtype.OptionalNamedType('objectDigestInfo',
  84. ObjectDigestInfo().subtype(implicitTag=tag.Tag(
  85. tag.tagClassContext, tag.tagFormatConstructed, 2)))
  86. )
  87. class V2Form(univ.Sequence):
  88. componentType = namedtype.NamedTypes(
  89. namedtype.OptionalNamedType('issuerName',
  90. GeneralNames()),
  91. namedtype.OptionalNamedType('baseCertificateID',
  92. IssuerSerial().subtype(implicitTag=tag.Tag(
  93. tag.tagClassContext, tag.tagFormatConstructed, 0))),
  94. namedtype.OptionalNamedType('objectDigestInfo',
  95. ObjectDigestInfo().subtype(implicitTag=tag.Tag(
  96. tag.tagClassContext, tag.tagFormatConstructed, 1)))
  97. )
  98. class AttCertIssuer(univ.Choice):
  99. componentType = namedtype.NamedTypes(
  100. namedtype.NamedType('v1Form', GeneralNames()),
  101. namedtype.NamedType('v2Form', V2Form().subtype(implicitTag=tag.Tag(
  102. tag.tagClassContext, tag.tagFormatConstructed, 0)))
  103. )
  104. class AttCertValidityPeriod(univ.Sequence):
  105. componentType = namedtype.NamedTypes(
  106. namedtype.NamedType('notBeforeTime', useful.GeneralizedTime()),
  107. namedtype.NamedType('notAfterTime', useful.GeneralizedTime())
  108. )
  109. class AttributeCertificateInfo(univ.Sequence):
  110. componentType = namedtype.NamedTypes(
  111. namedtype.NamedType('version',
  112. AttCertVersion()),
  113. namedtype.NamedType('holder',
  114. Holder()),
  115. namedtype.NamedType('issuer',
  116. AttCertIssuer()),
  117. namedtype.NamedType('signature',
  118. AlgorithmIdentifier()),
  119. namedtype.NamedType('serialNumber',
  120. CertificateSerialNumber()),
  121. namedtype.NamedType('attrCertValidityPeriod',
  122. AttCertValidityPeriod()),
  123. namedtype.NamedType('attributes',
  124. univ.SequenceOf(componentType=Attribute())),
  125. namedtype.OptionalNamedType('issuerUniqueID',
  126. UniqueIdentifier()),
  127. namedtype.OptionalNamedType('extensions',
  128. Extensions())
  129. )
  130. class AttributeCertificate(univ.Sequence):
  131. componentType = namedtype.NamedTypes(
  132. namedtype.NamedType('acinfo', AttributeCertificateInfo()),
  133. namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()),
  134. namedtype.NamedType('signatureValue', univ.BitString())
  135. )
  136. # Attribute Certificate Extensions
  137. id_pe_ac_auditIdentity = id_pe + (4, )
  138. id_ce_noRevAvail = id_ce + (56, )
  139. id_ce_targetInformation = id_ce + (55, )
  140. class TargetCert(univ.Sequence):
  141. componentType = namedtype.NamedTypes(
  142. namedtype.NamedType('targetCertificate', IssuerSerial()),
  143. namedtype.OptionalNamedType('targetName', GeneralName()),
  144. namedtype.OptionalNamedType('certDigestInfo', ObjectDigestInfo())
  145. )
  146. class Target(univ.Choice):
  147. componentType = namedtype.NamedTypes(
  148. namedtype.NamedType('targetName',
  149. GeneralName().subtype(implicitTag=tag.Tag(
  150. tag.tagClassContext, tag.tagFormatSimple, 0))),
  151. namedtype.NamedType('targetGroup',
  152. GeneralName().subtype(implicitTag=tag.Tag(
  153. tag.tagClassContext, tag.tagFormatSimple, 1))),
  154. namedtype.NamedType('targetCert',
  155. TargetCert().subtype(implicitTag=tag.Tag(
  156. tag.tagClassContext, tag.tagFormatConstructed, 2)))
  157. )
  158. class Targets(univ.SequenceOf):
  159. componentType = Target()
  160. id_pe_ac_proxying = id_pe + (10, )
  161. class ProxyInfo(univ.SequenceOf):
  162. componentType = Targets()
  163. id_pe_aaControls = id_pe + (6, )
  164. class AttrSpec(univ.SequenceOf):
  165. componentType = univ.ObjectIdentifier()
  166. class AAControls(univ.Sequence):
  167. componentType = namedtype.NamedTypes(
  168. namedtype.OptionalNamedType('pathLenConstraint',
  169. univ.Integer().subtype(
  170. subtypeSpec=constraint.ValueRangeConstraint(0, MAX))),
  171. namedtype.OptionalNamedType('permittedAttrs',
  172. AttrSpec().subtype(implicitTag=tag.Tag(
  173. tag.tagClassContext, tag.tagFormatSimple, 0))),
  174. namedtype.OptionalNamedType('excludedAttrs',
  175. AttrSpec().subtype(implicitTag=tag.Tag(
  176. tag.tagClassContext, tag.tagFormatSimple, 1))),
  177. namedtype.DefaultedNamedType('permitUnSpecified',
  178. univ.Boolean().subtype(value=1))
  179. )
  180. # Attribute Certificate Attributes
  181. id_aca_authenticationInfo = id_aca + (1, )
  182. id_aca_accessIdentity = id_aca + (2, )
  183. class SvceAuthInfo(univ.Sequence):
  184. componentType = namedtype.NamedTypes(
  185. namedtype.NamedType('service', GeneralName()),
  186. namedtype.NamedType('ident', GeneralName()),
  187. namedtype.OptionalNamedType('authInfo', univ.OctetString())
  188. )
  189. id_aca_chargingIdentity = id_aca + (3, )
  190. id_aca_group = id_aca + (4, )
  191. class IetfAttrSyntax(univ.Sequence):
  192. componentType = namedtype.NamedTypes(
  193. namedtype.OptionalNamedType('policyAuthority',
  194. GeneralNames().subtype(implicitTag=tag.Tag(
  195. tag.tagClassContext, tag.tagFormatSimple, 0))),
  196. namedtype.NamedType('values', univ.SequenceOf(
  197. componentType=univ.Choice(componentType=namedtype.NamedTypes(
  198. namedtype.NamedType('octets', univ.OctetString()),
  199. namedtype.NamedType('oid', univ.ObjectIdentifier()),
  200. namedtype.NamedType('string', char.UTF8String())
  201. ))
  202. ))
  203. )
  204. id_at_role = id_at + (72,)
  205. class RoleSyntax(univ.Sequence):
  206. componentType = namedtype.NamedTypes(
  207. namedtype.OptionalNamedType('roleAuthority',
  208. GeneralNames().subtype(implicitTag=tag.Tag(
  209. tag.tagClassContext, tag.tagFormatSimple, 0))),
  210. namedtype.NamedType('roleName',
  211. GeneralName().subtype(implicitTag=tag.Tag(
  212. tag.tagClassContext, tag.tagFormatSimple, 1)))
  213. )
  214. class ClassList(univ.BitString):
  215. namedValues = namedval.NamedValues(
  216. ('unmarked', 0),
  217. ('unclassified', 1),
  218. ('restricted', 2),
  219. ('confidential', 3),
  220. ('secret', 4),
  221. ('topSecret', 5)
  222. )
  223. class SecurityCategory(univ.Sequence):
  224. componentType = namedtype.NamedTypes(
  225. namedtype.NamedType('type',
  226. univ.ObjectIdentifier().subtype(implicitTag=tag.Tag(
  227. tag.tagClassContext, tag.tagFormatSimple, 0))),
  228. namedtype.NamedType('value',
  229. univ.Any().subtype(implicitTag=tag.Tag(
  230. tag.tagClassContext, tag.tagFormatSimple, 1)),
  231. openType=opentype.OpenType('type', securityCategoryMap))
  232. )
  233. id_at_clearance = univ.ObjectIdentifier((2, 5, 4, 55, ))
  234. class Clearance(univ.Sequence):
  235. componentType = namedtype.NamedTypes(
  236. namedtype.NamedType('policyId',
  237. univ.ObjectIdentifier()),
  238. namedtype.DefaultedNamedType('classList',
  239. ClassList().subtype(value='unclassified')),
  240. namedtype.OptionalNamedType('securityCategories',
  241. univ.SetOf(componentType=SecurityCategory()))
  242. )
  243. id_at_clearance_rfc3281 = univ.ObjectIdentifier((2, 5, 1, 5, 55, ))
  244. class Clearance_rfc3281(univ.Sequence):
  245. componentType = namedtype.NamedTypes(
  246. namedtype.NamedType('policyId',
  247. univ.ObjectIdentifier().subtype(implicitTag=tag.Tag(
  248. tag.tagClassContext, tag.tagFormatSimple, 0))),
  249. namedtype.DefaultedNamedType('classList',
  250. ClassList().subtype(implicitTag=tag.Tag(
  251. tag.tagClassContext, tag.tagFormatSimple, 1)).subtype(
  252. value='unclassified')),
  253. namedtype.OptionalNamedType('securityCategories',
  254. univ.SetOf(componentType=SecurityCategory()).subtype(
  255. implicitTag=tag.Tag(
  256. tag.tagClassContext, tag.tagFormatSimple, 2)))
  257. )
  258. id_aca_encAttrs = id_aca + (6, )
  259. class ACClearAttrs(univ.Sequence):
  260. componentType = namedtype.NamedTypes(
  261. namedtype.NamedType('acIssuer', GeneralName()),
  262. namedtype.NamedType('acSerial', univ.Integer()),
  263. namedtype.NamedType('attrs', univ.SequenceOf(componentType=Attribute()))
  264. )
  265. # Map of Certificate Extension OIDs to Extensions added to the
  266. # ones that are in rfc5280.py
  267. _certificateExtensionsMapUpdate = {
  268. id_pe_ac_auditIdentity: univ.OctetString(),
  269. id_ce_noRevAvail: univ.Null(),
  270. id_ce_targetInformation: Targets(),
  271. id_pe_ac_proxying: ProxyInfo(),
  272. id_pe_aaControls: AAControls(),
  273. }
  274. rfc5280.certificateExtensionsMap.update(_certificateExtensionsMapUpdate)
  275. # Map of AttributeType OIDs to AttributeValue added to the
  276. # ones that are in rfc5280.py
  277. _certificateAttributesMapUpdate = {
  278. id_aca_authenticationInfo: SvceAuthInfo(),
  279. id_aca_accessIdentity: SvceAuthInfo(),
  280. id_aca_chargingIdentity: IetfAttrSyntax(),
  281. id_aca_group: IetfAttrSyntax(),
  282. id_at_role: RoleSyntax(),
  283. id_at_clearance: Clearance(),
  284. id_at_clearance_rfc3281: Clearance_rfc3281(),
  285. id_aca_encAttrs: ContentInfo(),
  286. }
  287. rfc5280.certificateAttributesMap.update(_certificateAttributesMapUpdate)