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 rfc5280 16from pyasn1_modules import rfc7296 17 18from pyasn1.type.univ import noValue 19 20try: 21 import unittest2 as unittest 22except ImportError: 23 import unittest 24 25 26class CertBundleTestCase(unittest.TestCase): 27 cert_bundle_pem_text = """\ 28MIITfqCCA8kwggPFMIICraADAgECAhACrFwmagtAm48LefKuRiV3MA0GCSqGSIb3 29DQEBBQUAMGwxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAX 30BgNVBAsTEHd3dy5kaWdpY2VydC5jb20xKzApBgNVBAMTIkRpZ2lDZXJ0IEhpZ2gg 31QXNzdXJhbmNlIEVWIFJvb3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAw 32MDAwWjBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD 33VQQLExB3d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFz 34c3VyYW5jZSBFViBSb290IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC 35AQEAxszlc+b71LvlLS0ypt/lgT/JzSVJtnEqw9WUNGeiChywX2mmQLHEt7KP0Jik 36qUFZOtPclNY823Q4pErMTSWC90qlUxI47vNJbXGRfmO2q6Zfw6SE+E9iUb74xezb 37OJLjBuUIkQzEKEFV+8taiRV+ceg1v01yCT2+OjhQW3cxG42zxyRFmqesbQAUWgS3 38uhPrUQqYQUEiTmVhh4FBUKZ5XIneGUpX1S7mXRxTLH6YzRoGFqRoc9A0BBNcoXHT 39WnxV215k4TeHMFYE5RG0KYAS8Xk5iKICEXwnZreI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E50ERySS8vA6AKGCAh8wggIbMIIBAwIBATAN 121BgkqhkiG9w0BAQsFADBsMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQg 122SW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2Vy 123dCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBFw0xOTA1MDIyMjE1NTRaFw0xOTA1 124MjMyMjE1NTRaMDEwLwIQDPWCOBgZnlb4K9ZS7Sft6RcNMTgxMDI1MTYxMTM4WjAM 125MAoGA1UdFQQDCgEAoDAwLjAfBgNVHSMEGDAWgBSxPsNpA/i/RwHUmCYaCALvY2Qr 126wzALBgNVHRQEBAICAcQwDQYJKoZIhvcNAQELBQADggEBABPO3OA0OkQZ+RLVxz/c 127Nx5uNVEO416oOePkN0A4DxFztf337caS4OyfS9Wyu1j5yUdWJVpAKXSQeN95MqHk 128pSpYDssuqbuYjv8ViJfseGBgtXTczUzzNeNdY2uxMbCxuhmPkgacAo1lx9LkK2Sc 129YHWVbfFRF1UQ/dcmavaZsEOBNuLWOxQYA9MqfVNAymHe7vPqwm/8IY2FbHe9HsiJ 130ZfGxNWMDP5lmJiXmpntTeDQ2UjdiyXwGGKjyiSTFk2jVRutrGINufaoA/f7eCmIb 1314UDPbpMjVfD215dW8eBKouypCVoEvmCSSTacdiBI2yOluvMN0PzvPve0ECAE+D4e 132m9Y= 133""" 134 135 def setUp(self): 136 self.asn1Spec = rfc7296.CertificateBundle() 137 138 def testDerCodec(self): 139 substrate = pem.readBase64fromText(self.cert_bundle_pem_text) 140 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 141 assert not rest 142 assert asn1Object.prettyPrint() 143 assert der_encode(asn1Object) == substrate 144 145 cert_count = 0 146 crl_count = 0 147 unk_count = 0 148 for item in asn1Object: 149 if item.getName() == 'cert': 150 cert_count += 1 151 elif item.getName() == 'crl': 152 crl_count += 1 153 else: 154 unk_count += 1 155 156 assert cert_count == 3 157 assert crl_count == 2 158 assert unk_count == 0 159 160 161suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 162 163if __name__ == '__main__': 164 unittest.TextTestRunner(verbosity=2).run(suite) 165