aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pyasn1-modules/py2/tests/test_rfc5940.py
blob: d55ba6e813df0859ce6f29394fe5161a4e16bf2d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#
# This file is part of pyasn1-modules software.
#
# Copyright (c) 2019, Vigil Security, LLC
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
import unittest

from pyasn1.codec.der.decoder import decode as der_decoder
from pyasn1.codec.der.encoder import encode as der_encoder

from pyasn1_modules import pem
from pyasn1_modules import rfc2560
from pyasn1_modules import rfc5940
from pyasn1_modules import rfc5652
from pyasn1_modules import rfc5280


class CRLandOCSPResponseTestCase(unittest.TestCase):
    pem_text = """\
MIIHWQYJKoZIhvcNAQcCoIIHSjCCB0YCAQExDTALBglghkgBZQMEAgEwUwYJKoZI
hvcNAQcBoEYERENvbnRlbnQtVHlwZTogdGV4dC9wbGFpbg0KDQpXYXRzb24sIGNv
bWUgaGVyZSAtIEkgd2FudCB0byBzZWUgeW91Lg0KoIIBaDCCAWQwggEKoAMCAQIC
CQClWUKCJkwnGTAKBggqhkjOPQQDAjAkMRQwEgYDVQQKDAtleGFtcGxlLm9yZzEM
MAoGA1UEAwwDQm9iMB4XDTE3MTIyMDIzMDc0OVoXDTE4MTIyMDIzMDc0OVowJDEU
MBIGA1UECgwLZXhhbXBsZS5vcmcxDDAKBgNVBAMMA0JvYjBZMBMGByqGSM49AgEG
CCqGSM49AwEHA0IABIZP//xT8ah2ymmxfidI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self):
        self.asn1Spec = rfc5652.ContentInfo()

    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.pem_text)

        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertEqual(rfc5652.id_signedData, asn1Object['contentType'])

        sd, rest = der_decoder(
            asn1Object['content'], asn1Spec=rfc5652.SignedData())

        self.assertTrue(sd.prettyPrint())

        self.assertEqual(
            rfc5652.id_data, sd['encapContentInfo']['eContentType'])
        self.assertTrue(sd['encapContentInfo']['eContent'])

        v2 = rfc5280.Version(value='v2')

        self.assertEqual(v2, sd['crls'][0]['crl']['tbsCertList']['version'])

        ocspr_oid = rfc5940.id_ri_ocsp_response

        self.assertEqual(ocspr_oid, sd['crls'][1]['other']['otherRevInfoFormat'])

        ocspr, rest = der_decoder(
            sd['crls'][1]['other']['otherRevInfo'],
            asn1Spec=rfc5940.OCSPResponse())

        self.assertTrue(ocspr.prettyPrint())

        success = rfc2560.OCSPResponseStatus(value='successful')

        self.assertEqual(success, ocspr['responseStatus'])

    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertEqual(rfc5652.id_signedData, asn1Object['contentType'])

        sd_eci = asn1Object['content']['encapContentInfo']

        self.assertEqual(rfc5652.id_data, sd_eci['eContentType'])
        self.assertTrue(sd_eci['eContent'].hasValue())

        for ri in asn1Object['content']['crls']:
            if ri.getName() == 'crl':
                v2 = rfc5280.Version(value='v2')
                self.assertEqual(v2, ri['crl']['tbsCertList']['version'])

            if ri.getName() == 'other':
                ori = ri['other']
                ocspr_oid = rfc5940.id_ri_ocsp_response

                self.assertEqual(ocspr_oid, ori['otherRevInfoFormat'])

                ocspr_status = ori['otherRevInfo']['responseStatus']
                success = rfc2560.OCSPResponseStatus(value='successful')

                self.assertEqual(success, ocspr_status)


suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])

if __name__ == '__main__':
    result = unittest.TextTestRunner(verbosity=2).run(suite)
    sys.exit(not result.wasSuccessful())