rfc6664.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley with some 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. # S/MIME Capabilities for Public Key Definitions
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc6664.txt
  13. #
  14. from pyasn1.type import constraint
  15. from pyasn1.type import namedtype
  16. from pyasn1.type import tag
  17. from pyasn1.type import univ
  18. from pyasn1_modules import rfc5280
  19. from pyasn1_modules import rfc5751
  20. from pyasn1_modules import rfc5480
  21. from pyasn1_modules import rfc4055
  22. from pyasn1_modules import rfc3279
  23. MAX = float('inf')
  24. # Imports from RFC 5280
  25. AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
  26. # Imports from RFC 3279
  27. dhpublicnumber = rfc3279.dhpublicnumber
  28. Dss_Parms = rfc3279.Dss_Parms
  29. id_dsa = rfc3279.id_dsa
  30. id_ecPublicKey = rfc3279.id_ecPublicKey
  31. rsaEncryption = rfc3279.rsaEncryption
  32. # Imports from RFC 4055
  33. id_mgf1 = rfc4055.id_mgf1
  34. id_RSAES_OAEP = rfc4055.id_RSAES_OAEP
  35. id_RSASSA_PSS = rfc4055.id_RSASSA_PSS
  36. # Imports from RFC 5480
  37. ECParameters = rfc5480.ECParameters
  38. id_ecDH = rfc5480.id_ecDH
  39. id_ecMQV = rfc5480.id_ecMQV
  40. # RSA
  41. class RSAKeySize(univ.Integer):
  42. # suggested values are 1024, 2048, 3072, 4096, 7680, 8192, and 15360;
  43. # however, the integer value is not limited to these suggestions
  44. pass
  45. class RSAKeyCapabilities(univ.Sequence):
  46. componentType = namedtype.NamedTypes(
  47. namedtype.NamedType('minKeySize', RSAKeySize()),
  48. namedtype.OptionalNamedType('maxKeySize', RSAKeySize())
  49. )
  50. class RsaSsa_Pss_sig_caps(univ.Sequence):
  51. componentType = namedtype.NamedTypes(
  52. namedtype.NamedType('hashAlg', AlgorithmIdentifier()),
  53. namedtype.OptionalNamedType('maskAlg', AlgorithmIdentifier()),
  54. namedtype.DefaultedNamedType('trailerField', univ.Integer().subtype(value=1))
  55. )
  56. # Diffie-Hellman and DSA
  57. class DSAKeySize(univ.Integer):
  58. subtypeSpec = constraint.SingleValueConstraint(1024, 2048, 3072, 7680, 15360)
  59. class DSAKeyCapabilities(univ.Choice):
  60. componentType = namedtype.NamedTypes(
  61. namedtype.NamedType('keySizes', univ.Sequence(componentType=namedtype.NamedTypes(
  62. namedtype.NamedType('minKeySize',
  63. DSAKeySize()),
  64. namedtype.OptionalNamedType('maxKeySize',
  65. DSAKeySize()),
  66. namedtype.OptionalNamedType('maxSizeP',
  67. univ.Integer().subtype(explicitTag=tag.Tag(
  68. tag.tagClassContext, tag.tagFormatSimple, 1))),
  69. namedtype.OptionalNamedType('maxSizeQ',
  70. univ.Integer().subtype(explicitTag=tag.Tag(
  71. tag.tagClassContext, tag.tagFormatSimple, 2))),
  72. namedtype.OptionalNamedType('maxSizeG',
  73. univ.Integer().subtype(explicitTag=tag.Tag(
  74. tag.tagClassContext, tag.tagFormatSimple, 3)))
  75. )).subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  76. namedtype.NamedType('keyParams',
  77. Dss_Parms().subtype(explicitTag=tag.Tag(
  78. tag.tagClassContext, tag.tagFormatConstructed, 1)))
  79. )
  80. # Elliptic Curve
  81. class EC_SMimeCaps(univ.SequenceOf):
  82. componentType = ECParameters()
  83. subtypeSpec=constraint.ValueSizeConstraint(1, MAX)
  84. # Update the SMIMECapabilities Attribute Map in rfc5751.py
  85. #
  86. # The map can either include an entry for scap-sa-rsaSSA-PSS or
  87. # scap-pk-rsaSSA-PSS, but not both. One is associated with the
  88. # public key and the other is associated with the signature
  89. # algorithm; however, they use the same OID. If you need the
  90. # other one in your application, copy the map into a local dict,
  91. # adjust as needed, and pass the local dict to the decoder with
  92. # openTypes=your_local_map.
  93. _smimeCapabilityMapUpdate = {
  94. rsaEncryption: RSAKeyCapabilities(),
  95. id_RSASSA_PSS: RSAKeyCapabilities(),
  96. # id_RSASSA_PSS: RsaSsa_Pss_sig_caps(),
  97. id_RSAES_OAEP: RSAKeyCapabilities(),
  98. id_dsa: DSAKeyCapabilities(),
  99. dhpublicnumber: DSAKeyCapabilities(),
  100. id_ecPublicKey: EC_SMimeCaps(),
  101. id_ecDH: EC_SMimeCaps(),
  102. id_ecMQV: EC_SMimeCaps(),
  103. id_mgf1: AlgorithmIdentifier(),
  104. }
  105. rfc5751.smimeCapabilityMap.update(_smimeCapabilityMapUpdate)