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 5.8KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. # Derived from RFC 3279
  8. #
  9. from pyasn1.type import namedtype
  10. from pyasn1.type import namedval
  11. from pyasn1.type import univ
  12. def _OID(*components):
  13. output = []
  14. for x in tuple(components):
  15. if isinstance(x, univ.ObjectIdentifier):
  16. output.extend(list(x))
  17. else:
  18. output.append(int(x))
  19. return univ.ObjectIdentifier(output)
  20. md2 = _OID(1, 2, 840, 113549, 2, 2)
  21. md5 = _OID(1, 2, 840, 113549, 2, 5)
  22. id_sha1 = _OID(1, 3, 14, 3, 2, 26)
  23. id_dsa = _OID(1, 2, 840, 10040, 4, 1)
  24. class DSAPublicKey(univ.Integer):
  25. pass
  26. class Dss_Parms(univ.Sequence):
  27. componentType = namedtype.NamedTypes(
  28. namedtype.NamedType('p', univ.Integer()),
  29. namedtype.NamedType('q', univ.Integer()),
  30. namedtype.NamedType('g', univ.Integer())
  31. )
  32. id_dsa_with_sha1 = _OID(1, 2, 840, 10040, 4, 3)
  33. class Dss_Sig_Value(univ.Sequence):
  34. componentType = namedtype.NamedTypes(
  35. namedtype.NamedType('r', univ.Integer()),
  36. namedtype.NamedType('s', univ.Integer())
  37. )
  38. pkcs_1 = _OID(1, 2, 840, 113549, 1, 1)
  39. rsaEncryption = _OID(pkcs_1, 1)
  40. md2WithRSAEncryption = _OID(pkcs_1, 2)
  41. md5WithRSAEncryption = _OID(pkcs_1, 4)
  42. sha1WithRSAEncryption = _OID(pkcs_1, 5)
  43. class RSAPublicKey(univ.Sequence):
  44. componentType = namedtype.NamedTypes(
  45. namedtype.NamedType('modulus', univ.Integer()),
  46. namedtype.NamedType('publicExponent', univ.Integer())
  47. )
  48. dhpublicnumber = _OID(1, 2, 840, 10046, 2, 1)
  49. class DHPublicKey(univ.Integer):
  50. pass
  51. class ValidationParms(univ.Sequence):
  52. componentType = namedtype.NamedTypes(
  53. namedtype.NamedType('seed', univ.BitString()),
  54. namedtype.NamedType('pgenCounter', univ.Integer())
  55. )
  56. class DomainParameters(univ.Sequence):
  57. componentType = namedtype.NamedTypes(
  58. namedtype.NamedType('p', univ.Integer()),
  59. namedtype.NamedType('g', univ.Integer()),
  60. namedtype.NamedType('q', univ.Integer()),
  61. namedtype.OptionalNamedType('j', univ.Integer()),
  62. namedtype.OptionalNamedType('validationParms', ValidationParms())
  63. )
  64. id_keyExchangeAlgorithm = _OID(2, 16, 840, 1, 101, 2, 1, 1, 22)
  65. class KEA_Parms_Id(univ.OctetString):
  66. pass
  67. ansi_X9_62 = _OID(1, 2, 840, 10045)
  68. class FieldID(univ.Sequence):
  69. componentType = namedtype.NamedTypes(
  70. namedtype.NamedType('fieldType', univ.ObjectIdentifier()),
  71. namedtype.NamedType('parameters', univ.Any())
  72. )
  73. id_ecSigType = _OID(ansi_X9_62, 4)
  74. ecdsa_with_SHA1 = _OID(id_ecSigType, 1)
  75. class ECDSA_Sig_Value(univ.Sequence):
  76. componentType = namedtype.NamedTypes(
  77. namedtype.NamedType('r', univ.Integer()),
  78. namedtype.NamedType('s', univ.Integer())
  79. )
  80. id_fieldType = _OID(ansi_X9_62, 1)
  81. prime_field = _OID(id_fieldType, 1)
  82. class Prime_p(univ.Integer):
  83. pass
  84. characteristic_two_field = _OID(id_fieldType, 2)
  85. class Characteristic_two(univ.Sequence):
  86. componentType = namedtype.NamedTypes(
  87. namedtype.NamedType('m', univ.Integer()),
  88. namedtype.NamedType('basis', univ.ObjectIdentifier()),
  89. namedtype.NamedType('parameters', univ.Any())
  90. )
  91. id_characteristic_two_basis = _OID(characteristic_two_field, 3)
  92. gnBasis = _OID(id_characteristic_two_basis, 1)
  93. tpBasis = _OID(id_characteristic_two_basis, 2)
  94. class Trinomial(univ.Integer):
  95. pass
  96. ppBasis = _OID(id_characteristic_two_basis, 3)
  97. class Pentanomial(univ.Sequence):
  98. componentType = namedtype.NamedTypes(
  99. namedtype.NamedType('k1', univ.Integer()),
  100. namedtype.NamedType('k2', univ.Integer()),
  101. namedtype.NamedType('k3', univ.Integer())
  102. )
  103. class FieldElement(univ.OctetString):
  104. pass
  105. class ECPoint(univ.OctetString):
  106. pass
  107. class Curve(univ.Sequence):
  108. componentType = namedtype.NamedTypes(
  109. namedtype.NamedType('a', FieldElement()),
  110. namedtype.NamedType('b', FieldElement()),
  111. namedtype.OptionalNamedType('seed', univ.BitString())
  112. )
  113. class ECPVer(univ.Integer):
  114. namedValues = namedval.NamedValues(
  115. ('ecpVer1', 1)
  116. )
  117. class ECParameters(univ.Sequence):
  118. componentType = namedtype.NamedTypes(
  119. namedtype.NamedType('version', ECPVer()),
  120. namedtype.NamedType('fieldID', FieldID()),
  121. namedtype.NamedType('curve', Curve()),
  122. namedtype.NamedType('base', ECPoint()),
  123. namedtype.NamedType('order', univ.Integer()),
  124. namedtype.OptionalNamedType('cofactor', univ.Integer())
  125. )
  126. class EcpkParameters(univ.Choice):
  127. componentType = namedtype.NamedTypes(
  128. namedtype.NamedType('ecParameters', ECParameters()),
  129. namedtype.NamedType('namedCurve', univ.ObjectIdentifier()),
  130. namedtype.NamedType('implicitlyCA', univ.Null())
  131. )
  132. id_publicKeyType = _OID(ansi_X9_62, 2)
  133. id_ecPublicKey = _OID(id_publicKeyType, 1)
  134. ellipticCurve = _OID(ansi_X9_62, 3)
  135. c_TwoCurve = _OID(ellipticCurve, 0)
  136. c2pnb163v1 = _OID(c_TwoCurve, 1)
  137. c2pnb163v2 = _OID(c_TwoCurve, 2)
  138. c2pnb163v3 = _OID(c_TwoCurve, 3)
  139. c2pnb176w1 = _OID(c_TwoCurve, 4)
  140. c2tnb191v1 = _OID(c_TwoCurve, 5)
  141. c2tnb191v2 = _OID(c_TwoCurve, 6)
  142. c2tnb191v3 = _OID(c_TwoCurve, 7)
  143. c2onb191v4 = _OID(c_TwoCurve, 8)
  144. c2onb191v5 = _OID(c_TwoCurve, 9)
  145. c2pnb208w1 = _OID(c_TwoCurve, 10)
  146. c2tnb239v1 = _OID(c_TwoCurve, 11)
  147. c2tnb239v2 = _OID(c_TwoCurve, 12)
  148. c2tnb239v3 = _OID(c_TwoCurve, 13)
  149. c2onb239v4 = _OID(c_TwoCurve, 14)
  150. c2onb239v5 = _OID(c_TwoCurve, 15)
  151. c2pnb272w1 = _OID(c_TwoCurve, 16)
  152. c2pnb304w1 = _OID(c_TwoCurve, 17)
  153. c2tnb359v1 = _OID(c_TwoCurve, 18)
  154. c2pnb368w1 = _OID(c_TwoCurve, 19)
  155. c2tnb431r1 = _OID(c_TwoCurve, 20)
  156. primeCurve = _OID(ellipticCurve, 1)
  157. prime192v1 = _OID(primeCurve, 1)
  158. prime192v2 = _OID(primeCurve, 2)
  159. prime192v3 = _OID(primeCurve, 3)
  160. prime239v1 = _OID(primeCurve, 4)
  161. prime239v2 = _OID(primeCurve, 5)
  162. prime239v3 = _OID(primeCurve, 6)
  163. prime256v1 = _OID(primeCurve, 7)