test_rfc4211.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley
  5. # Copyright (c) 2019, Vigil Security, LLC
  6. # License: http://snmplabs.com/pyasn1/license.html
  7. #
  8. import sys
  9. import unittest
  10. from pyasn1.codec.der.decoder import decode as der_decoder
  11. from pyasn1.codec.der.encoder import encode as der_encoder
  12. from pyasn1_modules import pem
  13. from pyasn1_modules import rfc4211
  14. class CertificateReqTestCase(unittest.TestCase):
  15. pem_text = """\
  16. MIIBozCCAZ8wggEFAgUAwTnj2jCByoABAqURMA8xDTALBgNVBAMTBHVzZXKmgZ8w
  17. DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ6ZQ2cYbn/lFsmBOlRltbRbFQUvvE0Q
  18. nbopOu1kC7Bmaaz7QTx8nxeiHi4m7uxCbGGxHNoGCt7EmdG8eZUBNAcHyGlXrJdm
  19. 0z3/uNEGiBHq+xB8FnFJCA5EIJ3RWFnlbu9otSITLxWK7c5+/NHmWM+yaeHD/f/h
  20. rp01c/8qXZfZAgMBAAGpEDAOBgNVHQ8BAf8EBAMCBeAwLzASBgkrBgEFBQcFAQEM
  21. BTExMTExMBkGCSsGAQUFBwUBAgwMc2VydmVyX21hZ2ljoYGTMA0GCSqGSIb3DQEB
  22. BQUAA4GBAEI3KNEvTq/n1kNVhNhPkovk1AZxyJrN1u1+7Gkc4PLjWwjLOjcEVWt4
  23. AajUk/gkIJ6bbeO+fZlMjHfPSDKcD6AV2hN+n72QZwfzcw3icNvBG1el9EU4XfIm
  24. xfu5YVWi81/fw8QQ6X6YGHFQkomLd7jxakVyjxSng9BhO6GpjJNF
  25. """
  26. def setUp(self):
  27. self.asn1Spec = rfc4211.CertReqMessages()
  28. def testDerCodec(self):
  29. substrate = pem.readBase64fromText(self.pem_text)
  30. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  31. self.assertFalse(rest)
  32. self.assertTrue(asn1Object.prettyPrint())
  33. self.assertEqual(substrate, der_encoder(asn1Object))
  34. count = 0
  35. for crm in asn1Object:
  36. self.assertEqual(2, crm['certReq']['certTemplate']['version'])
  37. count += 1
  38. self.assertEqual(1, count)
  39. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  40. if __name__ == '__main__':
  41. result = unittest.TextTestRunner(verbosity=2).run(suite)
  42. sys.exit(not result.wasSuccessful())