From cf29ce37627fd6ba4416dd9eb5e56bed44128131 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Thu, 5 May 2016 00:02:04 +0200 Subject: [PATCH] stupidgcm: set dummy locking callback. In general, OpenSSL is only threadsafe if you provide a locking function through CRYPTO_set_locking_callback. However, the GCM operations that stupidgcm uses never call that function. To guard against that ever changing, set a dummy locking callback that crashes the app. --- internal/stupidgcm/locking.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 internal/stupidgcm/locking.go diff --git a/internal/stupidgcm/locking.go b/internal/stupidgcm/locking.go new file mode 100644 index 0000000..06add56 --- /dev/null +++ b/internal/stupidgcm/locking.go @@ -0,0 +1,26 @@ +package stupidgcm + +// In general, OpenSSL is only threadsafe if you provide a locking function +// through CRYPTO_set_locking_callback. However, the GCM operations that +// stupidgcm uses never call that function. Additionally, the manual locking +// has been removed completely in openssl 1.1.0. + +/* +#include +#include + +static void dummy_callback(int mode, int n, const char *file, int line) { + printf("stupidgcm: thread locking is not implemented and should not be " + "needed. Please upgrade openssl.\n"); + // panic + *((int*)0)=0; +} +static void set_dummy_callback() { + CRYPTO_set_locking_callback(dummy_callback); +} +*/ +import "C" + +func init() { + C.set_dummy_callback() +}