• 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) 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 rfc3281
16
17try:
18    import unittest2 as unittest
19
20except ImportError:
21    import unittest
22
23
24class AttributeCertificateTestCase(unittest.TestCase):
25    pem_text = """\
26MIIDBTCCAm4CAQEwgY+gUTBKpEgwRjEjMCEGA1UEAwwaQUNNRSBJbnRlcm1lZGlh
27dGUgRUNEU0EgQ0ExCzAJBgNVBAYTAkZJMRIwEAYDVQQKDAlBQ01FIEx0ZC4CAx7N
28WqE6pDgwNjETMBEGA1UEAwwKQUNNRSBFQ0RTQTELMAkGA1UEBhMCRkkxEjAQBgNV
29BAoMCUFDTUUgTHRkLqA9MDukOTA3MRQwEgYDVQQDDAtleGFtcGxlLmNvbTELMAkG
30A1UEBhMCRkkxEjAQBgNVBAoMCUFDTUUgTHRkLjANBgkqhkiG9w0BAQsFAAIEC63K
31/jAiGA8yMDE2MDEwMTEyMDAwMFoYDzIwMTYwMzAxMTIwMDAwWjCB8jA8BggrBgEF
32BQcKATEwMC6GC3VybjpzZXJ2aWNlpBUwEzERMA8GA1UEAwwIdXNlcm5hbWUECHBh
33c3N3b3JkMDIGCCsGAQUFBwoCMSYwJIYLdXJuOnNlcnZpY2WkFTATMREwDwYDVQQD
34DAh1c2VybmFtZTA1BggrBgEFBQcKAzEpMCegGKQWMBQxEjAQBgNVBAMMCUFDTUUg
35THRkLjALDAlBQ01FIEx0ZC4wIAYIKwYBBQUHCgQxFDASMBAMBmdyb3VwMQwGZ3Jv
36dXAyMCUGA1UESDEeMA2hC4YJdXJuOnJvbGUxMA2hC4YJdXJuOnJvbGUyMGowHwYD
37VR0jBBgwFoAUgJCMhskAsEBzvklAX8yJBOXO500wCQYDVR04BAIFADA8BgNVHTcB
38Af8EMjAwMB2gCoYIdXJuOnRlc3SgD4INKi5leGFtcGxlLmNvbTAPoA2GC3Vybjph
39bm90aGVyMA0GCSqGSIb3DQEBCwUAA4GBACygfTs6TkPurZQTLufcE3B1H2707OXK
40sJlwRpuodR2oJbunSHZ94jcJHs5dfbzFs6vNfVLlBiDBRieX4p+4JcQ2P44bkgyi
41UTJu7g1b6C1liB3vO6yH5hOZicOAaKd+c/myuGb9uJ4n6y2oLNxnk/fDzpuZUe2h
42Q4eikPk4LQey
43"""
44
45    def setUp(self):
46        self.asn1Spec = rfc3281.AttributeCertificate()
47
48    def testDerCodec(self):
49        substrate = pem.readBase64fromText(self.pem_text)
50        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
51        assert not rest
52        assert asn1Object.prettyPrint()
53        assert der_encode(asn1Object) == substrate
54
55        assert asn1Object['acinfo']['version'] == 1
56
57        attributeMap = {
58            rfc3281.id_at_role: rfc3281.RoleSyntax(),
59            rfc3281.id_aca_authenticationInfo: rfc3281.SvceAuthInfo(),
60            rfc3281.id_aca_accessIdentity: rfc3281.SvceAuthInfo(),
61            rfc3281.id_aca_chargingIdentity: rfc3281.IetfAttrSyntax(),
62            rfc3281.id_aca_group: rfc3281.IetfAttrSyntax(),
63        }
64
65        count = 0
66        for attr in asn1Object['acinfo']['attributes']:
67            assert attr['type'] in attributeMap
68            av, rest = der_decode(attr['values'][0],
69                asn1Spec=attributeMap[attr['type']])
70            assert not rest
71            assert av.prettyPrint()
72            assert der_encode(av) == attr['values'][0]
73            count += 1
74
75        assert count == 5
76
77
78suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
79
80if __name__ == '__main__':
81    import sys
82
83    result = unittest.TextTestRunner(verbosity=2).run(suite)
84    sys.exit(not result.wasSuccessful())
85