• 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 rfc5652
14from pyasn1_modules import rfc6486
15
16try:
17    import unittest2 as unittest
18except ImportError:
19    import unittest
20
21
22class SignedManifestTestCase(unittest.TestCase):
23    manifest_pem_text = """\
24MIIHVAYJKoZIhvcNAQcCoIIHRTCCB0ECAQMxDTALBglghkgBZQMEAgEwgYwGCyqGSIb3DQEJ
25EAEaoH0EezB5AgIK5xgPMjAxMjEwMjMyMjI2MDNaGA8yMDEyMTAyNTIyMjYwM1oGCWCGSAFl
26AwQCATBGMEQWH1pYU0dCREJrTDgyVEZHSHVFNFZPWXRKUC1FNC5jcmwDIQCzTdC3GsuONsRq
27RFnYf8+AJ2NnCIgmnc3O8PyfGvn18aCCBO4wggTqMIID0qADAgECAgIK5zANBgkqhkiG9w0B
28AQsFADATMREwDwYDVQQDEwhBOTE5OTg4NTAeFw0xMjEwMjMyMjI2MDNaFw0xMjEwMjUyMjI2
29MDNaMBgxFjAUBgNVBAMTDTUwODcxOTdjLTIwZjcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
30ggEKAoIBAQDEl4R4LiCs6zyR/IAeaRCfz0O0mXXAUKt8bmG6DXzaDYNG8dnBjbrsM1L05sb4
312Ti4TyE1UXtwFFEwatsFQ2uRBn9gsKmDGOjW8TH1AYObmZW+hZlEN7OLSz2bmPLtxIMwiCq/
32vqmBJlMWPyCSym4iPnjzwWbJechqHSiTMOYGICF1QSW5xjJDAhRfeZG3nRY7TqfW8R2KJXeN
33cKSYSGNKzv79B8GCswmwU8J8kcuryIiqb7WtcK2B6VBsROIQHGXM0UV4Zbnvv9m9Fl0SjvZJ
34XyrzRjGzV2C00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un0pkImVSqPO11gqyKV9ZCwCJUa5U/zsWDMNrj
49MSZl1I3VoPs2rx997rLoiQiMqwGeoqfl7snpsL9OR/CazPmepuq3SyZNWcCrUGcGRhRdGScj
50Tm2EHne1GiRHapn46HWQ3am8jumEKv5u0gLT4Mi9CyZwkDyhotGTJZmdAmN7zzGCAaowggGm
51AgEDgBRtxs7I0EeRFdcNoyrnWMLu85IcVTALBglghkgBZQMEAgGgazAaBgkqhkiG9w0BCQMx
52DQYLKoZIhvcNAQkQARowHAYJKoZIhvcNAQkFMQ8XDTEyMTAyMzIyMjYwNFowLwYJKoZIhvcN
53AQkEMSIEIIu2XV8dT+rqQy5Cbpm3Tv5I1dwkLK8n2GesMGOr6/pEMA0GCSqGSIb3DQEBAQUA
54BIIBAFsd0zkl4dIHrqZts441T+w/5/ekymDLFwftk6W+Mi35Htjvm2IHOthnKHQsK5h6dnEh
556DfNfc6tACmzLnM+UG7ve+uAhfpA+CUJIoVhpQvDH7Ntql0cD1X3d9ng484jpkVoHhbUIYNR
56TyxvV4DV5EBbLYpx2HYf6wWa8TCobxUXNtw53OVA24ceavS+KvuDa0JQPFpbYUCS0UPMt/Im
57mtKrWTmRUr8sYWdIQn+SStUh8iAR5rmSVr+Pe7aFbe2ju2FPf08gnIjH/SdCrJuFK8q7Z5MT
58C9ijmXiajracUe+7eCluqgXRE8yRtnscWoA/9fVFz1lPwgEeNHLoaK7Sqew=
59"""
60
61    def testDerCodec(self):
62        substrate = pem.readBase64fromText(self.manifest_pem_text)
63
64        layers = { }
65        layers.update(rfc5652.cmsContentTypesMap)
66
67        getNextLayer = {
68            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
69            rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'],
70            rfc6486.id_ct_rpkiManifest: lambda x: None
71        }
72
73        getNextSubstrate = {
74            rfc5652.id_ct_contentInfo: lambda x: x['content'],
75            rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
76            rfc6486.id_ct_rpkiManifest: lambda x: None
77        }
78
79        next_layer = rfc5652.id_ct_contentInfo
80        while next_layer:
81            asn1Object, rest = der_decode(substrate, asn1Spec=layers[next_layer])
82            assert not rest
83            assert asn1Object.prettyPrint()
84            assert der_encode(asn1Object) == substrate
85
86            substrate = getNextSubstrate[next_layer](asn1Object)
87            next_layer = getNextLayer[next_layer](asn1Object)
88
89        assert asn1Object['version'] == 0
90        for f in asn1Object['fileList']:
91            assert f['file'] == 'ZXSGBDBkL82TFGHuE4VOYtJP-E4.crl'
92
93    def testOpenTypes(self):
94        substrate = pem.readBase64fromText(self.manifest_pem_text)
95        asn1Object, rest = der_decode(substrate,
96            asn1Spec=rfc5652.ContentInfo(),
97            decodeOpenTypes=True)
98        assert not rest
99        assert asn1Object.prettyPrint()
100        assert der_encode(asn1Object) == substrate
101
102        oid =  asn1Object['content']['encapContentInfo']['eContentType']
103        substrate = asn1Object['content']['encapContentInfo']['eContent']
104        assert oid in rfc5652.cmsContentTypesMap.keys()
105        asn1Object, rest = der_decode(substrate,
106            asn1Spec=rfc5652.cmsContentTypesMap[oid],
107            decodeOpenTypes=True)
108        assert not rest
109        assert asn1Object.prettyPrint()
110        assert der_encode(asn1Object) == substrate
111
112        assert asn1Object['version'] == 0
113        for f in asn1Object['fileList']:
114            assert f['file'] == 'ZXSGBDBkL82TFGHuE4VOYtJP-E4.crl'
115
116
117suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
118
119if __name__ == '__main__':
120    import sys
121
122    result = unittest.TextTestRunner(verbosity=2).run(suite)
123    sys.exit(not result.wasSuccessful())
124