From 828c9cbbe7cf89e5e7e62f9d0ac29a6293a3165c Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 26 Apr 2008 18:06:54 -0400 Subject: 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. --- leakcheck/context-passphrase-callback.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 leakcheck/context-passphrase-callback.py (limited to 'leakcheck') 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() -- cgit v1.2.1