summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/OpenSSL/crypto.py2
-rw-r--r--tests/test_crypto.py14
2 files changed, 15 insertions, 1 deletions
diff --git a/src/OpenSSL/crypto.py b/src/OpenSSL/crypto.py
index b51e12f..e2956ae 100644
--- a/src/OpenSSL/crypto.py
+++ b/src/OpenSSL/crypto.py
@@ -345,7 +345,7 @@ class PKey(object):
rsa = _lib.EVP_PKEY_get1_RSA(self._pkey)
rsa = _ffi.gc(rsa, _lib.RSA_free)
result = _lib.RSA_check_key(rsa)
- if result:
+ if result == 1:
return True
_raise_current_error()
diff --git a/tests/test_crypto.py b/tests/test_crypto.py
index b0e8e8b..34a9d6e 100644
--- a/tests/test_crypto.py
+++ b/tests/test_crypto.py
@@ -561,6 +561,12 @@ e3fJQJwX9+KsHRut6qNZDUbvRbtO1YIAwB4UJZjwAjEAtXCPURS5A4McZHnSwgTi
Td8GMrwKz0557OxxtKN6uVVy4ACFMqEw0zN/KJI1vxc9
-----END CERTIFICATE-----"""
+rsa_p_not_prime_pem = """
+-----BEGIN RSA PRIVATE KEY-----
+MBsCAQACAS0CAQcCAQACAQ8CAQMCAQACAQACAQA=
+-----END RSA PRIVATE KEY-----
+"""
+
@pytest.fixture
def x509_data():
@@ -966,6 +972,14 @@ class TestPKey(object):
with pytest.raises(TypeError):
pub.check()
+ def test_check_pr_897(self):
+ """
+ `PKey.check` raises `OpenSSL.crypto.Error` if provided with broken key
+ """
+ pkey = load_privatekey(FILETYPE_PEM, rsa_p_not_prime_pem)
+ with pytest.raises(Error):
+ pkey.check()
+
def x509_name(**attrs):
"""