• 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.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 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_decode(substrate, asn1Spec=self.asn1Spec)
47        assert not rest
48        assert asn1Object.prettyPrint()
49        assert der_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        asn1Object, rest = der_decode(substrate,
77            asn1Spec=self.asn1Spec,
78            decodeOpenTypes=True)
79        assert not rest
80        assert asn1Object.prettyPrint()
81        assert der_encode(asn1Object) == substrate
82
83        assert asn1Object['contentType'] in rfc5652.cmsContentTypesMap
84        assert asn1Object['contentType'] == rfc5083.id_ct_authEnvelopedData
85        authenv = asn1Object['content']
86        assert authenv['version'] == 0
87
88        for attr in authenv['unauthAttrs']:
89            assert attr['attrType'] in rfc5652.cmsAttributesMap
90            if attr['attrType'] == rfc5035.id_aa_contentHint:
91                assert 'Watson' in attr['attrValues'][0]['contentDescription']
92
93
94suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
95
96if __name__ == '__main__':
97    import sys
98
99    result = unittest.TextTestRunner(verbosity=2).run(suite)
100    sys.exit(not result.wasSuccessful())
101