diff options
Diffstat (limited to 'tests/hazmat')
-rw-r--r-- | tests/hazmat/backends/test_multibackend.py | 88 | ||||
-rw-r--r-- | tests/hazmat/backends/test_openssl.py | 44 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_serialization.py | 67 |
3 files changed, 35 insertions, 164 deletions
diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index 03aa3cd8..43ecbf83 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -4,8 +4,6 @@ from __future__ import absolute_import, division, print_function -import pytest - from cryptography import utils from cryptography.exceptions import ( UnsupportedAlgorithm, _Reasons @@ -13,8 +11,7 @@ from cryptography.exceptions import ( from cryptography.hazmat.backends.interfaces import ( CMACBackend, CipherBackend, DSABackend, EllipticCurveBackend, HMACBackend, HashBackend, PBKDF2HMACBackend, PEMSerializationBackend, - PKCS8SerializationBackend, RSABackend, - TraditionalOpenSSLSerializationBackend, X509Backend + RSABackend, X509Backend ) from cryptography.hazmat.backends.multibackend import MultiBackend from cryptography.hazmat.primitives import cmac, hashes, hmac @@ -169,31 +166,11 @@ class DummyEllipticCurveBackend(object): if not self.elliptic_curve_supported(numbers.public_numbers.curve): raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE) - def elliptic_curve_private_key_from_numbers(self, numbers): - if not self.elliptic_curve_supported(numbers.public_numbers.curve): - raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE) - - def elliptic_curve_public_key_from_numbers(self, numbers): - if not self.elliptic_curve_supported(numbers.curve): - raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE) - def load_elliptic_curve_public_numbers(self, numbers): if not self.elliptic_curve_supported(numbers.curve): raise UnsupportedAlgorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE) -@utils.register_interface(PKCS8SerializationBackend) -class DummyPKCS8SerializationBackend(object): - def load_pkcs8_pem_private_key(self, data, password): - pass - - -@utils.register_interface(TraditionalOpenSSLSerializationBackend) -class DummyTraditionalOpenSSLSerializationBackend(object): - def load_traditional_openssl_pem_private_key(self, data, password): - pass - - @utils.register_interface(PEMSerializationBackend) class DummyPEMSerializationBackend(object): def load_pem_private_key(self, data, password): @@ -457,69 +434,6 @@ class TestMultiBackend(object): ) ) - def test_deprecated_elliptic_curve(self): - backend = MultiBackend([ - DummyEllipticCurveBackend([ - ec.SECT283K1 - ]) - ]) - - assert backend.elliptic_curve_signature_algorithm_supported( - ec.ECDSA(hashes.SHA256()), - ec.SECT163K1() - ) is False - - pub_numbers = ec.EllipticCurvePublicNumbers(2, 3, ec.SECT283K1()) - numbers = ec.EllipticCurvePrivateNumbers(1, pub_numbers) - - pytest.deprecated_call( - backend.elliptic_curve_private_key_from_numbers, - numbers - ) - pytest.deprecated_call( - backend.elliptic_curve_public_key_from_numbers, - pub_numbers - ) - - with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE): - backend.elliptic_curve_private_key_from_numbers( - ec.EllipticCurvePrivateNumbers( - 1, - ec.EllipticCurvePublicNumbers( - 2, - 3, - ec.SECT163K1() - ) - ) - ) - - with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE): - backend.elliptic_curve_public_key_from_numbers( - ec.EllipticCurvePublicNumbers( - 2, - 3, - ec.SECT163K1() - ) - ) - - def test_pkcs8_serialization_backend(self): - backend = MultiBackend([DummyPKCS8SerializationBackend()]) - - backend.load_pkcs8_pem_private_key(b"keydata", None) - - backend = MultiBackend([]) - with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_SERIALIZATION): - backend.load_pkcs8_pem_private_key(b"keydata", None) - - def test_traditional_openssl_serialization_backend(self): - backend = MultiBackend([DummyTraditionalOpenSSLSerializationBackend()]) - - backend.load_traditional_openssl_pem_private_key(b"keydata", None) - - backend = MultiBackend([]) - with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_SERIALIZATION): - backend.load_traditional_openssl_pem_private_key(b"keydata", None) - def test_pem_serialization_backend(self): backend = MultiBackend([DummyPEMSerializationBackend()]) diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index dfd0abe1..b6bb5491 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -15,20 +15,18 @@ import pytest from cryptography import utils from cryptography.exceptions import InternalError, _Reasons -from cryptography.hazmat.backends.interfaces import EllipticCurveBackend from cryptography.hazmat.backends.openssl.backend import ( Backend, backend ) from cryptography.hazmat.backends.openssl.ec import _sn_to_elliptic_curve from cryptography.hazmat.primitives import hashes, interfaces -from cryptography.hazmat.primitives.asymmetric import dsa, ec, padding +from cryptography.hazmat.primitives.asymmetric import dsa, padding from cryptography.hazmat.primitives.ciphers import Cipher from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR from cryptography.hazmat.primitives.interfaces import BlockCipherAlgorithm from ..primitives.fixtures_rsa import RSA_KEY_512 -from ..primitives.test_ec import _skip_curve_unsupported from ...utils import load_vectors_from_file, raises_unsupported_algorithm @@ -458,7 +456,7 @@ class TestOpenSSLSerialisationWithOpenSSL(object): "key1.pem" ), lambda pemfile: ( - backend.load_traditional_openssl_pem_private_key( + backend.load_pem_private_key( pemfile.read().encode(), password ) ) @@ -481,41 +479,3 @@ class TestOpenSSLEllipticCurve(object): def test_sn_to_elliptic_curve_not_supported(self): with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_ELLIPTIC_CURVE): _sn_to_elliptic_curve(backend, b"fake") - - -@pytest.mark.requires_backend_interface(interface=EllipticCurveBackend) -class TestDeprecatedECBackendMethods(object): - def test_elliptic_curve_private_key_from_numbers(self): - d = 5634846038258869671139984276180670841223409490498798721258 - y = 4131560123026307384858369684985976479488628761329758810693 - x = 3402090428547195623222463880060959356423657484435591627791 - curve = ec.SECP192R1() - _skip_curve_unsupported(backend, curve) - pub_numbers = ec.EllipticCurvePublicNumbers( - x=x, - y=y, - curve=curve - ) - numbers = ec.EllipticCurvePrivateNumbers( - private_value=d, - public_numbers=pub_numbers - ) - pytest.deprecated_call( - backend.elliptic_curve_private_key_from_numbers, - numbers - ) - - def test_elliptic_curve_public_key_from_numbers(self): - y = 4131560123026307384858369684985976479488628761329758810693 - x = 3402090428547195623222463880060959356423657484435591627791 - curve = ec.SECP192R1() - _skip_curve_unsupported(backend, curve) - pub_numbers = ec.EllipticCurvePublicNumbers( - x=x, - y=y, - curve=curve - ) - pytest.deprecated_call( - backend.elliptic_curve_public_key_from_numbers, - pub_numbers - ) diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 91db318c..341ccf80 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -11,9 +11,7 @@ import pytest from cryptography.exceptions import UnsupportedAlgorithm, _Reasons from cryptography.hazmat.backends.interfaces import ( - DSABackend, EllipticCurveBackend, PEMSerializationBackend, - PKCS8SerializationBackend, RSABackend, - TraditionalOpenSSLSerializationBackend + DSABackend, EllipticCurveBackend, PEMSerializationBackend, RSABackend ) from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.asymmetric import ec @@ -22,8 +20,7 @@ from cryptography.hazmat.primitives.asymmetric.dsa import ( ) from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers from cryptography.hazmat.primitives.serialization import ( - load_pem_pkcs8_private_key, load_pem_private_key, load_pem_public_key, - load_pem_traditional_openssl_private_key, load_ssh_public_key + load_pem_private_key, load_pem_public_key, load_ssh_public_key ) @@ -138,7 +135,7 @@ class TestPEMSerialization(object): @pytest.mark.requires_backend_interface( - interface=TraditionalOpenSSLSerializationBackend + interface=PEMSerializationBackend ) class TestTraditionalOpenSSLSerialization(object): @pytest.mark.parametrize( @@ -154,7 +151,7 @@ class TestTraditionalOpenSSLSerialization(object): key = load_vectors_from_file( os.path.join( "asymmetric", "Traditional_OpenSSL_Serialization", key_file), - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -176,7 +173,7 @@ class TestTraditionalOpenSSLSerialization(object): key = load_vectors_from_file( os.path.join( "asymmetric", "Traditional_OpenSSL_Serialization", key_file), - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -188,7 +185,7 @@ class TestTraditionalOpenSSLSerialization(object): pkey = load_vectors_from_file( os.path.join( "asymmetric", "Traditional_OpenSSL_Serialization", "key1.pem"), - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), b"123456", backend ) ) @@ -235,7 +232,7 @@ class TestTraditionalOpenSSLSerialization(object): with pytest.raises(TypeError): load_vectors_from_file( key_file, - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -251,7 +248,7 @@ class TestTraditionalOpenSSLSerialization(object): with pytest.raises(ValueError): load_vectors_from_file( key_file, - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -267,7 +264,7 @@ class TestTraditionalOpenSSLSerialization(object): with pytest.raises(TypeError): load_vectors_from_file( key_file, - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -276,12 +273,12 @@ class TestTraditionalOpenSSLSerialization(object): key_data = b"---- NOT A KEY ----\n" with pytest.raises(ValueError): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, None, backend ) with pytest.raises(ValueError): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, b"this password will not be used", backend ) @@ -299,12 +296,12 @@ class TestTraditionalOpenSSLSerialization(object): """).encode() with pytest.raises(ValueError): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, None, backend ) with pytest.raises(ValueError): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, b"this password will not be used", backend ) @@ -328,12 +325,12 @@ class TestTraditionalOpenSSLSerialization(object): password = b"this password is wrong" with pytest.raises(ValueError): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, None, backend ) with pytest.raises(ValueError): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, password, backend ) @@ -356,12 +353,12 @@ class TestTraditionalOpenSSLSerialization(object): password = b"password" with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_CIPHER): - load_pem_traditional_openssl_private_key( + load_pem_private_key( key_data, password, backend ) -@pytest.mark.requires_backend_interface(interface=PKCS8SerializationBackend) +@pytest.mark.requires_backend_interface(interface=PEMSerializationBackend) class TestPKCS8Serialization(object): @pytest.mark.parametrize( ("key_file", "password"), @@ -385,7 +382,7 @@ class TestPKCS8Serialization(object): key = load_vectors_from_file( os.path.join( "asymmetric", "PKCS8", key_file), - lambda pemfile: load_pem_pkcs8_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -408,7 +405,7 @@ class TestPKCS8Serialization(object): key = load_vectors_from_file( os.path.join( "asymmetric", "PKCS8", key_file), - lambda pemfile: load_pem_pkcs8_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -425,7 +422,7 @@ class TestPKCS8Serialization(object): with pytest.raises(TypeError): load_vectors_from_file( key_file, - lambda pemfile: load_pem_pkcs8_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -438,7 +435,7 @@ class TestPKCS8Serialization(object): with pytest.raises(ValueError): load_vectors_from_file( key_file, - lambda pemfile: load_pem_pkcs8_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -454,7 +451,7 @@ class TestPKCS8Serialization(object): with pytest.raises(TypeError): load_vectors_from_file( key_file, - lambda pemfile: load_pem_pkcs8_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -463,12 +460,12 @@ class TestPKCS8Serialization(object): key_data = b"---- NOT A KEY ----\n" with pytest.raises(ValueError): - load_pem_pkcs8_private_key( + load_pem_private_key( key_data, None, backend ) with pytest.raises(ValueError): - load_pem_pkcs8_private_key( + load_pem_private_key( key_data, b"this password will not be used", backend ) @@ -493,12 +490,12 @@ class TestPKCS8Serialization(object): """).encode() with pytest.raises(ValueError): - load_pem_pkcs8_private_key( + load_pem_private_key( key_data, None, backend ) with pytest.raises(ValueError): - load_pem_pkcs8_private_key( + load_pem_private_key( key_data, b"this password will not be used", backend ) @@ -527,12 +524,12 @@ class TestPKCS8Serialization(object): password = b"this password is wrong" with pytest.raises(ValueError): - load_pem_pkcs8_private_key( + load_pem_private_key( key_data, None, backend ) with pytest.raises(ValueError): - load_pem_pkcs8_private_key( + load_pem_private_key( key_data, password, backend ) @@ -540,7 +537,7 @@ class TestPKCS8Serialization(object): pkey = load_vectors_from_file( os.path.join( "asymmetric", "PKCS8", "enc-rsa-pkcs8.pem"), - lambda pemfile: load_pem_pkcs8_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), b"foobar", backend ) ) @@ -606,7 +603,7 @@ class TestPKCS8Serialization(object): key = load_vectors_from_file( os.path.join( "asymmetric", "PKCS8", key_file), - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -665,7 +662,7 @@ class TestPKCS8Serialization(object): load_vectors_from_file( os.path.join( "asymmetric", "PKCS8", key_file), - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) @@ -681,7 +678,7 @@ class TestPKCS8Serialization(object): load_vectors_from_file( os.path.join( "asymmetric", "PKCS8", key_file), - lambda pemfile: load_pem_traditional_openssl_private_key( + lambda pemfile: load_pem_private_key( pemfile.read().encode(), password, backend ) ) |