summaryrefslogtreecommitdiff
path: root/leakcheck
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@boson>2008-04-26 18:06:54 -0400
committerJean-Paul Calderone <exarkun@boson>2008-04-26 18:06:54 -0400
commit828c9cbbe7cf89e5e7e62f9d0ac29a6293a3165c (patch)
treee36e09fe7ba56cd6b75e3c97905f289060532bbc /leakcheck
parent7e61f9fd138cebf5e7e8c15bfaf956dcdfb5582e (diff)
downloadpyopenssl-828c9cbbe7cf89e5e7e62f9d0ac29a6293a3165c.tar.gz
Fix a threading bug in passphrase callback support for context objects.
Also add a bunch of unit tests for loading and dumping private keys with passphrases.
Diffstat (limited to 'leakcheck')
-rw-r--r--leakcheck/context-passphrase-callback.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/leakcheck/context-passphrase-callback.py b/leakcheck/context-passphrase-callback.py
new file mode 100644
index 0000000..0f0933c
--- /dev/null
+++ b/leakcheck/context-passphrase-callback.py
@@ -0,0 +1,33 @@
+# Copyright (C) Jean-Paul Calderone 2008, All rights reserved
+#
+# Stress tester for thread-related bugs in global_passphrase_callback in
+# src/ssl/context.c. In 0.7 and earlier, this will somewhat reliably
+# segfault or abort after a few dozen to a few thousand iterations on an SMP
+# machine (generally not on a UP machine) due to uses of Python/C API
+# without holding the GIL.
+
+from itertools import count
+from threading import Thread
+
+from OpenSSL.SSL import Context, TLSv1_METHOD
+from OpenSSL.crypto import TYPE_RSA, FILETYPE_PEM, PKey, dump_privatekey
+
+k = PKey()
+k.generate_key(TYPE_RSA, 128)
+file('pkey.pem', 'w').write(dump_privatekey(FILETYPE_PEM, k, "blowfish", "foobar"))
+
+count = count()
+def go():
+ def cb(a, b, c):
+ print count.next()
+ return "foobar"
+ c = Context(TLSv1_METHOD)
+ c.set_passwd_cb(cb)
+ while 1:
+ c.use_privatekey_file('pkey.pem')
+
+threads = [Thread(target=go, args=()) for i in xrange(2)]
+for th in threads:
+ th.start()
+for th in threads:
+ th.join()