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.type import univ 13 14from pyasn1_modules import pem 15from pyasn1_modules import rfc2560 16from pyasn1_modules import rfc5940 17from pyasn1_modules import rfc5652 18from pyasn1_modules import rfc5280 19 20try: 21 import unittest2 as unittest 22except ImportError: 23 import unittest 24 25 26class CRLandOCSPResponseTestCase(unittest.TestCase): 27 pem_text = """\ 28MIIHWQYJKoZIhvcNAQcCoIIHSjCCB0YCAQExDTALBglghkgBZQMEAgEwUwYJKoZI 29hvcNAQcBoEYERENvbnRlbnQtVHlwZTogdGV4dC9wbGFpbg0KDQpXYXRzb24sIGNv 30bWUgaGVyZSAtIEkgd2FudCB0byBzZWUgeW91Lg0KoIIBaDCCAWQwggEKoAMCAQIC 31CQClWUKCJkwnGTAKBggqhkjOPQQDAjAkMRQwEgYDVQQKDAtleGFtcGxlLm9yZzEM 32MAoGA1UEAwwDQm9iMB4XDTE3MTIyMDIzMDc0OVoXDTE4MTIyMDIzMDc0OVowJDEU 33MBIGA1UECgwLZXhhbXBsZS5vcmcxDDAKBgNVBAMMA0JvYjBZMBMGByqGSM49AgEG 34CCqGSM49AwEHA0IABIZP//xT8ah2ymmxfidIegeccVKuGxN+OTuvGq69EnQ8fUFD 35ov2KNw8Cup0DtzAfHaZOMFWUu2+Vy3H6SLbQo4OjJTAjMCEGA1UdEQEB/wQXMBWG 36E3NpcDpib2JAZXhhbXBsZS5vcmcwCgYIKoZIzj0EAwIDSAAwRQIhALIkjJJAKCI4 37nsklf2TM/RBvuguWwRkHMDTVGxAvczlsAiAVjrFR8IW5vS4EzyePDVIua7b+Tzb3 38THcQsVpPR53kDaGCBGQwggIbMIIBAwIBATANBgkqhkiG9w0BAQsFADBsMQswCQYD 39VQQGEwJVUzEVMBMGA1UEChMMRG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EAx4IAFQAZQBzAHQw 56HhcNMTkwMjAxMDUwMDAwWhcNMjIwMjAxMDUwMDAwWjAeMRwwCQYDVQQGEwJSVTAP 57BgNVBAMeCABUAGUAcwB0MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEM0jxEYgg 58RxC/r87uV/h6iZ8BAdHT/6fxRuzG0PRMIlFBy38skFUXJJulKV9JW16YJqOkVsqv 59xwMM61z7p1vQ/qMgMB4wDwYDVR0TBAgwBgEB/wIBAzALBgNVHQ8EBAMCAAYwCgYI 60KoZIzj0EAwIDSAAwRQIhAIdpCt5g89ofSADXmBD3KXQGnTghwbAMeWrKXqTGww+x 61AiAl8NQgfUk4xMymZ3VtCLJ2MdczDps4Zh2KPOqAR5fZAjGCAQcwggEDAgEBMDEw 62JDEUMBIGA1UECgwLZXhhbXBsZS5vcmcxDDAKBgNVBAMMA0JvYgIJAKVZQoImTCcZ 63MAsGCWCGSAFlAwQCAaBpMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZI 64hvcNAQkFMQ8XDTE5MDEyNDIzNTI1NlowLwYJKoZIhvcNAQkEMSIEIO93j8lA1ebc 65JXb0elmbMSYZWp8aInra81+iLAUNjRlaMAoGCCqGSM49BAMCBEcwRQIhAPeI7URq 66tw//LB/6TAN0/Qh3/WHukXwxRbOJpnYVx0b6AiB3lK3FfwBhx4S5YSPMblS7goJl 67ttTMEpl2prH8bbwo1g== 68""" 69 70 def setUp(self): 71 self.asn1Spec = rfc5652.ContentInfo() 72 73 def testDerCodec(self): 74 substrate = pem.readBase64fromText(self.pem_text) 75 76 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 77 78 assert not rest 79 assert asn1Object.prettyPrint() 80 assert der_encode(asn1Object) == substrate 81 82 assert asn1Object['contentType'] == rfc5652.id_signedData 83 sd, rest = der_decode(asn1Object['content'], 84 asn1Spec=rfc5652.SignedData()) 85 assert sd.prettyPrint() 86 87 assert sd['encapContentInfo']['eContentType'] == rfc5652.id_data 88 assert sd['encapContentInfo']['eContent'] 89 v2 = rfc5280.Version(value='v2') 90 assert sd['crls'][0]['crl']['tbsCertList']['version'] == v2 91 ocspr_oid = rfc5940.id_ri_ocsp_response 92 assert sd['crls'][1]['other']['otherRevInfoFormat'] == ocspr_oid 93 94 ocspr, rest = der_decode(sd['crls'][1]['other']['otherRevInfo'], 95 asn1Spec=rfc5940.OCSPResponse()) 96 assert ocspr.prettyPrint() 97 success = rfc2560.OCSPResponseStatus(value='successful') 98 assert ocspr['responseStatus'] == success 99 100 def testOpenTypes(self): 101 substrate = pem.readBase64fromText(self.pem_text) 102 asn1Object, rest = der_decode(substrate, 103 asn1Spec=self.asn1Spec, 104 decodeOpenTypes=True) 105 assert not rest 106 assert asn1Object.prettyPrint() 107 assert der_encode(asn1Object) == substrate 108 109 assert asn1Object['contentType'] == rfc5652.id_signedData 110 sd_eci = asn1Object['content']['encapContentInfo'] 111 assert sd_eci['eContentType'] == rfc5652.id_data 112 assert sd_eci['eContent'].hasValue() 113 114 for ri in asn1Object['content']['crls']: 115 if ri.getName() == 'crl': 116 v2 = rfc5280.Version(value='v2') 117 assert ri['crl']['tbsCertList']['version'] == v2 118 if ri.getName() == 'other': 119 ori = ri['other'] 120 ocspr_oid = rfc5940.id_ri_ocsp_response 121 assert ori['otherRevInfoFormat'] == ocspr_oid 122 ocspr_status = ori['otherRevInfo']['responseStatus'] 123 success = rfc2560.OCSPResponseStatus(value='successful') 124 assert ocspr_status == success 125 126 127suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 128 129if __name__ == '__main__': 130 import sys 131 132 result = unittest.TextTestRunner(verbosity=2).run(suite) 133 sys.exit(not result.wasSuccessful()) 134