33static const char ja3_tx[] =
"suricata:ja3:tx";
52 struct LuaTx *ltx = (
struct LuaTx *)lua_newuserdata(L,
sizeof(*ltx));
59 luaL_getmetatable(L, ja3_tx);
60 lua_setmetatable(L, -2);
67 struct LuaTx *ltx = luaL_testudata(L, 1, ja3_tx);
74 if (ssl_state->client_connp.ja3_hash == NULL) {
79 strlen(ssl_state->client_connp.ja3_hash));
81 const uint8_t *buf = NULL;
83 if (!SCQuicTxGetJa3(ltx->
tx, STREAM_TOSERVER, &buf, &b_len)) {
87 uint8_t ja3_hash[SC_MD5_HEX_LEN + 1];
89 SCMd5HashBufferToHex(buf, b_len, (
char *)ja3_hash, SC_MD5_HEX_LEN + 1);
95 struct LuaTx *ltx = luaL_testudata(L, 1, ja3_tx);
102 if (ssl_state->client_connp.ja3_str == NULL ||
103 ssl_state->client_connp.ja3_str->data == NULL) {
108 ssl_state->client_connp.ja3_str->used);
110 const uint8_t *buf = NULL;
112 if (!SCQuicTxGetJa3(ltx->
tx, STREAM_TOSERVER, &buf, &b_len)) {
119static int LuaJa3TxGetServerHash(
lua_State *L)
121 struct LuaTx *ltx = luaL_testudata(L, 1, ja3_tx);
128 if (ssl_state->server_connp.ja3_hash == NULL) {
133 strlen(ssl_state->server_connp.ja3_hash));
135 const uint8_t *buf = NULL;
137 if (!SCQuicTxGetJa3(ltx->
tx, STREAM_TOCLIENT, &buf, &b_len)) {
141 uint8_t ja3_hash[SC_MD5_HEX_LEN + 1];
143 SCMd5HashBufferToHex(buf, b_len, (
char *)ja3_hash, SC_MD5_HEX_LEN + 1);
147static int LuaJa3TxGetServerString(
lua_State *L)
149 struct LuaTx *ltx = luaL_testudata(L, 1, ja3_tx);
156 if (ssl_state->server_connp.ja3_str == NULL ||
157 ssl_state->server_connp.ja3_str->data == NULL) {
162 ssl_state->server_connp.ja3_str->used);
164 const uint8_t *buf = NULL;
166 if (!SCQuicTxGetJa3(ltx->
tx, STREAM_TOCLIENT, &buf, &b_len)) {
173static const struct luaL_Reg txlib[] = {
175 {
"ja3_get_hash", LuaJa3TxGetHash },
176 {
"ja3_get_string", LuaJa3TxGetString },
177 {
"ja3s_get_hash", LuaJa3TxGetServerHash },
178 {
"ja3s_get_string", LuaJa3TxGetServerString },
189static const struct luaL_Reg ja3lib[] = {
191 {
"get_tx", LuaJa3GetTx },
192 {
"enable_ja3", LuaJa3Enable },
199 luaL_newmetatable(L, ja3_tx);
200 lua_pushvalue(L, -1);
201 lua_setfield(L, -2,
"__index");
202 luaL_setfuncs(L, txlib, 0);
204 luaL_newlib(L, ja3lib);
void SSLEnableJA3(void)
if not explicitly disabled in config, enable ja3 support
SSLv[2.0|3.[0|1|2|3]] state structure.
struct lua_State lua_State
int LuaStateNeedProto(lua_State *luastate, AppProto alproto)
int LuaCallbackError(lua_State *luastate, const char *msg)
int SCLuaLoadJa3Lib(lua_State *L)
int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
void * LuaStateGetTX(lua_State *luastate)
get tx pointer from the lua state