Merge pull request #126 from neheb/master

Get rid of some deprecation warnings with OpenSSL 1.1
This commit is contained in:
Bruno Silvestre 2019-10-13 19:42:19 -03:00 committed by GitHub
commit 3490d8d1c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -17,6 +17,7 @@
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/x509.h> #include <openssl/x509.h>
#include <openssl/x509v3.h> #include <openssl/x509v3.h>
#include <openssl/dh.h>
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>

View File

@ -912,6 +912,7 @@ static luaL_Reg funcs[] = {
*/ */
LSEC_API int luaopen_ssl_core(lua_State *L) LSEC_API int luaopen_ssl_core(lua_State *L)
{ {
#if OPENSSL_VERSION_NUMBER<0x10100000L
/* Initialize SSL */ /* Initialize SSL */
if (!SSL_library_init()) { if (!SSL_library_init()) {
lua_pushstring(L, "unable to initialize SSL library"); lua_pushstring(L, "unable to initialize SSL library");
@ -919,6 +920,7 @@ LSEC_API int luaopen_ssl_core(lua_State *L)
} }
OpenSSL_add_all_algorithms(); OpenSSL_add_all_algorithms();
SSL_load_error_strings(); SSL_load_error_strings();
#endif
#if defined(WITH_LUASOCKET) #if defined(WITH_LUASOCKET)
/* Initialize internal library */ /* Initialize internal library */

View File

@ -42,6 +42,10 @@
#define LSEC_ASN1_STRING_data(x) ASN1_STRING_data(x) #define LSEC_ASN1_STRING_data(x) ASN1_STRING_data(x)
#endif #endif
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define X509_get0_notBefore X509_get_notBefore
#define X509_get0_notAfter X509_get_notAfter
#endif
static const char* hex_tab = "0123456789abcdef"; static const char* hex_tab = "0123456789abcdef";
@ -174,7 +178,7 @@ static void push_asn1_string(lua_State* L, ASN1_STRING *string, int encode)
/** /**
* Return a human readable time. * Return a human readable time.
*/ */
static int push_asn1_time(lua_State *L, ASN1_UTCTIME *tm) static int push_asn1_time(lua_State *L, const ASN1_UTCTIME *tm)
{ {
char *tmp; char *tmp;
long size; long size;
@ -492,8 +496,8 @@ static int meth_valid_at(lua_State* L)
{ {
X509* cert = lsec_checkx509(L, 1); X509* cert = lsec_checkx509(L, 1);
time_t time = luaL_checkinteger(L, 2); time_t time = luaL_checkinteger(L, 2);
lua_pushboolean(L, (X509_cmp_time(X509_get_notAfter(cert), &time) >= 0 lua_pushboolean(L, (X509_cmp_time(X509_get0_notAfter(cert), &time) >= 0
&& X509_cmp_time(X509_get_notBefore(cert), &time) <= 0)); && X509_cmp_time(X509_get0_notBefore(cert), &time) <= 0));
return 1; return 1;
} }
@ -521,7 +525,7 @@ static int meth_serial(lua_State *L)
static int meth_notbefore(lua_State *L) static int meth_notbefore(lua_State *L)
{ {
X509* cert = lsec_checkx509(L, 1); X509* cert = lsec_checkx509(L, 1);
return push_asn1_time(L, X509_get_notBefore(cert)); return push_asn1_time(L, X509_get0_notBefore(cert));
} }
/** /**
@ -530,7 +534,7 @@ static int meth_notbefore(lua_State *L)
static int meth_notafter(lua_State *L) static int meth_notafter(lua_State *L)
{ {
X509* cert = lsec_checkx509(L, 1); X509* cert = lsec_checkx509(L, 1);
return push_asn1_time(L, X509_get_notAfter(cert)); return push_asn1_time(L, X509_get0_notAfter(cert));
} }
/** /**