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.

96 lines
2.1 KiB

4 years ago
  1. # coding: utf-8
  2. """
  3. ASN.1 type classes for certificate signing requests (CSR). Exports the
  4. following items:
  5. - CertificatationRequest()
  6. Other type classes are defined that help compose the types listed above.
  7. """
  8. from __future__ import unicode_literals, division, absolute_import, print_function
  9. from .algos import SignedDigestAlgorithm
  10. from .core import (
  11. Any,
  12. Integer,
  13. ObjectIdentifier,
  14. OctetBitString,
  15. Sequence,
  16. SetOf,
  17. )
  18. from .keys import PublicKeyInfo
  19. from .x509 import DirectoryString, Extensions, Name
  20. # The structures in this file are taken from https://tools.ietf.org/html/rfc2986
  21. # and https://tools.ietf.org/html/rfc2985
  22. class Version(Integer):
  23. _map = {
  24. 0: 'v1',
  25. }
  26. class CSRAttributeType(ObjectIdentifier):
  27. _map = {
  28. '1.2.840.113549.1.9.7': 'challenge_password',
  29. '1.2.840.113549.1.9.9': 'extended_certificate_attributes',
  30. '1.2.840.113549.1.9.14': 'extension_request',
  31. }
  32. class SetOfDirectoryString(SetOf):
  33. _child_spec = DirectoryString
  34. class Attribute(Sequence):
  35. _fields = [
  36. ('type', ObjectIdentifier),
  37. ('values', SetOf, {'spec': Any}),
  38. ]
  39. class SetOfAttributes(SetOf):
  40. _child_spec = Attribute
  41. class SetOfExtensions(SetOf):
  42. _child_spec = Extensions
  43. class CRIAttribute(Sequence):
  44. _fields = [
  45. ('type', CSRAttributeType),
  46. ('values', Any),
  47. ]
  48. _oid_pair = ('type', 'values')
  49. _oid_specs = {
  50. 'challenge_password': SetOfDirectoryString,
  51. 'extended_certificate_attributes': SetOfAttributes,
  52. 'extension_request': SetOfExtensions,
  53. }
  54. class CRIAttributes(SetOf):
  55. _child_spec = CRIAttribute
  56. class CertificationRequestInfo(Sequence):
  57. _fields = [
  58. ('version', Version),
  59. ('subject', Name),
  60. ('subject_pk_info', PublicKeyInfo),
  61. ('attributes', CRIAttributes, {'implicit': 0, 'optional': True}),
  62. ]
  63. class CertificationRequest(Sequence):
  64. _fields = [
  65. ('certification_request_info', CertificationRequestInfo),
  66. ('signature_algorithm', SignedDigestAlgorithm),
  67. ('signature', OctetBitString),
  68. ]