diff options
author | Russ Housley <housley@vigilsec.com> | 2019-10-06 04:20:25 -0400 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-10-06 10:20:25 +0200 |
commit | 7da04e58044fbd2e0f43b441dad1a37b98286cf9 (patch) | |
tree | 8a8a660799506710d8fc87a939e270ec4a80526b /tests | |
parent | 4dfe517a355d939902d223decf1efc0a4409a96b (diff) | |
download | pyasn1-modules-7da04e58044fbd2e0f43b441dad1a37b98286cf9.tar.gz |
Add support for RFC 8209 (#74)
* Add support for RFC 8209
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__main__.py | 1 | ||||
-rw-r--r-- | tests/test_rfc8209.py | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/tests/__main__.py b/tests/__main__.py index 979b1ba..9b4cb18 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -61,6 +61,7 @@ suite = unittest.TestLoader().loadTestsFromNames( 'tests.test_rfc7906.suite', 'tests.test_rfc8018.suite', 'tests.test_rfc8103.suite', + 'tests.test_rfc8209.suite', 'tests.test_rfc8226.suite', 'tests.test_rfc8358.suite', 'tests.test_rfc8360.suite', diff --git a/tests/test_rfc8209.py b/tests/test_rfc8209.py new file mode 100644 index 0000000..1eb2efd --- /dev/null +++ b/tests/test_rfc8209.py @@ -0,0 +1,59 @@ +# +# This file is part of pyasn1-modules software. +# +# Created by Russ Housley +# Copyright (c) 2019, Vigil Security, LLC +# License: http://snmplabs.com/pyasn1/license.html +# + +import sys + +from pyasn1.codec.der.decoder import decode as der_decode +from pyasn1.codec.der.encoder import encode as der_encode + +from pyasn1_modules import pem +from pyasn1_modules import rfc5280 +from pyasn1_modules import rfc8209 + +try: + import unittest2 as unittest +except ImportError: + import unittest + +class CertificateTestCase(unittest.TestCase): + cert_pem_text = """\ +MIIBiDCCAS+gAwIBAgIEAk3WfDAKBggqhkjOPQQDAjAaMRgwFgYDVQQDDA9ST1VU +RVItMDAwMEZCRjAwHhcNMTcwMTAxMDUwMDAwWhcNMTgwNzAxMDUwMDAwWjAaMRgw +FgYDVQQDDA9ST1VURVItMDAwMEZCRjAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC +AARzkbq7kqDLO+EOWbGev/shTgSpHgy6GxOafTjZD3flWqBbjmlWeOD6FpBLVdnU +9cDfxYiV7lC8T3XSBaJb02/1o2MwYTALBgNVHQ8EBAMCB4AwHQYDVR0OBBYEFKtN +kQ9VyucaIV7zyv46zEW17sFUMBMGA1UdJQQMMAoGCCsGAQUFBwMeMB4GCCsGAQUF +BwEIAQH/BA8wDaAHMAUCAwD78KECBQAwCgYIKoZIzj0EAwIDRwAwRAIgB7e0al+k +8cxoNjkDpIPsfIAC0vYInUay7Cp75pKzb7ECIACRBUqh9bAYnSck6LQi/dEc8D2x +OCRdZCk1KI3uDDgp +""" + + def setUp(self): + self.asn1Spec = rfc5280.Certificate() + + def testDerCodec(self): + substrate = pem.readBase64fromText(self.cert_pem_text) + asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) + assert not rest + assert asn1Object.prettyPrint() + assert der_encode(asn1Object) == substrate + + for extn in asn1Object['tbsCertificate']['extensions']: + if extn['extnID'] in rfc5280.certificateExtensionsMap.keys(): + extnValue, rest = der_decode(extn['extnValue'], + asn1Spec=rfc5280.certificateExtensionsMap[extn['extnID']]) + assert der_encode(extnValue) == extn['extnValue'] + + if extn['extnID'] == rfc5280.id_ce_extKeyUsage: + assert rfc8209.id_kp_bgpsec_router in extnValue + + +suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) + +if __name__ == '__main__': + unittest.TextTestRunner(verbosity=2).run(suite) |