From c1970a3655360ef603288d50451a6547becdaf3a Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Fri, 6 Mar 2015 21:05:51 +0100 Subject: [PATCH] json-ssh: export logging function It will be use in alert logging to display SSH information. --- src/output-json-ssh.c | 45 +++++++++++++++++++++++++------------------ src/output-json-ssh.h | 6 ++++++ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/output-json-ssh.c b/src/output-json-ssh.c index 0a6ea46230..d8494d5e35 100644 --- a/src/output-json-ssh.c +++ b/src/output-json-ssh.c @@ -65,6 +65,31 @@ typedef struct JsonSshLogThread_ { MemBuffer *buffer; } JsonSshLogThread; + +void JsonSshLogJSON(json_t *tjs, SshState *ssh_state) +{ + json_t *cjs = json_object(); + if (cjs != NULL) { + json_object_set_new(cjs, "proto_version", + json_string((char *)ssh_state->cli_hdr.proto_version)); + + json_object_set_new(cjs, "software_version", + json_string((char *)ssh_state->cli_hdr.software_version)); + } + json_object_set_new(tjs, "client", cjs); + + json_t *sjs = json_object(); + if (sjs != NULL) { + json_object_set_new(sjs, "proto_version", + json_string((char *)ssh_state->srv_hdr.proto_version)); + + json_object_set_new(sjs, "software_version", + json_string((char *)ssh_state->srv_hdr.software_version)); + } + json_object_set_new(tjs, "server", sjs); + +} + static int JsonSshLogger(ThreadVars *tv, void *thread_data, const Packet *p) { JsonSshLogThread *aft = (JsonSshLogThread *)thread_data; @@ -102,25 +127,7 @@ static int JsonSshLogger(ThreadVars *tv, void *thread_data, const Packet *p) /* reset */ MemBufferReset(buffer); - json_t *cjs = json_object(); - if (cjs != NULL) { - json_object_set_new(cjs, "proto_version", - json_string((char *)ssh_state->cli_hdr.proto_version)); - - json_object_set_new(cjs, "software_version", - json_string((char *)ssh_state->cli_hdr.software_version)); - } - json_object_set_new(tjs, "client", cjs); - - json_t *sjs = json_object(); - if (sjs != NULL) { - json_object_set_new(sjs, "proto_version", - json_string((char *)ssh_state->srv_hdr.proto_version)); - - json_object_set_new(sjs, "software_version", - json_string((char *)ssh_state->srv_hdr.software_version)); - } - json_object_set_new(tjs, "server", sjs); + JsonSshLogJSON(tjs, ssh_state); json_object_set_new(js, "ssh", tjs); diff --git a/src/output-json-ssh.h b/src/output-json-ssh.h index af0711c711..5d0752bf2a 100644 --- a/src/output-json-ssh.h +++ b/src/output-json-ssh.h @@ -26,4 +26,10 @@ void TmModuleJsonSshLogRegister (void); +#ifdef HAVE_LIBJANSSON +#include "app-layer-ssh.h" + +void JsonSshLogJSON(json_t *js, SshState *tx); +#endif + #endif /* __OUTPUT_JSON_SSH_H__ */