diff options
author | Ziga Seilnacht <ziga.seilnacht@gmail.com> | 2009-12-22 16:04:10 +0100 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@divmod.com> | 2009-12-22 16:04:10 +0100 |
commit | 376cf9796ec555bc0baa599ed9aba0c4959d4127 (patch) | |
tree | 375b44a02696db662350281fa6741fe2f8cc6726 /OpenSSL/test | |
parent | 781295ae151fb709e613d1d30f47f31426f8008e (diff) | |
download | pyopenssl-376cf9796ec555bc0baa599ed9aba0c4959d4127.tar.gz |
Raise an error if a passphrase is used with a private key format that does not support encryption.
Otherwise users might get an unpleasant surprise once they learn that their private key, which they
thought was secure, is in fact readable by everyone.
Diffstat (limited to 'OpenSSL/test')
-rw-r--r-- | OpenSSL/test/test_crypto.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py index e108528..dba9ce8 100644 --- a/OpenSSL/test/test_crypto.py +++ b/OpenSSL/test/test_crypto.py @@ -1979,6 +1979,18 @@ class FunctionTests(TestCase): load_privatekey, FILETYPE_PEM, encryptedPrivateKeyPEM, b("quack")) + def test_load_privatekey_passphraseWrongType(self): + """ + L{load_privatekey} raises C{ValueError} when it is passed a passphrase + with a private key encoded in a format, that doesn't support + encryption. + """ + key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM) + blob = dump_privatekey(FILETYPE_ASN1, key) + self.assertRaises(ValueError, + load_privatekey, FILETYPE_ASN1, blob, "secret") + + def test_load_privatekey_passphrase(self): """ :py:obj:`load_privatekey` can create a :py:obj:`PKey` object from an encrypted PEM @@ -2116,6 +2128,17 @@ class FunctionTests(TestCase): self.assertEqual(loadedKey.bits(), key.bits()) + def test_dump_privatekey_passphraseWrongType(self): + """ + L{dump_privatekey} raises C{ValueError} when it is passed a passphrase + with a private key encoded in a format, that doesn't support + encryption. + """ + key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM) + self.assertRaises(ValueError, + dump_privatekey, FILETYPE_ASN1, key, "blowfish", "secret") + + def test_dump_certificate(self): """ :py:obj:`dump_certificate` writes PEM, DER, and text. |