From 42b3713eede3f5b417b0ce123fdcc9c4c24009d3 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 23 Feb 2014 19:13:19 -0600 Subject: add RSA verification support --- tests/hazmat/backends/test_multibackend.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index be1e76e2..5a8f9934 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -89,6 +89,10 @@ class DummyRSABackend(object): def create_rsa_signature_ctx(self, private_key, padding, algorithm): pass + def create_rsa_verification_ctx(self, public_key, signature, padding, + algorithm): + pass + class TestMultiBackend(object): def test_ciphers(self): @@ -165,6 +169,9 @@ class TestMultiBackend(object): backend.create_rsa_signature_ctx("private_key", padding.PKCS1v15(), hashes.MD5()) + backend.create_rsa_verification_ctx("public_key", "sig", + padding.PKCS1(), hashes.MD5()) + backend = MultiBackend([]) with pytest.raises(UnsupportedAlgorithm): backend.generate_rsa_private_key(key_size=1024, public_exponent=3) @@ -172,3 +179,7 @@ class TestMultiBackend(object): with pytest.raises(UnsupportedAlgorithm): backend.create_rsa_signature_ctx("private_key", padding.PKCS1v15(), hashes.MD5()) + + with pytest.raises(UnsupportedAlgorithm): + backend.create_rsa_verification_ctx("public_key", "sig", + padding.PKCS1(), hashes.MD5()) -- cgit v1.2.3 From dc720296556645f0641907e3618f6a1613c39fe7 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 25 Feb 2014 22:59:58 -0600 Subject: more PKCS1->PKCS1v15 --- tests/hazmat/backends/test_multibackend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_multibackend.py b/tests/hazmat/backends/test_multibackend.py index 5a8f9934..63168180 100644 --- a/tests/hazmat/backends/test_multibackend.py +++ b/tests/hazmat/backends/test_multibackend.py @@ -170,7 +170,7 @@ class TestMultiBackend(object): hashes.MD5()) backend.create_rsa_verification_ctx("public_key", "sig", - padding.PKCS1(), hashes.MD5()) + padding.PKCS1v15(), hashes.MD5()) backend = MultiBackend([]) with pytest.raises(UnsupportedAlgorithm): @@ -181,5 +181,5 @@ class TestMultiBackend(object): hashes.MD5()) with pytest.raises(UnsupportedAlgorithm): - backend.create_rsa_verification_ctx("public_key", "sig", - padding.PKCS1(), hashes.MD5()) + backend.create_rsa_verification_ctx( + "public_key", "sig", padding.PKCS1v15(), hashes.MD5()) -- cgit v1.2.3 From 235d3ce2b7ae13cf94c97c00f5aa89c40bc6763c Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Sat, 1 Mar 2014 20:54:13 +0000 Subject: Get rid of handle_errors --- tests/hazmat/backends/test_openssl.py | 39 +++++------------------------------ 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index b24808df..fb9b978d 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -71,46 +71,17 @@ class TestOpenSSL(object): with pytest.raises(UnsupportedAlgorithm): cipher.encryptor() - def test_handle_unknown_error(self): - with pytest.raises(InternalError): - backend._handle_error_code(0) - - backend._lib.ERR_put_error(backend._lib.ERR_LIB_EVP, 0, 0, - b"test_openssl.py", -1) - with pytest.raises(InternalError): - backend._handle_error(None) - - backend._lib.ERR_put_error( - backend._lib.ERR_LIB_EVP, - backend._lib.EVP_F_EVP_ENCRYPTFINAL_EX, - 0, - b"test_openssl.py", - -1 - ) - with pytest.raises(InternalError): - backend._handle_error(None) - - backend._lib.ERR_put_error( - backend._lib.ERR_LIB_EVP, - backend._lib.EVP_F_EVP_DECRYPTFINAL_EX, - 0, - b"test_openssl.py", - -1 - ) - with pytest.raises(InternalError): - backend._handle_error(None) - - def test_handle_multiple_errors(self): + def test_consume_errors(self): for i in range(10): backend._lib.ERR_put_error(backend._lib.ERR_LIB_EVP, 0, 0, b"test_openssl.py", -1) assert backend._lib.ERR_peek_error() != 0 - with pytest.raises(InternalError): - backend._handle_error(None) + errors = backend._consume_errors() assert backend._lib.ERR_peek_error() == 0 + assert len(errors) == 10 def test_openssl_error_string(self): backend._lib.ERR_put_error( @@ -121,8 +92,8 @@ class TestOpenSSL(object): -1 ) - with pytest.raises(InternalError) as exc: - backend._handle_error(None) + errors = backend._consume_errors() + exc = backend._unknown_error(errors[0]) assert ( "digital envelope routines:" -- cgit v1.2.3 From 1c979c6a28385e8c2f92ecd457fc0ebe48819536 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Sat, 1 Mar 2014 21:29:28 +0000 Subject: pep8 --- tests/hazmat/backends/test_openssl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index fb9b978d..9d48f4e8 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -14,7 +14,7 @@ import pytest from cryptography import utils -from cryptography.exceptions import UnsupportedAlgorithm, InternalError +from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.backends.openssl.backend import backend, Backend from cryptography.hazmat.primitives import interfaces, hashes from cryptography.hazmat.primitives.ciphers import Cipher -- cgit v1.2.3 From 94ee8b5c8570a330f9e3d30ae8313ec41b10b470 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Sat, 1 Mar 2014 22:08:49 +0000 Subject: raise InternalError --- tests/hazmat/backends/test_openssl.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests/hazmat/backends') diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 9d48f4e8..42c1b395 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -14,7 +14,7 @@ import pytest from cryptography import utils -from cryptography.exceptions import UnsupportedAlgorithm +from cryptography.exceptions import UnsupportedAlgorithm, InternalError from cryptography.hazmat.backends.openssl.backend import backend, Backend from cryptography.hazmat.primitives import interfaces, hashes from cryptography.hazmat.primitives.ciphers import Cipher @@ -118,6 +118,15 @@ class TestOpenSSL(object): b"data not multiple of block length" ) + def test_unknown_error_in_cipher_finalize(self): + cipher = Cipher(AES(b"\0" * 16), CBC(b"\0" * 16), backend=backend) + enc = cipher.encryptor() + enc.update(b"\0") + backend._lib.ERR_put_error(0, 0, 1, + b"test_openssl.py", -1) + with pytest.raises(InternalError): + enc.finalize() + def test_derive_pbkdf2_raises_unsupported_on_old_openssl(self): if backend.pbkdf2_hmac_supported(hashes.SHA256()): pytest.skip("Requires an older OpenSSL") -- cgit v1.2.3