diff options
author | Russ Housley <housley@vigilsec.com> | 2019-10-02 16:41:03 -0400 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-10-02 22:41:03 +0200 |
commit | 6b3ecead6ee42ce57986ac00d4e6639337aed7ba (patch) | |
tree | 4a17953e198bea4c167bbc1fcb08be6a783d0f6e | |
parent | fd7d16fdde4f47727f70944df8bf5e8f4701d1f4 (diff) | |
download | platform_external_python_pyasn1-modules-6b3ecead6ee42ce57986ac00d4e6639337aed7ba.tar.gz platform_external_python_pyasn1-modules-6b3ecead6ee42ce57986ac00d4e6639337aed7ba.tar.bz2 platform_external_python_pyasn1-modules-6b3ecead6ee42ce57986ac00d4e6639337aed7ba.zip |
Add support for RFC 8398 (#69)
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | pyasn1_modules/rfc8398.py | 52 | ||||
-rw-r--r-- | tests/__main__.py | 1 | ||||
-rw-r--r-- | tests/test_rfc8398.py | 67 |
4 files changed, 122 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index bbf2dc7..3d013c4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -34,6 +34,8 @@ Revision 0.2.7, released XX-09-2019 - Added RFC6210 providing Experiment for Hash Functions with Parameters - Added RFC5751 providing S/MIME Version 3.2 Message Specification - Added RFC8494 providing Multicast Email (MULE) over ACP 142 +- Added RFC8398 providing Internationalized Email Addresses in + X.509 Certificates Revision 0.2.6, released 31-07-2019 ----------------------------------- diff --git a/pyasn1_modules/rfc8398.py b/pyasn1_modules/rfc8398.py new file mode 100644 index 0000000..151b632 --- /dev/null +++ b/pyasn1_modules/rfc8398.py @@ -0,0 +1,52 @@ +# +# This file is part of pyasn1-modules software. +# +# Created by Russ Housley with some assistance from asn1ate v.0.6.0. +# +# Copyright (c) 2019, Vigil Security, LLC +# License: http://snmplabs.com/pyasn1/license.html +# +# Internationalized Email Addresses in X.509 Certificates +# +# ASN.1 source from: +# https://www.rfc-editor.org/rfc/rfc8398.txt +# https://www.rfc-editor.org/errata/eid5418 +# + +from pyasn1.type import char +from pyasn1.type import constraint +from pyasn1.type import univ + +from pyasn1_modules import rfc5280 + +MAX = float('inf') + + +# SmtpUTF8Mailbox contains Mailbox as specified in Section 3.3 of RFC 6531 + +id_pkix = rfc5280.id_pkix + +id_on = id_pkix + (8, ) + +id_on_SmtpUTF8Mailbox = id_on + (9, ) + + +class SmtpUTF8Mailbox(char.UTF8String): + pass + +SmtpUTF8Mailbox.subtypeSpec = constraint.ValueSizeConstraint(1, MAX) + + +on_SmtpUTF8Mailbox = rfc5280.AnotherName() +on_SmtpUTF8Mailbox['type-id'] = id_on_SmtpUTF8Mailbox +on_SmtpUTF8Mailbox['value'] = SmtpUTF8Mailbox() + + +# Map of Other Name OIDs to Other Name is added to the +# ones that are in rfc5280.py + +_anotherNameMapUpdate = { + id_on_SmtpUTF8Mailbox: SmtpUTF8Mailbox(), +} + +rfc5280.anotherNameMap.update(_anotherNameMapUpdate) diff --git a/tests/__main__.py b/tests/__main__.py index 391a23d..c90b2e2 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -62,6 +62,7 @@ suite = unittest.TestLoader().loadTestsFromNames( 'tests.test_rfc8018.suite', 'tests.test_rfc8103.suite', 'tests.test_rfc8226.suite', + 'tests.test_rfc8398.suite', 'tests.test_rfc8410.suite', 'tests.test_rfc8418.suite', 'tests.test_rfc8494.suite', diff --git a/tests/test_rfc8398.py b/tests/test_rfc8398.py new file mode 100644 index 0000000..0b27d4a --- /dev/null +++ b/tests/test_rfc8398.py @@ -0,0 +1,67 @@ +# +# This file is part of pyasn1-modules software. +# +# Copyright (c) 2019, Vigil Security, LLC +# License: http://snmplabs.com/pyasn1/license.html +# +import sys + +from pyasn1.codec.der.decoder import decode as der_decode +from pyasn1.codec.der.encoder import encode as der_encode + +from pyasn1_modules import pem +from pyasn1_modules import rfc5280 +from pyasn1_modules import rfc8398 + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +class EAITestCase(unittest.TestCase): + pem_text = "oCAGCCsGAQUFBwgJoBQMEuiAgeW4q0BleGFtcGxlLmNvbQ==" + + def setUp(self): + self.asn1Spec = rfc5280.GeneralName() + + def testDerCodec(self): + substrate = pem.readBase64fromText(self.pem_text) + asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) + assert not rest + assert asn1Object.prettyPrint() + assert der_encode(asn1Object) == substrate + + assert asn1Object['otherName']['type-id'] in rfc5280.anotherNameMap.keys() + assert asn1Object['otherName']['type-id'] == rfc8398.id_on_SmtpUTF8Mailbox + + eai, rest = der_decode(asn1Object['otherName']['value'], + asn1Spec=rfc5280.anotherNameMap[asn1Object['otherName']['type-id']]) + assert not rest + assert eai.prettyPrint() + assert der_encode(eai) == asn1Object['otherName']['value'] + + assert eai[0] == u'\u8001' + assert eai[1] == u'\u5E2B' + + def testOpenTypes(self): + substrate = pem.readBase64fromText(self.pem_text) + asn1Object, rest = der_decode(substrate, + asn1Spec=self.asn1Spec, + decodeOpenTypes=True) + assert not rest + assert asn1Object.prettyPrint() + assert der_encode(asn1Object) == substrate + + assert asn1Object['otherName']['type-id'] == rfc8398.id_on_SmtpUTF8Mailbox + assert asn1Object['otherName']['value'][0] == u'\u8001' + assert asn1Object['otherName']['value'][1] == u'\u5E2B' + + +suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) + +if __name__ == '__main__': + import sys + + result = unittest.TextTestRunner(verbosity=2).run(suite) + sys.exit(not result.wasSuccessful()) |