diff options
author | Russ Housley <housley@vigilsec.com> | 2019-06-11 13:56:50 -0400 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-06-11 19:56:50 +0200 |
commit | 1de1622ed5751168b090e9aa3d78cec83d13f3fe (patch) | |
tree | e1245f0a1004add5b22dec6d8f9e79a27721919d | |
parent | 3aae55e849eb11259a2b5a7333a148993d46d14e (diff) | |
download | pyasn1-modules-1de1622ed5751168b090e9aa3d78cec83d13f3fe.tar.gz |
Add support for RFC 8619 (#43)
Add support for RFC 8619
-rw-r--r-- | CHANGES.txt | 1 | ||||
-rw-r--r-- | pyasn1_modules/rfc8619.py | 45 | ||||
-rw-r--r-- | tests/__main__.py | 3 | ||||
-rw-r--r-- | tests/test_rfc8619.py | 82 |
4 files changed, 130 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 7952dc9..3a7b723 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -19,6 +19,7 @@ Revision 0.2.6, released XX-05-2019 - Added RFC5915 providing Elliptic Curve Private Key - Added RFC5940 providing CMS Revocation Information Choices - Added RFC7296 providing IKEv2 Certificate Bundle +- Added RFC8619 providing HKDF Algorithm Identifiers Revision 0.2.5, released 24-04-2019 ----------------------------------- diff --git a/pyasn1_modules/rfc8619.py b/pyasn1_modules/rfc8619.py new file mode 100644 index 0000000..0aaa811 --- /dev/null +++ b/pyasn1_modules/rfc8619.py @@ -0,0 +1,45 @@ +# +# 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 +# +# Algorithm Identifiers for HKDF +# +# ASN.1 source from: +# https://www.rfc-editor.org/rfc/rfc8619.txt +# + +from pyasn1.type import univ + +from pyasn1_modules import rfc5280 + + +# Object Identifiers + +id_alg_hkdf_with_sha256 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.3.28') + + +id_alg_hkdf_with_sha384 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.3.29') + + +id_alg_hkdf_with_sha512 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.3.30') + + +# Key Derivation Algorithm Identifiers + +kda_hkdf_with_sha256 = rfc5280.AlgorithmIdentifier() +kda_hkdf_with_sha256['algorithm'] = id_alg_hkdf_with_sha256 +# kda_hkdf_with_sha256['parameters'] are absent + + +kda_hkdf_with_sha384 = rfc5280.AlgorithmIdentifier() +kda_hkdf_with_sha384['algorithm'] = id_alg_hkdf_with_sha384 +# kda_hkdf_with_sha384['parameters'] are absent + + +kda_hkdf_with_sha512 = rfc5280.AlgorithmIdentifier() +kda_hkdf_with_sha512['algorithm'] = id_alg_hkdf_with_sha512 +# kda_hkdf_with_sha512['parameters'] are absent diff --git a/tests/__main__.py b/tests/__main__.py index aa25f12..101a2b2 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -45,7 +45,8 @@ suite = unittest.TestLoader().loadTestsFromNames( 'tests.test_rfc8226.suite', 'tests.test_rfc8410.suite', 'tests.test_rfc8418.suite', - 'tests.test_rfc8520.suite'] + 'tests.test_rfc8520.suite', + 'tests.test_rfc8619.suite'] ) diff --git a/tests/test_rfc8619.py b/tests/test_rfc8619.py new file mode 100644 index 0000000..b030a38 --- /dev/null +++ b/tests/test_rfc8619.py @@ -0,0 +1,82 @@ +# +# 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 import decoder as der_decoder +from pyasn1.codec.der import encoder as der_encoder + +from pyasn1_modules import pem +from pyasn1_modules import rfc5280 +from pyasn1_modules import rfc8619 + +try: + import unittest2 as unittest +except ImportError: + import unittest + + +class HKDFSHA256TestCase(unittest.TestCase): + alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMc" + + def setUp(self): + self.asn1Spec = rfc5280.AlgorithmIdentifier() + + def testDerCodec(self): + + substrate = pem.readBase64fromText(self.alg_id_1_pem_text) + + asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) + + assert not rest + assert asn1Object.prettyPrint() + assert der_encoder.encode(asn1Object) == substrate + + assert asn1Object['algorithm'] == rfc8619.id_alg_hkdf_with_sha256 + + +class HKDFSHA384TestCase(unittest.TestCase): + alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMd" + + def setUp(self): + self.asn1Spec = rfc5280.AlgorithmIdentifier() + + def testDerCodec(self): + + substrate = pem.readBase64fromText(self.alg_id_1_pem_text) + + asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) + + assert not rest + assert asn1Object.prettyPrint() + assert der_encoder.encode(asn1Object) == substrate + + assert asn1Object['algorithm'] == rfc8619.id_alg_hkdf_with_sha384 + + +class HKDFSHA512TestCase(unittest.TestCase): + alg_id_1_pem_text = "MA0GCyqGSIb3DQEJEAMe" + + def setUp(self): + self.asn1Spec = rfc5280.AlgorithmIdentifier() + + def testDerCodec(self): + + substrate = pem.readBase64fromText(self.alg_id_1_pem_text) + + asn1Object, rest = der_decoder.decode(substrate, asn1Spec=self.asn1Spec) + + assert not rest + assert asn1Object.prettyPrint() + assert der_encoder.encode(asn1Object) == substrate + + assert asn1Object['algorithm'] == rfc8619.id_alg_hkdf_with_sha512 + + +suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) + +if __name__ == '__main__': + unittest.TextTestRunner(verbosity=2).run(suite) |