mirror of
https://github.com/brunoos/luasec.git
synced 2025-02-18 18:02:47 +01:00
commit
a9b81b1c10
31
src/x509.c
31
src/x509.c
@ -20,6 +20,8 @@
|
|||||||
#include <openssl/bio.h>
|
#include <openssl/bio.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
@ -103,6 +105,8 @@ static void push_asn1_string(lua_State* L, ASN1_STRING *string, int encode)
|
|||||||
lua_pushlstring(L, (char*)data, len);
|
lua_pushlstring(L, (char*)data, len);
|
||||||
OPENSSL_free(data);
|
OPENSSL_free(data);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +125,31 @@ static int push_asn1_time(lua_State *L, ASN1_UTCTIME *tm)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a human readable IP address.
|
||||||
|
*/
|
||||||
|
static void push_asn1_ip(lua_State *L, ASN1_STRING *string)
|
||||||
|
{
|
||||||
|
unsigned char *ip = ASN1_STRING_data(string);
|
||||||
|
char dst[INET6_ADDRSTRLEN];
|
||||||
|
int typ;
|
||||||
|
switch(ASN1_STRING_length(string)) {
|
||||||
|
case 4:
|
||||||
|
typ = AF_INET;
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
typ = AF_INET6;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
lua_pushnil(L);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(inet_ntop(typ, ip, dst, INET6_ADDRSTRLEN))
|
||||||
|
lua_pushstring(L, dst);
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -260,7 +289,7 @@ int meth_extensions(lua_State* L)
|
|||||||
case GEN_IPADD:
|
case GEN_IPADD:
|
||||||
lua_pushstring(L, "iPAddress");
|
lua_pushstring(L, "iPAddress");
|
||||||
push_subtable(L, -2);
|
push_subtable(L, -2);
|
||||||
push_asn1_string(L, general_name->d.iPAddress, px->encode);
|
push_asn1_ip(L, general_name->d.iPAddress);
|
||||||
lua_rawseti(L, -2, lua_rawlen(L, -2)+1);
|
lua_rawseti(L, -2, lua_rawlen(L, -2)+1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user