aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-12-01 12:02:50 +0300
committeralexv-smirnov <alex@ydb.tech>2023-12-01 13:28:10 +0300
commit0e578a4c44d4abd539d9838347b9ebafaca41dfb (patch)
treea0c1969c37f818c830ebeff9c077eacf30be6ef8 /contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py
parent84f2d3d4cc985e63217cff149bd2e6d67ae6fe22 (diff)
downloadydb-0e578a4c44d4abd539d9838347b9ebafaca41dfb.tar.gz
Change "ya.make"
Diffstat (limited to 'contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py')
-rw-r--r--contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py157
1 files changed, 157 insertions, 0 deletions
diff --git a/contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py b/contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py
new file mode 100644
index 0000000000..e970dfa7dd
--- /dev/null
+++ b/contrib/python/pyasn1-modules/py3/tests/test_rfc6402.py
@@ -0,0 +1,157 @@
+#
+# This file is part of pyasn1-modules software.
+#
+# Created by Russ Housley
+# 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.type import char
+from pyasn1.type import namedtype
+from pyasn1.type import univ
+
+from pyasn1_modules import pem
+from pyasn1_modules import rfc5652
+from pyasn1_modules import rfc6402
+
+
+class BackwardCompatibilityTestCase(unittest.TestCase):
+ pem_text = """\
+MIIEJQYJKoZIhvcNAQcCoIIEFjCCBBICAQMxCzAJBgUrDgMCGgUAMIIDAgYIKwYBBQUHDAKgggL0
+BIIC8DCCAuwweDB2AgECBgorBgEEAYI3CgoBMWUwYwIBADADAgEBMVkwVwYJKwYBBAGCNxUUMUow
+SAIBBQwZ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QEJBDEWBBTFTkK/OifaFjwqHiJu
+xM7qXcg/VzANBgkqhkiG9w0BAQEFAASBgKfC6jOi1Wgy4xxDCQVK9+e5tktL8wE/j2cb9JSqq+aU
+5UxEgXEw7q7BoYZCAzcxMRriGzakXr8aXHcgkRJ7XcFvLPUjpmGg9SOZ2sGW4zQdWAwImN/i8loc
+xicQmJP+VoMHo/ZpjFY9fYCjNZUArgKsEwK/s+p9yrVVeB1Nf8Mn
+"""
+
+ def testDerCodec(self):
+ layers = { }
+ layers.update(rfc5652.cmsContentTypesMap)
+
+ getNextLayer = {
+ rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
+ rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'],
+ rfc6402.id_cct_PKIData: lambda x: None
+ }
+
+ getNextSubstrate = {
+ rfc5652.id_ct_contentInfo: lambda x: x['content'],
+ rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
+ rfc6402.id_cct_PKIData: lambda x: None
+ }
+
+ substrate = pem.readBase64fromText(self.pem_text)
+
+ next_layer = rfc5652.id_ct_contentInfo
+ while next_layer:
+ asn1Object, rest = der_decoder(substrate, asn1Spec=layers[next_layer])
+ self.assertFalse(rest)
+ self.assertTrue(asn1Object.prettyPrint())
+ self.assertEqual(substrate, der_encoder(asn1Object))
+
+ substrate = getNextSubstrate[next_layer](asn1Object)
+ next_layer = getNextLayer[next_layer](asn1Object)
+
+
+ def testOpenTypes(self):
+ class ClientInformation(univ.Sequence):
+ pass
+
+ ClientInformation.componentType = namedtype.NamedTypes(
+ namedtype.NamedType('clientId', univ.Integer()),
+ namedtype.NamedType('MachineName', char.UTF8String()),
+ namedtype.NamedType('UserName', char.UTF8String()),
+ namedtype.NamedType('ProcessName', char.UTF8String())
+ )
+
+ class EnrollmentCSP(univ.Sequence):
+ pass
+
+ EnrollmentCSP.componentType = namedtype.NamedTypes(
+ namedtype.NamedType('KeySpec', univ.Integer()),
+ namedtype.NamedType('Name', char.BMPString()),
+ namedtype.NamedType('Signature', univ.BitString())
+ )
+
+ openTypeMap = {
+ # attributes
+ univ.ObjectIdentifier('1.3.6.1.4.1.311.13.2.3'): char.IA5String(),
+ univ.ObjectIdentifier('1.3.6.1.4.1.311.13.2.2'): EnrollmentCSP(),
+ univ.ObjectIdentifier('1.3.6.1.4.1.311.21.20'): ClientInformation(),
+ # algorithm identifier parameters
+ univ.ObjectIdentifier('1.2.840.113549.1.1.1'): univ.Null(""),
+ univ.ObjectIdentifier('1.2.840.113549.1.1.5'): univ.Null(""),
+ univ.ObjectIdentifier('1.2.840.113549.1.1.11'): univ.Null(""),
+ }
+
+ openTypeMap.update(rfc5652.cmsAttributesMap)
+ openTypeMap.update(rfc6402.cmcControlAttributesMap)
+
+ substrate = pem.readBase64fromText(self.pem_text)
+ asn1Object, rest = der_decoder(
+ substrate, asn1Spec=rfc5652.ContentInfo(), decodeOpenTypes=True)
+
+ self.assertFalse(rest)
+ self.assertTrue(asn1Object.prettyPrint())
+ self.assertEqual(substrate, der_encoder(asn1Object))
+
+ eci = asn1Object['content']['encapContentInfo']
+
+ self.assertEqual(rfc6402.id_cct_PKIData, eci['eContentType'])
+
+ substrate = eci['eContent']
+ asn1Object, rest = der_decoder(
+ substrate, asn1Spec=rfc6402.PKIData(), openTypes=openTypeMap,
+ decodeOpenTypes=True)
+
+ self.assertFalse(rest)
+ self.assertTrue(asn1Object.prettyPrint())
+ self.assertEqual(substrate, der_encoder(asn1Object))
+
+ for req in asn1Object['reqSequence']:
+ cr = req['tcr']['certificationRequest']
+
+ sig_alg = cr['signatureAlgorithm']
+
+ self.assertIn(sig_alg['algorithm'], openTypeMap)
+ self.assertEqual(univ.Null(""), sig_alg['parameters'])
+
+ cri = cr['certificationRequestInfo']
+ spki_alg = cri['subjectPublicKeyInfo']['algorithm']
+
+ self.assertIn(spki_alg['algorithm'], openTypeMap)
+ self.assertEqual(univ.Null(""), spki_alg['parameters'])
+
+ attrs = cr['certificationRequestInfo']['attributes']
+ for attr in attrs:
+ self.assertIn( attr['attrType'], openTypeMap)
+
+ if attr['attrType'] == univ.ObjectIdentifier('1.3.6.1.4.1.311.13.2.3'):
+ self.assertEqual("6.2.9200.2", attr['attrValues'][0])
+
+ else:
+ self.assertTrue(attr['attrValues'][0].hasValue())
+
+
+suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
+
+if __name__ == '__main__':
+ unittest.TextTestRunner(verbosity=2).run(suite)