mirror of
https://github.com/brunoos/luasec.git
synced 2024-11-08 06:28:26 +01:00
Add key material export method
This commit is contained in:
parent
df27c62f4c
commit
371abcf718
37
src/ssl.c
37
src/ssl.c
@ -671,6 +671,42 @@ static int meth_getpeerfinished(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
static int meth_exportkeyingmaterial(lua_State *L)
|
||||
{
|
||||
p_ssl ssl = (p_ssl)luaL_checkudata(L, 1, "SSL:Connection");
|
||||
|
||||
if(ssl->state != LSEC_STATE_CONNECTED) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "closed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t llen = 0;
|
||||
const char *label = luaL_checklstring(L, 2, &llen);
|
||||
int olen = luaL_checkinteger(L, 3);
|
||||
size_t contextlen = 0;
|
||||
const unsigned char *context = NULL;
|
||||
|
||||
if(!lua_isnoneornil(L, 4)) {
|
||||
const unsigned char *context = (unsigned char *)luaL_checklstring(L, 4, &contextlen);
|
||||
}
|
||||
|
||||
/* temporary buffer memory-managed by Lua itself */
|
||||
unsigned char *out = lua_newuserdata(L, olen);
|
||||
|
||||
if(SSL_export_keying_material(ssl->ssl, out, olen, label, llen, context, contextlen, context != NULL) != 1) {
|
||||
lua_pushnil(L);
|
||||
/* Could not find whether OpenSSL keeps any details anywhere */
|
||||
lua_pushstring(L, "error exporting keying material");
|
||||
return 2;
|
||||
}
|
||||
|
||||
lua_pushlstring(L, (char *)out, olen);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object information -- tostring metamethod
|
||||
*/
|
||||
@ -876,6 +912,7 @@ static luaL_Reg methods[] = {
|
||||
{"getpeerchain", meth_getpeerchain},
|
||||
{"getpeerverification", meth_getpeerverification},
|
||||
{"getpeerfinished", meth_getpeerfinished},
|
||||
{"exportkeyingmaterial",meth_exportkeyingmaterial},
|
||||
{"getsniname", meth_getsniname},
|
||||
{"getstats", meth_getstats},
|
||||
{"setstats", meth_setstats},
|
||||
|
Loading…
Reference in New Issue
Block a user