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.

rfc3279.py 6.6KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #
  2. # This file is part of pyasn1-modules.
  3. #
  4. # Copyright (c) 2017, Danielle Madeley <danielle@madeley.id.au>
  5. # License: http://snmplabs.com/pyasn1/license.html
  6. #
  7. # Modified by Russ Housley to add maps for use with opentypes.
  8. #
  9. # Algorithms and Identifiers for Internet X.509 Certificates and CRLs
  10. #
  11. # Derived from RFC 3279:
  12. # https://www.rfc-editor.org/rfc/rfc3279.txt
  13. #
  14. from pyasn1.type import namedtype
  15. from pyasn1.type import namedval
  16. from pyasn1.type import univ
  17. from pyasn1_modules import rfc5280
  18. def _OID(*components):
  19. output = []
  20. for x in tuple(components):
  21. if isinstance(x, univ.ObjectIdentifier):
  22. output.extend(list(x))
  23. else:
  24. output.append(int(x))
  25. return univ.ObjectIdentifier(output)
  26. md2 = _OID(1, 2, 840, 113549, 2, 2)
  27. md5 = _OID(1, 2, 840, 113549, 2, 5)
  28. id_sha1 = _OID(1, 3, 14, 3, 2, 26)
  29. id_dsa = _OID(1, 2, 840, 10040, 4, 1)
  30. class DSAPublicKey(univ.Integer):
  31. pass
  32. class Dss_Parms(univ.Sequence):
  33. componentType = namedtype.NamedTypes(
  34. namedtype.NamedType('p', univ.Integer()),
  35. namedtype.NamedType('q', univ.Integer()),
  36. namedtype.NamedType('g', univ.Integer())
  37. )
  38. id_dsa_with_sha1 = _OID(1, 2, 840, 10040, 4, 3)
  39. class Dss_Sig_Value(univ.Sequence):
  40. componentType = namedtype.NamedTypes(
  41. namedtype.NamedType('r', univ.Integer()),
  42. namedtype.NamedType('s', univ.Integer())
  43. )
  44. pkcs_1 = _OID(1, 2, 840, 113549, 1, 1)
  45. rsaEncryption = _OID(pkcs_1, 1)
  46. md2WithRSAEncryption = _OID(pkcs_1, 2)
  47. md5WithRSAEncryption = _OID(pkcs_1, 4)
  48. sha1WithRSAEncryption = _OID(pkcs_1, 5)
  49. class RSAPublicKey(univ.Sequence):
  50. componentType = namedtype.NamedTypes(
  51. namedtype.NamedType('modulus', univ.Integer()),
  52. namedtype.NamedType('publicExponent', univ.Integer())
  53. )
  54. dhpublicnumber = _OID(1, 2, 840, 10046, 2, 1)
  55. class DHPublicKey(univ.Integer):
  56. pass
  57. class ValidationParms(univ.Sequence):
  58. componentType = namedtype.NamedTypes(
  59. namedtype.NamedType('seed', univ.BitString()),
  60. namedtype.NamedType('pgenCounter', univ.Integer())
  61. )
  62. class DomainParameters(univ.Sequence):
  63. componentType = namedtype.NamedTypes(
  64. namedtype.NamedType('p', univ.Integer()),
  65. namedtype.NamedType('g', univ.Integer()),
  66. namedtype.NamedType('q', univ.Integer()),
  67. namedtype.OptionalNamedType('j', univ.Integer()),
  68. namedtype.OptionalNamedType('validationParms', ValidationParms())
  69. )
  70. id_keyExchangeAlgorithm = _OID(2, 16, 840, 1, 101, 2, 1, 1, 22)
  71. class KEA_Parms_Id(univ.OctetString):
  72. pass
  73. ansi_X9_62 = _OID(1, 2, 840, 10045)
  74. class FieldID(univ.Sequence):
  75. componentType = namedtype.NamedTypes(
  76. namedtype.NamedType('fieldType', univ.ObjectIdentifier()),
  77. namedtype.NamedType('parameters', univ.Any())
  78. )
  79. id_ecSigType = _OID(ansi_X9_62, 4)
  80. ecdsa_with_SHA1 = _OID(id_ecSigType, 1)
  81. class ECDSA_Sig_Value(univ.Sequence):
  82. componentType = namedtype.NamedTypes(
  83. namedtype.NamedType('r', univ.Integer()),
  84. namedtype.NamedType('s', univ.Integer())
  85. )
  86. id_fieldType = _OID(ansi_X9_62, 1)
  87. prime_field = _OID(id_fieldType, 1)
  88. class Prime_p(univ.Integer):
  89. pass
  90. characteristic_two_field = _OID(id_fieldType, 2)
  91. class Characteristic_two(univ.Sequence):
  92. componentType = namedtype.NamedTypes(
  93. namedtype.NamedType('m', univ.Integer()),
  94. namedtype.NamedType('basis', univ.ObjectIdentifier()),
  95. namedtype.NamedType('parameters', univ.Any())
  96. )
  97. id_characteristic_two_basis = _OID(characteristic_two_field, 3)
  98. gnBasis = _OID(id_characteristic_two_basis, 1)
  99. tpBasis = _OID(id_characteristic_two_basis, 2)
  100. class Trinomial(univ.Integer):
  101. pass
  102. ppBasis = _OID(id_characteristic_two_basis, 3)
  103. class Pentanomial(univ.Sequence):
  104. componentType = namedtype.NamedTypes(
  105. namedtype.NamedType('k1', univ.Integer()),
  106. namedtype.NamedType('k2', univ.Integer()),
  107. namedtype.NamedType('k3', univ.Integer())
  108. )
  109. class FieldElement(univ.OctetString):
  110. pass
  111. class ECPoint(univ.OctetString):
  112. pass
  113. class Curve(univ.Sequence):
  114. componentType = namedtype.NamedTypes(
  115. namedtype.NamedType('a', FieldElement()),
  116. namedtype.NamedType('b', FieldElement()),
  117. namedtype.OptionalNamedType('seed', univ.BitString())
  118. )
  119. class ECPVer(univ.Integer):
  120. namedValues = namedval.NamedValues(
  121. ('ecpVer1', 1)
  122. )
  123. class ECParameters(univ.Sequence):
  124. componentType = namedtype.NamedTypes(
  125. namedtype.NamedType('version', ECPVer()),
  126. namedtype.NamedType('fieldID', FieldID()),
  127. namedtype.NamedType('curve', Curve()),
  128. namedtype.NamedType('base', ECPoint()),
  129. namedtype.NamedType('order', univ.Integer()),
  130. namedtype.OptionalNamedType('cofactor', univ.Integer())
  131. )
  132. class EcpkParameters(univ.Choice):
  133. componentType = namedtype.NamedTypes(
  134. namedtype.NamedType('ecParameters', ECParameters()),
  135. namedtype.NamedType('namedCurve', univ.ObjectIdentifier()),
  136. namedtype.NamedType('implicitlyCA', univ.Null())
  137. )
  138. id_publicKeyType = _OID(ansi_X9_62, 2)
  139. id_ecPublicKey = _OID(id_publicKeyType, 1)
  140. ellipticCurve = _OID(ansi_X9_62, 3)
  141. c_TwoCurve = _OID(ellipticCurve, 0)
  142. c2pnb163v1 = _OID(c_TwoCurve, 1)
  143. c2pnb163v2 = _OID(c_TwoCurve, 2)
  144. c2pnb163v3 = _OID(c_TwoCurve, 3)
  145. c2pnb176w1 = _OID(c_TwoCurve, 4)
  146. c2tnb191v1 = _OID(c_TwoCurve, 5)
  147. c2tnb191v2 = _OID(c_TwoCurve, 6)
  148. c2tnb191v3 = _OID(c_TwoCurve, 7)
  149. c2onb191v4 = _OID(c_TwoCurve, 8)
  150. c2onb191v5 = _OID(c_TwoCurve, 9)
  151. c2pnb208w1 = _OID(c_TwoCurve, 10)
  152. c2tnb239v1 = _OID(c_TwoCurve, 11)
  153. c2tnb239v2 = _OID(c_TwoCurve, 12)
  154. c2tnb239v3 = _OID(c_TwoCurve, 13)
  155. c2onb239v4 = _OID(c_TwoCurve, 14)
  156. c2onb239v5 = _OID(c_TwoCurve, 15)
  157. c2pnb272w1 = _OID(c_TwoCurve, 16)
  158. c2pnb304w1 = _OID(c_TwoCurve, 17)
  159. c2tnb359v1 = _OID(c_TwoCurve, 18)
  160. c2pnb368w1 = _OID(c_TwoCurve, 19)
  161. c2tnb431r1 = _OID(c_TwoCurve, 20)
  162. primeCurve = _OID(ellipticCurve, 1)
  163. prime192v1 = _OID(primeCurve, 1)
  164. prime192v2 = _OID(primeCurve, 2)
  165. prime192v3 = _OID(primeCurve, 3)
  166. prime239v1 = _OID(primeCurve, 4)
  167. prime239v2 = _OID(primeCurve, 5)
  168. prime239v3 = _OID(primeCurve, 6)
  169. prime256v1 = _OID(primeCurve, 7)
  170. # Map of Algorithm Identifier OIDs to Parameters added to the
  171. # ones in rfc5280.py. Do not add OIDs with absent paramaters.
  172. _algorithmIdentifierMapUpdate = {
  173. md2: univ.Null(""),
  174. md5: univ.Null(""),
  175. id_sha1: univ.Null(""),
  176. id_dsa: Dss_Parms(),
  177. rsaEncryption: univ.Null(""),
  178. md2WithRSAEncryption: univ.Null(""),
  179. md5WithRSAEncryption: univ.Null(""),
  180. sha1WithRSAEncryption: univ.Null(""),
  181. dhpublicnumber: DomainParameters(),
  182. id_keyExchangeAlgorithm: KEA_Parms_Id(),
  183. id_ecPublicKey: EcpkParameters(),
  184. }
  185. rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)