diff options
author | Alex Stapleton <alexs@prol.etari.at> | 2014-05-03 21:50:39 +0100 |
---|---|---|
committer | Alex Stapleton <alexs@prol.etari.at> | 2014-05-03 21:50:39 +0100 |
commit | 595393dd4d84f1bbb6541082b837c6cfb1aaa71b (patch) | |
tree | bdd6ac952da562695ebaab440aeeb75dbbfd221f | |
parent | d798d7a65ec94a990bd2fd17c864f80c30b01960 (diff) | |
download | cryptography-595393dd4d84f1bbb6541082b837c6cfb1aaa71b.tar.gz cryptography-595393dd4d84f1bbb6541082b837c6cfb1aaa71b.tar.bz2 cryptography-595393dd4d84f1bbb6541082b837c6cfb1aaa71b.zip |
DSA support
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_serialization.py | 22 |
2 files changed, 36 insertions, 0 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index aa3a9350..5a434dcd 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -396,9 +396,23 @@ class Backend(object): assert rsa_cdata != self._ffi.NULL rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free) return self._rsa_cdata_to_private_key(rsa_cdata) + elif type == self._lib.EVP_PKEY_DSA: + dsa_cdata = self._lib.EVP_PKEY_get1_DSA(evp_pkey) + assert dsa_cdata != self._ffi.NULL + dsa_cdata = self._ffi.gc(dsa_cdata, self._lib.DSA_free) + return self._dsa_cdata_to_private_key(dsa_cdata) else: raise UnsupportedAlgorithm("Unsupported key type.") + def _dsa_cdata_to_private_key(self, cdata): + return dsa.DSAPrivateKey( + modulus=self._bn_to_int(cdata.p), + subgroup_order=self._bn_to_int(cdata.q), + generator=self._bn_to_int(cdata.g), + x=self._bn_to_int(cdata.priv_key), + y=self._bn_to_int(cdata.pub_key) + ) + def _rsa_cdata_to_private_key(self, cdata): return rsa.RSAPrivateKey( p=self._bn_to_int(cdata.p), diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 7e6987c4..8d3b8fd4 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -19,6 +19,7 @@ import textwrap import pytest +from cryptography.hazmat.primitives.asymmetric import dsa, rsa from cryptography.hazmat.primitives.serialization import ( load_pem_traditional_openssl_private_key ) @@ -48,8 +49,29 @@ class TestTraditionalOpenSSLSerialisation(object): ) assert key + assert isinstance(key, rsa.RSAPrivateKey) _check_rsa_private_key(key) + @pytest.mark.parametrize( + ("key_file", "password"), + [ + ("dsa.1024.pem", None), + ("dsa.2048.pem", None), + ("dsa.3072.pem", None), + ] + ) + def test_load_pem_dsa_private_key(self, key_file, password, backend): + key = load_vectors_from_file( + os.path.join( + "asymmetric", "Traditional_OpenSSL_Serialization", key_file), + lambda pemfile: load_pem_traditional_openssl_private_key( + pemfile.read().encode(), password, backend + ) + ) + + assert key + assert isinstance(key, dsa.DSAPrivateKey) + def test_key1_pem_encrypted_values(self, backend): pkey = load_vectors_from_file( os.path.join( |