Merge pull request #187 from Zash/exporter

Add key material export method
This commit is contained in:
Bruno Silvestre 2022-07-20 17:32:02 -03:00 committed by GitHub
commit afb2d44b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -671,6 +671,42 @@ static int meth_getpeerfinished(lua_State *L)
return 1; 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 * Object information -- tostring metamethod
*/ */
@ -876,6 +912,7 @@ static luaL_Reg methods[] = {
{"getpeerchain", meth_getpeerchain}, {"getpeerchain", meth_getpeerchain},
{"getpeerverification", meth_getpeerverification}, {"getpeerverification", meth_getpeerverification},
{"getpeerfinished", meth_getpeerfinished}, {"getpeerfinished", meth_getpeerfinished},
{"exportkeyingmaterial",meth_exportkeyingmaterial},
{"getsniname", meth_getsniname}, {"getsniname", meth_getsniname},
{"getstats", meth_getstats}, {"getstats", meth_getstats},
{"setstats", meth_setstats}, {"setstats", meth_setstats},