• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# This file is part of pyasn1-modules software.
3#
4# Copyright (c) 2019, Vigil Security, LLC
5# License: http://snmplabs.com/pyasn1/license.html
6#
7import sys
8
9from pyasn1.codec.der.decoder import decode as der_decode
10from pyasn1.codec.der.encoder import encode as der_encode
11
12from pyasn1_modules import pem
13from pyasn1_modules import rfc4055
14from pyasn1_modules import rfc5280
15from pyasn1_modules import rfc8649
16
17try:
18    import unittest2 as unittest
19except ImportError:
20    import unittest
21
22
23class RootCertificateExtnTestCase(unittest.TestCase):
24    extn_pem_text = """\
25MGEGCisGAQQBg5IbAgEEUzBRMA0GCWCGSAFlAwQCAwUABEBxId+rK+WVDLOda2Yk
26FFRbqQAztXhs91j/RxHjYJIv/3gleQg3Qix/yQy2rIg3xysjCvHWw8AuYOGVh/sL
27GANG
28"""
29
30    def setUp(self):
31        self.asn1Spec = rfc5280.Extension()
32
33    def testDerCodec(self):
34        substrate = pem.readBase64fromText(self.extn_pem_text)
35        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
36        assert not rest
37        assert asn1Object.prettyPrint()
38        assert der_encode(asn1Object) == substrate
39
40        assert asn1Object['extnID'] == rfc8649.id_ce_hashOfRootKey
41        hashed_root_key, rest = der_decode(asn1Object['extnValue'],
42            rfc8649.HashedRootKey())
43        assert not rest
44        assert hashed_root_key.prettyPrint()
45        assert der_encode(hashed_root_key) == asn1Object['extnValue']
46
47        assert hashed_root_key['hashAlg']['algorithm'] == rfc4055.id_sha512
48
49    def testExtensionsMap(self):
50        substrate = pem.readBase64fromText(self.extn_pem_text)
51        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
52        assert not rest
53
54        assert asn1Object['extnID'] == rfc8649.id_ce_hashOfRootKey
55        assert asn1Object['extnID'] in rfc5280.certificateExtensionsMap.keys()
56
57
58suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
59
60if __name__ == '__main__':
61    import sys
62
63    result = unittest.TextTestRunner(verbosity=2).run(suite)
64    sys.exit(not result.wasSuccessful())
65