Go to the documentation of this file.
47 #define DEFAULT_LOG_FILENAME "tls.log"
49 #define MODULE_NAME "LogTlsLog"
51 #define PRINT_BUF_LEN 46
53 #define OUTPUT_BUFFER_SIZE 65535
55 #define LOG_TLS_DEFAULT 0
56 #define LOG_TLS_EXTENDED 1
57 #define LOG_TLS_CUSTOM 2
59 #define LOG_TLS_SESSION_RESUMPTION 4
61 #define LOG_TLS_CF_VERSION 'v'
62 #define LOG_TLS_CF_DATE_NOT_BEFORE 'd'
63 #define LOG_TLS_CF_DATE_NOT_AFTER 'D'
64 #define LOG_TLS_CF_SHA1 'f'
65 #define LOG_TLS_CF_SNI 'n'
66 #define LOG_TLS_CF_SUBJECT 's'
67 #define LOG_TLS_CF_ISSUER 'i'
68 #define LOG_TLS_CF_EXTENDED 'E'
82 socklen_t dstip_len,
Port *dp,
int ipproto)
133 if (initdata == NULL) {
134 SCLogDebug(
"Error getting context for TLSLog. \"initdata\" argument NULL");
140 if (aft->
buffer == NULL) {
166 static void LogTlsLogDeInitCtx(
OutputCtx *output_ctx)
181 SCLogWarning(
"The tls-log output has been deprecated and will be removed in Suricata 9.0.");
186 if (file_ctx == NULL) {
188 "create new file_ctx");
207 if (custom != NULL && customformat != NULL &&
ConfValIsTrue(custom)) {
209 if (!tlslog_ctx->
cf) {
219 if (extended == NULL) {
229 "session-resumption");
238 output_ctx->
data = tlslog_ctx;
239 output_ctx->
DeInit = LogTlsLogDeInitCtx;
246 result.
ctx = output_ctx;
268 static void LogTlsLogDate(
MemBuffer *buffer,
const char *title, int64_t *date)
270 char timebuf[64] = {0};
271 if (sc_x509_format_timestamp(*date, timebuf,
sizeof(timebuf))) {
276 static void LogTlsLogString(
MemBuffer *buffer,
const char *title,
283 char *srcip,
Port sp,
char *dstip,
Port dp)
288 "%s %s:%d -> %s:%d TLS:",
289 timebuf, srcip, sp, dstip, dp);
314 char *srcip,
Port sp,
char *dstip,
Port dp)
318 LogTlsLogString(aft->
buffer,
"SHA1",
327 LogTlsLogString(aft->
buffer,
"SERIAL",
336 LogTlsLogDate(aft->
buffer,
"NOTBEFORE",
341 LogTlsLogDate(aft->
buffer,
"NOTAFTER",
348 char *srcip,
Port sp,
char *dstip,
Port dp)
354 for (i = 0; i < tlslog_ctx->
cf->
cf_n; i++)
360 switch (node->
type) {
371 snprintf(buf,
sizeof(buf),
"%06u", (
unsigned int)
SCTIME_USECS(
ts));
373 (uint8_t *)buf,
MIN(strlen(buf), 6));
379 (uint8_t *)srcip,strlen(srcip));
385 (uint8_t *)dstip, strlen(dstip));
399 LogTlsLogDate(aft->
buffer,
"NOTBEFORE",
403 LogTlsLogDate(aft->
buffer,
"NOTAFTER",
440 LogTlsLogExtended(aft, ssl_state,
ts, srcip, sp, dstip, dp);
445 SCLogDebug(
"No matching parameter %%%c for custom tls log.",
454 Flow *f,
void *state,
void *tx, uint64_t tx_id)
458 int ipproto = (PacketIsIPv4(p)) ? AF_INET : AF_INET6;
481 MemBufferReset(aft->
buffer);
484 LogTlsLogCustom(aft, ssl_state, p->
ts, srcip, sp, dstip, dp);
486 LogTlsLogBasic(aft, ssl_state, p->
ts, srcip, sp, dstip, dp);
487 LogTlsLogExtended(aft, ssl_state, p->
ts, srcip, sp, dstip, dp);
489 LogTlsLogBasic(aft, ssl_state, p->
ts, srcip, sp, dstip, dp);
504 LogTlsLogThreadDeinit);
void LogCustomFormatFree(LogCustomFormat *cf)
Frees memory held by a custom format.
SSLv[2.0|3.[0|1|2|3]] state structure.
#define LOG_TLS_SESSION_RESUMPTION
SSLStateConnp client_connp
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
#define OUTPUT_BUFFER_SIZE
#define DEFAULT_LOG_FILENAME
SSLStateConnp server_connp
#define SSL_AL_FLAG_SESSION_RESUMED
void LogTlsLogRegister(void)
#define SSL_AL_FLAG_STATE_SERVER_HELLO
#define SSL_VERSION_MAX_STRLEN
int(* Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp)
void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts)
Writes a timestamp with given format into a MemBuffer.
#define LOG_CF_CLIENT_PORT
#define GET_IPV6_DST_ADDR(p)
int ConfValIsTrue(const char *val)
Check if a value is true.
int SCConfLogOpenGeneric(ConfNode *conf, LogFileCtx *log_ctx, const char *default_filename, int rotate)
open a generic output "log file", which may be a regular file or a socket
#define LOG_TLS_CF_DATE_NOT_AFTER
#define LOG_TLS_CF_SUBJECT
#define GET_IPV4_DST_ADDR_PTR(p)
#define PKT_IS_TOSERVER(p)
void OutputRegisterTxModuleWithProgress(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, int tc_log_progress, int ts_log_progress, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a tx output module with progress.
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
struct LogTlsLogThread_ LogTlsLogThread
Per thread variable structure.
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
#define LOG_CF_SERVER_PORT
void SSLVersionToString(uint16_t version, char *buffer)
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define LOG_CF_TIMESTAMP_U
#define LOG_CF_WRITE_UNKNOWN_VALUE(buffer)
void PrintRawUriBuf(char *retbuf, uint32_t *offset, uint32_t retbuflen, uint8_t *buf, size_t buflen)
#define LOG_TLS_CF_VERSION
int TLSGetIPInformations(const Packet *p, char *srcip, socklen_t srcip_len, Port *sp, char *dstip, socklen_t dstip_len, Port *dp, int ipproto)
#define GET_IPV4_SRC_ADDR_PTR(p)
struct LogTlsFileCtx_ LogTlsFileCtx
void(* DeInit)(struct OutputCtx_ *)
void MemBufferFree(MemBuffer *buffer)
int LogFileFreeCtx(LogFileCtx *lf_ctx)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
LogTlsFileCtx * tlslog_ctx
#define SCLogError(...)
Macro used to log ERROR messages.
#define GET_IPV6_SRC_ADDR(p)
#define LOG_TLS_CF_DATE_NOT_BEFORE
#define LOG_TLS_CF_ISSUER
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
#define MEMBUFFER_BUFFER(mem_buffer)
Get the MemBuffers underlying buffer.
LogCustomFormat * LogCustomFormatAlloc(void)
Creates a custom format.
#define MEMBUFFER_OFFSET(mem_buffer)
Get the MemBuffers current offset.
#define LOG_CF_WRITE_SPACE_SEPARATOR(buffer)
#define SSL_AL_FLAG_LOG_WITHOUT_CERT
void CreateTimeString(const SCTime_t ts, char *str, size_t size)
MemBuffer * MemBufferCreateNew(uint32_t size)
#define LOG_TLS_CF_EXTENDED
int LogCustomFormatParse(LogCustomFormat *cf, const char *format)
Parses and saves format nodes for custom format.
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.