diff options
| author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-21 18:34:00 -0600 | 
|---|---|---|
| committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-25 07:49:52 -0600 | 
| commit | f83e25c81bb186ed8a96d4a569d5068546a24349 (patch) | |
| tree | a34d97e993351ac1396e8d7481457cee21118171 /tests/hazmat/backends/test_openssl.py | |
| parent | 36394237388d19eacd3a80e79bf8c459cb234700 (diff) | |
| download | cryptography-f83e25c81bb186ed8a96d4a569d5068546a24349.tar.gz cryptography-f83e25c81bb186ed8a96d4a569d5068546a24349.tar.bz2 cryptography-f83e25c81bb186ed8a96d4a569d5068546a24349.zip | |
Support for traditional OpenSSL and PKCS8 RSA private key serialization
Diffstat (limited to 'tests/hazmat/backends/test_openssl.py')
| -rw-r--r-- | tests/hazmat/backends/test_openssl.py | 29 | 
1 files changed, 27 insertions, 2 deletions
| diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 0e4d75ed..35b7c5c3 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -15,11 +15,12 @@ import pytest  from cryptography import utils  from cryptography.exceptions import InternalError, _Reasons +from cryptography.hazmat.backends.interfaces import RSABackend  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 +from cryptography.hazmat.primitives import hashes, serialization  from cryptography.hazmat.primitives.asymmetric import dsa, padding  from cryptography.hazmat.primitives.ciphers import (      BlockCipherAlgorithm, Cipher, CipherAlgorithm @@ -27,7 +28,7 @@ from cryptography.hazmat.primitives.ciphers import (  from cryptography.hazmat.primitives.ciphers.algorithms import AES  from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR, Mode -from ..primitives.fixtures_rsa import RSA_KEY_512 +from ..primitives.fixtures_rsa import RSA_KEY_2048, RSA_KEY_512  from ...utils import load_vectors_from_file, raises_unsupported_algorithm @@ -493,3 +494,27 @@ 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=RSABackend) +class TestRSAPEMSerialization(object): +    def test_password_length_limit(self): +        password = b"x" * 1024 +        key = RSA_KEY_2048.private_key(backend) +        with pytest.raises(ValueError): +            key.dump( +                serialization.PKCS8( +                    serialization.Encoding.PEM +                ), +                serialization.BestAvailable(password) +            ) + +    def test_unsupported_key_encoding(self): +        key = RSA_KEY_2048.private_key(backend) +        with pytest.raises(ValueError): +            key.dump( +                serialization.PKCS8( +                    serialization.Encoding.DER +                ), +                serialization.NoEncryption() +            ) | 
