• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# This file is part of pyasn1-modules software.
3#
4# Created by Russ Housley
5# Copyright (c) 2018, 2019  Vigil Security, LLC
6# License: http://snmplabs.com/pyasn1/license.html
7#
8
9import sys
10
11from pyasn1.codec.der import decoder as der_decoder
12from pyasn1.codec.der import encoder as der_encoder
13
14from pyasn1_modules import pem
15from pyasn1_modules import rfc5652
16from pyasn1_modules import rfc5083
17from pyasn1_modules import rfc5035
18
19try:
20    import unittest2 as unittest
21except ImportError:
22    import unittest
23
24
25class AuthEnvelopedDataTestCase(unittest.TestCase):
26    pem_text = """\
27MIICdQIBADGCAiekggIjBgsqhkiG9w0BCRANATCCAhICAQAEE3B0Zi1rbWM6MTM2MTQxMjIx
28MTIwDQYLKoZIhvcNAQkQAzAwCwYJYIZIAWUDBAEtMIIBsDCCAawCAQKAFJ7rZ8m5WnTUTS8W
29OWaA6AG1y6ScMA0GCSqGSIb3DQEBAQUABIIBgHfnHNqDbyyql2NqX6UQggelWMTjwzJJ1L2e
30rbsj1bIAGmpIsUijw+fX8VOS7v1C9ui2Md9NFgCfkmKLo8T/jELqrk7MpMu09G5zDgeXzJfQ
31DFc115wbrWAUU3XP7XIb6TNOc3xtq4UxA5V6jNUK2XyWKpjzOtM7gm0VWIJGVVlYu+u32LQc
32CjRFb87kvOY/WEnjxQpCW8g+4V747Ud97dYpMub7TLJiRNZkdHnq8xEGKlXjVHSgc10lhphe
331kFGeCpfJEsqjtN7YsVzf65ri9Z+3FJ1IO4cnMDbzGhyRXkS7a0k58/miJbSj88PvzKNSURw
34pu4YHMQQX/mjT2ey1SY4ihPMuxxgTdCa04L0UxaRr7xAucz3n2UWShelm3IIjnWRlYdXypnX
35vKvwCLoeh5mJwUl1JNFPCQkQ487cKRyobUyNgXQKT4ZDHCgXciwsX5nTsom87Ixp5vqSDJ+D
36hXA0r/Caiu1vnY5X9GLHSkqgXkgqgUuu0LfcsQERD8psfQQogbiuZDqJmYt1Iau/pkuGfmee
37qeiM3aeQ4NZf9AFZUVWBGArPNHrvVDA3BgkqhkiG9w0BBwEwGwYJYIZIAWUDBAEuMA4EDMr+
38ur76ztut3sr4iIANmvLRbyFUf87+2bPvLQQMoOWSXMGE4BckY8RM
39"""
40
41    def setUp(self):
42        self.asn1Spec = rfc5083.AuthEnvelopedData()
43
44    def testDerCodec(self):
45        substrate = pem.readBase64fromText(self.pem_text)
46        asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec)
47        assert not rest
48        assert asn1Object.prettyPrint()
49        assert der_encoder.encode(asn1Object) == substrate
50
51
52class AuthEnvelopedDataOpenTypesTestCase(unittest.TestCase):
53    pem_text = """\
54MIICvQYLKoZIhvcNAQkQARegggKsMIICqAIBADGCAiekggIjBgsqhkiG9w0BCRAN
55ATCCAhICAQAEE3B0Zi1rbWM6MTM2MTQxMjIxMTIwDQYLKoZIhvcNAQkQAzAwCwYJ
56YIZIAWUDBAEtMIIBsDCCAawCAQKAFJ7rZ8m5WnTUTS8WOWaA6AG1y6ScMA0GCSqG
57SIb3DQEBAQUABIIBgHfnHNqDbyyql2NqX6UQggelWMTjwzJJ1L2erbsj1bIAGmpI
58sUijw+fX8VOS7v1C9ui2Md9NFgCfkmKLo8T/jELqrk7MpMu09G5zDgeXzJfQDFc1
5915wbrWAUU3XP7XIb6TNOc3xtq4UxA5V6jNUK2XyWKpjzOtM7gm0VWIJGVVlYu+u3
602LQcCjRFb87kvOY/WEnjxQpCW8g+4V747Ud97dYpMub7TLJiRNZkdHnq8xEGKlXj
61VHSgc10lhphe1kFGeCpfJEsqjtN7YsVzf65ri9Z+3FJ1IO4cnMDbzGhyRXkS7a0k
6258/miJbSj88PvzKNSURwpu4YHMQQX/mjT2ey1SY4ihPMuxxgTdCa04L0UxaRr7xA
63ucz3n2UWShelm3IIjnWRlYdXypnXvKvwCLoeh5mJwUl1JNFPCQkQ487cKRyobUyN
64gXQKT4ZDHCgXciwsX5nTsom87Ixp5vqSDJ+DhXA0r/Caiu1vnY5X9GLHSkqgXkgq
65gUuu0LfcsQERD8psfQQogbiuZDqJmYt1Iau/pkuGfmeeqeiM3aeQ4NZf9AFZUVWB
66GArPNHrvVDA3BgkqhkiG9w0BBwEwGwYJYIZIAWUDBAEuMA4EDMr+ur76ztut3sr4
67iIANmvLRbyFUf87+2bPvLQQMoOWSXMGE4BckY8RMojEwLwYLKoZIhvcNAQkQAgQx
68IDAeDBFXYXRzb24sIGNvbWUgaGVyZQYJKoZIhvcNAQcB
69"""
70
71    def setUp(self):
72        self.asn1Spec = rfc5652.ContentInfo()
73
74    def testDerCodec(self):
75        substrate = pem.readBase64fromText(self.pem_text)
76        rfc5652.cmsAttributesMap.update(rfc5035.ESSAttributeMap)
77        rfc5652.cmsContentTypesMap.update(rfc5083.cmsContentTypesMapUpdate)
78        asn1Object, rest = der_decoder.decode(substrate,
79                                              asn1Spec=self.asn1Spec,
80                                              decodeOpenTypes=True)
81        assert not rest
82        assert asn1Object.prettyPrint()
83        assert der_encoder.encode(asn1Object) == substrate
84
85        assert asn1Object['contentType'] in rfc5652.cmsContentTypesMap
86        assert asn1Object['contentType'] == rfc5083.id_ct_authEnvelopedData
87        authenv = asn1Object['content']
88        assert authenv['version'] == rfc5652.CMSVersion().subtype(value='v0')
89
90        for attr in authenv['unauthAttrs']:
91            assert attr['attrType'] in rfc5652.cmsAttributesMap
92            if attr['attrType'] == rfc5035.id_aa_contentHint:
93                assert 'Watson' in attr['attrValues'][0]['contentDescription']
94
95
96suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
97
98if __name__ == '__main__':
99    import sys
100
101    result = unittest.TextTestRunner(verbosity=2).run(suite)
102    sys.exit(not result.wasSuccessful())
103