diff options
author | Russ Housley <housley@vigilsec.com> | 2019-05-31 01:23:02 -0400 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-05-31 07:23:02 +0200 |
commit | 61b5149d1b1e50a212f64846ffc90a9222f51a83 (patch) | |
tree | cc4d0f3a975f22da7b2d3b6cc210a3c6e7302666 | |
parent | 9901a7f012fb77aa406921c9e423b2c0cb8e37e4 (diff) | |
download | pyasn1-modules-61b5149d1b1e50a212f64846ffc90a9222f51a83.tar.gz |
Add support for RFC 5915 (#40)
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | pyasn1_modules/rfc5915.py | 32 | ||||
-rw-r--r-- | tests/__main__.py | 1 | ||||
-rw-r--r-- | tests/test_rfc5915.py | 48 |
4 files changed, 82 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index eab86ba..1b4652d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -16,6 +16,7 @@ Revision 0.2.6, released XX-05-2019 - Added RFC3274 providing CMS Compressed Data Content Type - Added RFC4073 providing Multiple Contents protection with CMS - Added RFC2634 providing Enhanced Security Services for S/MIME +- Added RFC5915 providing Elliptic Curve Private Key Revision 0.2.5, released 24-04-2019 ----------------------------------- diff --git a/pyasn1_modules/rfc5915.py b/pyasn1_modules/rfc5915.py new file mode 100644 index 0000000..82ff4a3 --- /dev/null +++ b/pyasn1_modules/rfc5915.py @@ -0,0 +1,32 @@ +# This file is being contributed to pyasn1-modules software. +# +# Created by Russ Housley with assistance from asn1ate v.0.6.0. +# +# Copyright (c) 2019, Vigil Security, LLC +# License: http://snmplabs.com/pyasn1/license.html +# +# Elliptic Curve Private Key +# +# ASN.1 source from: +# https://www.rfc-editor.org/rfc/rfc5915.txt + +from pyasn1.type import namedtype +from pyasn1.type import namedval +from pyasn1.type import tag +from pyasn1.type import univ + +from pyasn1_modules import rfc5480 + + +class ECPrivateKey(univ.Sequence): + pass + +ECPrivateKey.componentType = namedtype.NamedTypes( + namedtype.NamedType('version', univ.Integer( + namedValues=namedval.NamedValues(('ecPrivkeyVer1', 1)))), + namedtype.NamedType('privateKey', univ.OctetString()), + namedtype.OptionalNamedType('parameters', rfc5480.ECParameters().subtype( + explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))), + namedtype.OptionalNamedType('publicKey', univ.BitString().subtype( + explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))) +) diff --git a/tests/__main__.py b/tests/__main__.py index 360f4d8..a76ce57 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -36,6 +36,7 @@ suite = unittest.TestLoader().loadTestsFromNames( 'tests.test_rfc5480.suite', 'tests.test_rfc5649.suite', 'tests.test_rfc5652.suite', + 'tests.test_rfc5915.suite', 'tests.test_rfc5958.suite', 'tests.test_rfc6019.suite', 'tests.test_rfc8103.suite', diff --git a/tests/test_rfc5915.py b/tests/test_rfc5915.py new file mode 100644 index 0000000..1c581e1 --- /dev/null +++ b/tests/test_rfc5915.py @@ -0,0 +1,48 @@ +# +# 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 + +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 rfc5915 +from pyasn1_modules import rfc5480 + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +class MUDCertTestCase(unittest.TestCase): + private_key_pem_text = """\ +MIGkAgEBBDDLjzGbbLrR3T13lrrVum7WC/4Ua4Femc1RhhNVe1Q5XsArQ33kn9kx +3lOUfOcG+qagBwYFK4EEACKhZANiAAT4zZ8HL+xEDpXWkoWp5xFMTz4u4Ae1nF6z +XCYlmsEGD5vPu5hl9hDEjd1UHRgJIPoy3fJcWWeZ8FHCirICtuMgFisNscG/aTwK +yDYOFDuqz/C2jyEwqgWCRyxyohuJXtk= +""" + + def setUp(self): + self.asn1Spec = rfc5915.ECPrivateKey() + + def testDerCodec(self): + substrate = pem.readBase64fromText(self.private_key_pem_text) + asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) + assert not rest + assert asn1Object.prettyPrint() + assert der_encode(asn1Object) == substrate + + assert asn1Object['parameters']['namedCurve'] == rfc5480.secp384r1 + + +suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) + +if __name__ == '__main__': + unittest.TextTestRunner(verbosity=2).run(suite) |