Skip to content

Commit

Permalink
Don't test that invalid RSA keys can be imported (#1139)
Browse files Browse the repository at this point in the history
* Don't test that invalid RSA keys can be imported

test_check_pr_897 asserts that an invalid key is correctly detected as
invalid. However, in doing so, it also asserts that the invalid key is
considered *valid* at parse time.

Ideally, the underlying cryptography library would just call
RSA_check_key during parsing, but it would then fail this test. Make the
test more tolerant by allow either parsing or checking to throw an
error.

* Review comments, and also update the other test
  • Loading branch information
davidben authored Aug 12, 2022
1 parent 38f9b4e commit 301e29a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,10 +1206,11 @@ def test_regeneration(self):

def test_inconsistent_key(self):
"""
`PKey.check` returns `Error` if the key is not consistent.
Either `load_privatekey` or `PKey.check` returns `Error` if the key is
not consistent.
"""
key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
with pytest.raises(Error):
key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
key.check()

def test_check_public_key(self):
Expand All @@ -1228,10 +1229,11 @@ def test_check_public_key(self):

def test_check_pr_897(self):
"""
`PKey.check` raises `OpenSSL.crypto.Error` if provided with broken key
Either `load_privatekey` or `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 = load_privatekey(FILETYPE_PEM, rsa_p_not_prime_pem)
pkey.check()


Expand Down

0 comments on commit 301e29a

Please sign in to comment.