summaryrefslogtreecommitdiff
path: root/OpenSSL/test
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@divmod.com>2009-05-13 14:14:30 -0400
committerJean-Paul Calderone <exarkun@divmod.com>2009-05-13 14:14:30 -0400
commit55ec1714c9e17f865d21416bca7522e44c16cd26 (patch)
treefe78b7d58508e6ec54a145f5852136acb64ce78a /OpenSSL/test
parent8e6ce97e2d8a7d142d03b5b877575e75fd2074ef (diff)
downloadpyopenssl-55ec1714c9e17f865d21416bca7522e44c16cd26.tar.gz
test the negative path through PKeyType.check
Diffstat (limited to 'OpenSSL/test')
-rw-r--r--OpenSSL/test/test_crypto.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index 6c0ee31..a22ad12 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -207,6 +207,7 @@ MbzjS007Oe4qqBnCWaFPSnJX6uLApeTbqAxAeyCql56ULW5x6vDMNC3dwjvS/CEh
11n8RkgFIQA0AhuKSIg3CbuartRsJnWOLwgLTzsrKYL4yRog1RJrtw==
-----END RSA PRIVATE KEY-----
""")
+
encryptedPrivateKeyPEMPassphrase = b("foobar")
# Some PKCS#7 stuff. Generated with the openssl command line:
@@ -250,6 +251,21 @@ vrzEeLDRiiPl92dyyWmu
-----END X509 CRL-----
""")
+
+# A broken RSA private key which can be used to test the error path through
+# PKey.check.
+inconsistentPrivateKeyPEM = b("""-----BEGIN RSA PRIVATE KEY-----
+MIIBPAIBAAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh
+5kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEaAQJBAIqm/bz4NA1H++Vx5Ewx
+OcKp3w19QSaZAwlGRtsUxrP7436QjnREM3Bm8ygU11BjkPVmtrKm6AayQfCHqJoT
+zIECIQDW0BoMoL0HOYM/mrTLhaykYAVqgIeJsPjvkEhTFXWBuQIhAM3deFAvWNu4
+nklUQ37XsCT2c9tmNt1LAT+slG2JOTTRAiAuXDtC/m3NYVwyHfFm+zKHRzHkClk2
+HjubeEgjpj32AQIhAJqMGTaZVOwevTXvvHwNeH+vRWsAYU/gbx+OQB+7VOcBAiEA
+oolb6NMg/R3enNPvS1O4UU1H8wpaF77L4yiSWlE0p4w=
+-----END RSA PRIVATE KEY-----
+""")
+
+
class X509ExtTests(TestCase):
"""
Tests for L{OpenSSL.crypto.X509Extension}.
@@ -512,11 +528,13 @@ class PKeyTests(TestCase):
def test_pregeneration(self):
"""
L{PKeyType.bits} and L{PKeyType.type} return C{0} before the key is
+ generated. L{PKeyType.check} raises L{TypeError} before the key is
generated.
"""
key = PKey()
self.assertEqual(key.type(), 0)
self.assertEqual(key.bits(), 0)
+ self.assertRaises(TypeError, key.check)
def test_failedGeneration(self):
@@ -595,6 +613,13 @@ class PKeyTests(TestCase):
self.assertEqual(key.bits(), bits)
+ def test_inconsistentKey(self):
+ """
+ L{PKeyType.check} returns C{False} if the key is not consistent.
+ """
+ key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM)
+ self.assertFalse(key.check())
+
class X509NameTests(TestCase):
"""