60 static int GetCertNotBefore(
lua_State *luastate,
const Flow *f,
int direction)
62 void *state = FlowGetAppState(f);
64 return LuaCallbackError(luastate,
"error: no app layer state");
76 return LuaCallbackError(luastate,
"error: no certificate NotBefore");
83 static int TlsGetCertNotBefore(
lua_State *luastate)
88 return LuaCallbackError(luastate,
"error: protocol not tls");
90 int direction = LuaStateGetDirection(luastate);
92 Flow *f = LuaStateGetFlow(luastate);
94 return LuaCallbackError(luastate,
"internal error: no flow");
96 r = GetCertNotBefore(luastate, f, direction);
101 static int GetCertNotAfter(
lua_State *luastate,
const Flow *f,
int direction)
103 void *state = FlowGetAppState(f);
105 return LuaCallbackError(luastate,
"error: no app layer state");
117 return LuaCallbackError(luastate,
"error: no certificate NotAfter");
124 static int TlsGetCertNotAfter(
lua_State *luastate)
129 return LuaCallbackError(luastate,
"error: protocol not tls");
131 int direction = LuaStateGetDirection(luastate);
133 Flow *f = LuaStateGetFlow(luastate);
135 return LuaCallbackError(luastate,
"internal error: no flow");
137 r = GetCertNotAfter(luastate, f, direction);
142 static int GetCertInfo(
lua_State *luastate,
const Flow *f,
int direction)
144 void *state = FlowGetAppState(f);
146 return LuaCallbackError(luastate,
"error: no app layer state");
158 return LuaCallbackError(luastate,
"error: no cert");
164 int r = LuaPushStringBuffer(luastate, (uint8_t *)ssl_version, strlen(ssl_version));
171 static int TlsGetCertInfo(
lua_State *luastate)
176 return LuaCallbackError(luastate,
"error: protocol not tls");
178 int direction = LuaStateGetDirection(luastate);
180 Flow *f = LuaStateGetFlow(luastate);
182 return LuaCallbackError(luastate,
"internal error: no flow");
184 r = GetCertInfo(luastate, f, direction);
189 static int GetAgreedVersion(
lua_State *luastate,
const Flow *f)
191 void *state = FlowGetAppState(f);
193 return LuaCallbackError(luastate,
"error: no app layer state");
200 return LuaPushStringBuffer(luastate, (uint8_t *)ssl_version,
201 strlen(ssl_version));
204 static int TlsGetVersion(
lua_State *luastate)
209 return LuaCallbackError(luastate,
"error: protocol not tls");
211 Flow *f = LuaStateGetFlow(luastate);
213 return LuaCallbackError(luastate,
"internal error: no flow");
215 r = GetAgreedVersion(luastate, f);
222 void *state = FlowGetAppState(f);
224 return LuaCallbackError(luastate,
"error: no app layer state");
229 return LuaCallbackError(luastate,
"error: no server name indication");
231 return LuaPushStringBuffer(luastate, (uint8_t *)ssl_state->
client_connp.
sni,
235 static int TlsGetSNI(
lua_State *luastate)
240 return LuaCallbackError(luastate,
"error: protocol not tls");
242 Flow *f = LuaStateGetFlow(luastate);
244 return LuaCallbackError(luastate,
"internal error: no flow");
246 r = GetSNI(luastate, f);
253 void *state = FlowGetAppState(f);
255 return LuaCallbackError(luastate,
"error: no app layer state");
260 return LuaCallbackError(luastate,
"error: no certificate serial");
262 return LuaPushStringBuffer(luastate,
267 static int TlsGetCertSerial(
lua_State *luastate)
272 return LuaCallbackError(luastate,
"error: protocol not tls");
274 Flow *f = LuaStateGetFlow(luastate);
276 return LuaCallbackError(luastate,
"internal error: no flow");
278 r = GetCertSerial(luastate, f);
283 static int GetCertChain(
lua_State *luastate,
const Flow *f,
int direction)
285 void *state = FlowGetAppState(f);
287 return LuaCallbackError(luastate,
"error: no app layer state");
299 lua_newtable(luastate);
303 lua_pushinteger(luastate, u++);
305 lua_newtable(luastate);
307 lua_pushstring(luastate,
"length");
308 lua_pushinteger(luastate, cert->
cert_len);
309 lua_settable(luastate, -3);
311 lua_pushstring(luastate,
"data");
314 lua_settable(luastate, -3);
315 lua_settable(luastate, -3);
321 static int TlsGetCertChain(
lua_State *luastate)
326 return LuaCallbackError(luastate,
"error: protocol not tls");
328 int direction = LuaStateGetDirection(luastate);
330 Flow *f = LuaStateGetFlow(luastate);
332 return LuaCallbackError(luastate,
"internal error: no flow");
334 r = GetCertChain(luastate, f, direction);
340 int LuaRegisterTlsFunctions(
lua_State *luastate)
343 lua_pushcfunction(luastate, TlsGetCertNotBefore);
344 lua_setglobal(luastate,
"TlsGetCertNotBefore");
346 lua_pushcfunction(luastate, TlsGetCertNotAfter);
347 lua_setglobal(luastate,
"TlsGetCertNotAfter");
349 lua_pushcfunction(luastate, TlsGetVersion);
350 lua_setglobal(luastate,
"TlsGetVersion");
352 lua_pushcfunction(luastate, TlsGetCertInfo);
353 lua_setglobal(luastate,
"TlsGetCertInfo");
355 lua_pushcfunction(luastate, TlsGetSNI);
356 lua_setglobal(luastate,
"TlsGetSNI");
358 lua_pushcfunction(luastate, TlsGetCertSerial);
359 lua_setglobal(luastate,
"TlsGetCertSerial");
361 lua_pushcfunction(luastate, TlsGetCertChain);
362 lua_setglobal(luastate,
"TlsGetCertChain");