summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openssl.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 8af1d3d..ee2cd68 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -285,6 +285,10 @@
285#define HAVE_X509_UP_REF OPENSSL_PREREQ(1,1,0) 285#define HAVE_X509_UP_REF OPENSSL_PREREQ(1,1,0)
286#endif 286#endif
287 287
288#ifndef HAVE_X509_STORE_UP_REF
289#define HAVE_X509_STORE_UP_REF OPENSSL_PREREQ(1,1,0)
290#endif
291
288#ifndef HMAC_INIT_EX_INT 292#ifndef HMAC_INIT_EX_INT
289#define HMAC_INIT_EX_INT OPENSSL_PREREQ(1,0,0) 293#define HMAC_INIT_EX_INT OPENSSL_PREREQ(1,0,0)
290#endif 294#endif
@@ -1637,6 +1641,18 @@ static int compat_X509_up_ref(X509 *crt) {
1637} /* compat_X509_up_ref() */ 1641} /* compat_X509_up_ref() */
1638#endif 1642#endif
1639 1643
1644#if !HAVE_X509_STORE_UP_REF
1645#define X509_STORE_up_ref(...) compat_X509_STORE_up_ref(__VA_ARGS__)
1646
1647static int compat_X509_STORE_up_ref(X509_STORE *crt) {
1648 /* our caller should already have had a proper reference */
1649 if (CRYPTO_add(&crt->references, 1, CRYPTO_LOCK_X509_STORE) < 2)
1650 return 0; /* fail */
1651
1652 return 1;
1653} /* compat_X509_STORE_up_ref() */
1654#endif
1655
1640static int compat_init(void) { 1656static int compat_init(void) {
1641 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 1657 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1642 static int store_index = -1, ssl_ctx_index = -1, done; 1658 static int store_index = -1, ssl_ctx_index = -1, done;
@@ -6826,6 +6842,16 @@ static int xs_new(lua_State *L) {
6826} /* xs_new() */ 6842} /* xs_new() */
6827 6843
6828 6844
6845static X509_STORE *xs_push(lua_State *L, X509_STORE *store) {
6846 X509_STORE **ud = prepsimple(L, X509_STORE_CLASS);
6847
6848 X509_STORE_up_ref(store);
6849 *ud = store;
6850
6851 return *ud;
6852} /* xs_push() */
6853
6854
6829static int xs_interpose(lua_State *L) { 6855static int xs_interpose(lua_State *L) {
6830 return interpose(L, X509_STORE_CLASS); 6856 return interpose(L, X509_STORE_CLASS);
6831} /* xs_interpose() */ 6857} /* xs_interpose() */
@@ -7348,6 +7374,20 @@ static int sx_setStore(lua_State *L) {
7348} /* sx_setStore() */ 7374} /* sx_setStore() */
7349 7375
7350 7376
7377static int sx_getStore(lua_State *L) {
7378 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
7379 X509_STORE *store;
7380
7381 if((store = SSL_CTX_get_cert_store(ctx))) {
7382 xs_push(L, store);
7383 } else {
7384 lua_pushnil(L);
7385 }
7386
7387 return 1;
7388} /* sx_getStore() */
7389
7390
7351static int sx_setVerify(lua_State *L) { 7391static int sx_setVerify(lua_State *L) {
7352 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); 7392 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
7353 int mode = luaL_optint(L, 2, -1); 7393 int mode = luaL_optint(L, 2, -1);
@@ -7614,6 +7654,7 @@ static const auxL_Reg sx_methods[] = {
7614 { "getOptions", &sx_getOptions }, 7654 { "getOptions", &sx_getOptions },
7615 { "clearOptions", &sx_clearOptions }, 7655 { "clearOptions", &sx_clearOptions },
7616 { "setStore", &sx_setStore }, 7656 { "setStore", &sx_setStore },
7657 { "getStore", &sx_getStore },
7617 { "setVerify", &sx_setVerify }, 7658 { "setVerify", &sx_setVerify },
7618 { "getVerify", &sx_getVerify }, 7659 { "getVerify", &sx_getVerify },
7619 { "setCertificate", &sx_setCertificate }, 7660 { "setCertificate", &sx_setCertificate },