aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-11-07 23:29:45 +1100
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2016-11-07 23:33:44 +1100
commitf603c7ac366b90649d8635b600dd646f40dac25a (patch)
tree0c3a3e96f5ac7344520f3bc3bcbcb282b177a4fc /src
parentcb727f97f2e00512c70631210de2d8b951e81587 (diff)
downloadluaossl-f603c7ac366b90649d8635b600dd646f40dac25a.tar.gz
luaossl-f603c7ac366b90649d8635b600dd646f40dac25a.tar.bz2
luaossl-f603c7ac366b90649d8635b600dd646f40dac25a.zip
openssl.x509.store: Add xs_push to push an existing X509_STORE
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 4564061..d7b572e 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -259,6 +259,10 @@
#define HAVE_X509_UP_REF OPENSSL_PREREQ(1,1,0)
#endif
+#ifndef HAVE_X509_STORE_UP_REF
+#define HAVE_X509_STORE_UP_REF OPENSSL_PREREQ(1,1,0)
+#endif
+
#ifndef HMAC_INIT_EX_INT
#define HMAC_INIT_EX_INT OPENSSL_PREREQ(1,0,0)
#endif
@@ -1599,6 +1603,18 @@ static int compat_X509_up_ref(X509 *crt) {
} /* compat_X509_up_ref() */
#endif
+#if !HAVE_X509_STORE_UP_REF
+#define X509_STORE_up_ref(...) compat_X509_STORE_up_ref(__VA_ARGS__)
+
+static int compat_X509_STORE_up_ref(X509_STORE *crt) {
+ /* our caller should already have had a proper reference */
+ if (CRYPTO_add(&crt->references, 1, CRYPTO_LOCK_X509_STORE) < 2)
+ return 0; /* fail */
+
+ return 1;
+} /* compat_X509_STORE_up_ref() */
+#endif
+
static int compat_init(void) {
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int store_index = -1, ssl_ctx_index = -1, done;
@@ -6744,6 +6760,16 @@ static int xs_new(lua_State *L) {
} /* xs_new() */
+static X509_STORE *xs_push(lua_State *L, X509_STORE *store) {
+ X509_STORE **ud = prepsimple(L, X509_STORE_CLASS);
+
+ X509_STORE_up_ref(store);
+ *ud = store;
+
+ return *ud;
+} /* xs_push() */
+
+
static int xs_interpose(lua_State *L) {
return interpose(L, X509_STORE_CLASS);
} /* xs_interpose() */