test_rfc5924.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 rfc5280
  14. from pyasn1_modules import rfc5924
  15. class SIPDomainCertTestCase(unittest.TestCase):
  16. cert_pem_text = """\
  17. MIICiTCCAg+gAwIBAgIJAKWzVCgbsG5EMAoGCCqGSM49BAMDMD8xCzAJBgNVBAYT
  18. AlVTMQswCQYDVQQIDAJWQTEQMA4GA1UEBwwHSGVybmRvbjERMA8GA1UECgwIQm9n
  19. dXMgQ0EwHhcNMTkxMDMwMjEwMDM0WhcNMjAxMDI5MjEwMDM0WjBsMQswCQYDVQQG
  20. EwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24xEDAOBgNVBAoTB0V4
  21. YW1wbGUxEjAQBgNVBAsTCVNJUCBQcm94eTEYMBYGA1UEAxMPc2lwLmV4YW1wbGUu
  22. Y29tMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEcY3ckttSa6z3CfOFwZvPmZY8C9Ml
  23. D1XOydz00+Vqifh1lydhDuulHrJaQ+QgVjG1TzlTAssD9GeABit/M98DPS/IC3wi
  24. TsTMSyQ9/Oz4hKAw7x7lYEvufvycsZ7pJGRso4GpMIGmMEIGCWCGSAGG+EIBDQQ1
  25. FjNUaGlzIGNlcnRpZmljYXRlIGNhbm5vdCBiZSB0cnVzdGVkIGZvciBhbnkgcHVy
  26. cG9zZS4wHQYDVR0OBBYEFEcJ8iFWmJOl3Hg/44UFgFWNbe7FMB8GA1UdIwQYMBaA
  27. FPI12zQE2qVV8r1pA5mwYuziFQjBMAsGA1UdDwQEAwIHgDATBgNVHSUEDDAKBggr
  28. BgEFBQcDFDAKBggqhkjOPQQDAwNoADBlAjAXEPPNyXBUj40dzy+ZOqafuM3/6Fy6
  29. bkgiIObcQImra96X10fe6qacanrbu4uU6d8CMQCQ+BCjCnOP4dBbNC3vB0WypxLo
  30. UwZ6TjS0Rfr+dRvlyilVjP+hPVwbyb7ZOSZR6zk=
  31. """
  32. def setUp(self):
  33. self.asn1Spec = rfc5280.Certificate()
  34. def testDerCodec(self):
  35. substrate = pem.readBase64fromText(self.cert_pem_text)
  36. asn1Object, rest = der_decoder(
  37. substrate, asn1Spec=self.asn1Spec)
  38. self.assertFalse(rest)
  39. self.assertTrue(asn1Object.prettyPrint())
  40. self.assertEqual(substrate, der_encoder(asn1Object))
  41. found_kp_sipDomain = False
  42. for extn in asn1Object['tbsCertificate']['extensions']:
  43. if extn['extnID'] == rfc5280.id_ce_extKeyUsage:
  44. self.assertIn(
  45. extn['extnID'], rfc5280.certificateExtensionsMap)
  46. ev, rest = der_decoder(
  47. extn['extnValue'],
  48. asn1Spec=rfc5280.certificateExtensionsMap[extn['extnID']])
  49. self.assertFalse(rest)
  50. self.assertTrue(ev.prettyPrint())
  51. self.assertEqual(extn['extnValue'], der_encoder(ev))
  52. self.assertIn(rfc5924.id_kp_sipDomain, ev)
  53. found_kp_sipDomain = True
  54. self.assertTrue(found_kp_sipDomain)
  55. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  56. if __name__ == '__main__':
  57. result = unittest.TextTestRunner(verbosity=2).run(suite)
  58. sys.exit(not result.wasSuccessful())