• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
9import sys
10
11from pyasn1.codec.der.decoder import decode as der_decode
12from pyasn1.codec.der.encoder import encode as der_encode
13
14from pyasn1_modules import pem
15from pyasn1_modules import rfc4211
16
17try:
18    import unittest2 as unittest
19
20except ImportError:
21    import unittest
22
23
24class CertificateReqTestCase(unittest.TestCase):
25    pem_text = """\
26MIIBozCCAZ8wggEFAgUAwTnj2jCByoABAqURMA8xDTALBgNVBAMTBHVzZXKmgZ8w
27DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ6ZQ2cYbn/lFsmBOlRltbRbFQUvvE0Q
28nbopOu1kC7Bmaaz7QTx8nxeiHi4m7uxCbGGxHNoGCt7EmdG8eZUBNAcHyGlXrJdm
290z3/uNEGiBHq+xB8FnFJCA5EIJ3RWFnlbu9otSITLxWK7c5+/NHmWM+yaeHD/f/h
30rp01c/8qXZfZAgMBAAGpEDAOBgNVHQ8BAf8EBAMCBeAwLzASBgkrBgEFBQcFAQEM
31BTExMTExMBkGCSsGAQUFBwUBAgwMc2VydmVyX21hZ2ljoYGTMA0GCSqGSIb3DQEB
32BQUAA4GBAEI3KNEvTq/n1kNVhNhPkovk1AZxyJrN1u1+7Gkc4PLjWwjLOjcEVWt4
33AajUk/gkIJ6bbeO+fZlMjHfPSDKcD6AV2hN+n72QZwfzcw3icNvBG1el9EU4XfIm
34xfu5YVWi81/fw8QQ6X6YGHFQkomLd7jxakVyjxSng9BhO6GpjJNF
35"""
36
37    def setUp(self):
38        self.asn1Spec = rfc4211.CertReqMessages()
39
40    def testDerCodec(self):
41        substrate = pem.readBase64fromText(self.pem_text)
42        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
43        assert not rest
44        assert asn1Object.prettyPrint()
45        assert der_encode(asn1Object) == substrate
46
47        count = 0
48        for crm in asn1Object:
49            assert crm['certReq']['certTemplate']['version'] == 2
50            count += 1
51
52        assert count == 1
53
54
55suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
56
57if __name__ == '__main__':
58    import sys
59
60    result = unittest.TextTestRunner(verbosity=2).run(suite)
61    sys.exit(not result.wasSuccessful())
62