diff options
| author | daurnimator <quae@daurnimator.com> | 2016-11-07 23:29:45 +1100 |
|---|---|---|
| committer | daurnimator <quae@daurnimator.com> | 2016-11-07 23:33:44 +1100 |
| commit | f603c7ac366b90649d8635b600dd646f40dac25a (patch) | |
| tree | 0c3a3e96f5ac7344520f3bc3bcbcb282b177a4fc | |
| parent | cb727f97f2e00512c70631210de2d8b951e81587 (diff) | |
| download | luaossl-f603c7ac366b90649d8635b600dd646f40dac25a.tar.gz luaossl-f603c7ac366b90649d8635b600dd646f40dac25a.tar.bz2 luaossl-f603c7ac366b90649d8635b600dd646f40dac25a.zip | |
openssl.x509.store: Add xs_push to push an existing X509_STORE
| -rw-r--r-- | src/openssl.c | 26 |
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 @@ | |||
| 259 | #define HAVE_X509_UP_REF OPENSSL_PREREQ(1,1,0) | 259 | #define HAVE_X509_UP_REF OPENSSL_PREREQ(1,1,0) |
| 260 | #endif | 260 | #endif |
| 261 | 261 | ||
| 262 | #ifndef HAVE_X509_STORE_UP_REF | ||
| 263 | #define HAVE_X509_STORE_UP_REF OPENSSL_PREREQ(1,1,0) | ||
| 264 | #endif | ||
| 265 | |||
| 262 | #ifndef HMAC_INIT_EX_INT | 266 | #ifndef HMAC_INIT_EX_INT |
| 263 | #define HMAC_INIT_EX_INT OPENSSL_PREREQ(1,0,0) | 267 | #define HMAC_INIT_EX_INT OPENSSL_PREREQ(1,0,0) |
| 264 | #endif | 268 | #endif |
| @@ -1599,6 +1603,18 @@ static int compat_X509_up_ref(X509 *crt) { | |||
| 1599 | } /* compat_X509_up_ref() */ | 1603 | } /* compat_X509_up_ref() */ |
| 1600 | #endif | 1604 | #endif |
| 1601 | 1605 | ||
| 1606 | #if !HAVE_X509_STORE_UP_REF | ||
| 1607 | #define X509_STORE_up_ref(...) compat_X509_STORE_up_ref(__VA_ARGS__) | ||
| 1608 | |||
| 1609 | static int compat_X509_STORE_up_ref(X509_STORE *crt) { | ||
| 1610 | /* our caller should already have had a proper reference */ | ||
| 1611 | if (CRYPTO_add(&crt->references, 1, CRYPTO_LOCK_X509_STORE) < 2) | ||
| 1612 | return 0; /* fail */ | ||
| 1613 | |||
| 1614 | return 1; | ||
| 1615 | } /* compat_X509_STORE_up_ref() */ | ||
| 1616 | #endif | ||
| 1617 | |||
| 1602 | static int compat_init(void) { | 1618 | static int compat_init(void) { |
| 1603 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | 1619 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
| 1604 | static int store_index = -1, ssl_ctx_index = -1, done; | 1620 | static int store_index = -1, ssl_ctx_index = -1, done; |
| @@ -6744,6 +6760,16 @@ static int xs_new(lua_State *L) { | |||
| 6744 | } /* xs_new() */ | 6760 | } /* xs_new() */ |
| 6745 | 6761 | ||
| 6746 | 6762 | ||
| 6763 | static X509_STORE *xs_push(lua_State *L, X509_STORE *store) { | ||
| 6764 | X509_STORE **ud = prepsimple(L, X509_STORE_CLASS); | ||
| 6765 | |||
| 6766 | X509_STORE_up_ref(store); | ||
| 6767 | *ud = store; | ||
| 6768 | |||
| 6769 | return *ud; | ||
| 6770 | } /* xs_push() */ | ||
| 6771 | |||
| 6772 | |||
| 6747 | static int xs_interpose(lua_State *L) { | 6773 | static int xs_interpose(lua_State *L) { |
| 6748 | return interpose(L, X509_STORE_CLASS); | 6774 | return interpose(L, X509_STORE_CLASS); |
| 6749 | } /* xs_interpose() */ | 6775 | } /* xs_interpose() */ |
