41 #define LOG_TLS_FIELD_VERSION BIT_U64(0)
42 #define LOG_TLS_FIELD_SUBJECT BIT_U64(1)
43 #define LOG_TLS_FIELD_ISSUER BIT_U64(2)
44 #define LOG_TLS_FIELD_SERIAL BIT_U64(3)
45 #define LOG_TLS_FIELD_FINGERPRINT BIT_U64(4)
46 #define LOG_TLS_FIELD_NOTBEFORE BIT_U64(5)
47 #define LOG_TLS_FIELD_NOTAFTER BIT_U64(6)
48 #define LOG_TLS_FIELD_SNI BIT_U64(7)
49 #define LOG_TLS_FIELD_CERTIFICATE BIT_U64(8)
50 #define LOG_TLS_FIELD_CHAIN BIT_U64(9)
51 #define LOG_TLS_FIELD_SESSION_RESUMED BIT_U64(10)
52 #define LOG_TLS_FIELD_JA3 BIT_U64(11)
53 #define LOG_TLS_FIELD_JA3S BIT_U64(12)
54 #define LOG_TLS_FIELD_CLIENT BIT_U64(13)
55 #define LOG_TLS_FIELD_CLIENT_CERT BIT_U64(14)
56 #define LOG_TLS_FIELD_CLIENT_CHAIN BIT_U64(15)
57 #define LOG_TLS_FIELD_JA4 BIT_U64(16)
58 #define LOG_TLS_FIELD_SUBJECTALTNAME BIT_U64(17)
59 #define LOG_TLS_FIELD_CLIENT_ALPNS BIT_U64(18)
60 #define LOG_TLS_FIELD_SERVER_ALPNS BIT_U64(19)
94 #define BASIC_FIELDS \
95 (LOG_TLS_FIELD_SUBJECT | \
96 LOG_TLS_FIELD_ISSUER | \
97 LOG_TLS_FIELD_SUBJECTALTNAME)
101 #define EXTENDED_FIELDS \
103 LOG_TLS_FIELD_VERSION | \
104 LOG_TLS_FIELD_SERIAL | \
105 LOG_TLS_FIELD_FINGERPRINT | \
106 LOG_TLS_FIELD_NOTBEFORE | \
107 LOG_TLS_FIELD_NOTAFTER | \
108 LOG_TLS_FIELD_JA3 | \
109 LOG_TLS_FIELD_JA3S | \
110 LOG_TLS_FIELD_JA4 | \
111 LOG_TLS_FIELD_CLIENT | \
112 LOG_TLS_FIELD_CLIENT_ALPNS | \
113 LOG_TLS_FIELD_SERVER_ALPNS | \
128 static void JsonTlsLogSubject(JsonBuilder *js,
SSLState *ssl_state)
131 jb_set_string(js,
"subject",
136 static void JsonTlsLogIssuer(JsonBuilder *js,
SSLState *ssl_state)
139 jb_set_string(js,
"issuerdn",
144 static void JsonTlsLogSAN(JsonBuilder *js,
SSLState *ssl_state)
147 jb_open_array(js,
"subjectaltname");
155 static void JsonTlsLogSessionResumed(JsonBuilder *js,
SSLState *ssl_state)
164 jb_set_bool(js,
"session_resumed",
true);
169 static void JsonTlsLogFingerprint(JsonBuilder *js,
SSLState *ssl_state)
172 jb_set_string(js,
"fingerprint",
177 static void JsonTlsLogSni(JsonBuilder *js,
SSLState *ssl_state)
180 jb_set_string(js,
"sni",
185 static void JsonTlsLogSerial(JsonBuilder *js,
SSLState *ssl_state)
188 jb_set_string(js,
"serial",
193 static void JsonTlsLogVersion(JsonBuilder *js,
SSLState *ssl_state)
197 jb_set_string(js,
"version", ssl_version);
200 static void JsonTlsLogNotBefore(JsonBuilder *js,
SSLState *ssl_state)
207 static void JsonTlsLogNotAfter(JsonBuilder *js,
SSLState *ssl_state)
214 static void JsonTlsLogJa3Hash(JsonBuilder *js,
SSLState *ssl_state)
217 jb_set_string(js,
"hash",
222 static void JsonTlsLogJa3String(JsonBuilder *js,
SSLState *ssl_state)
226 jb_set_string(js,
"string",
231 static void JsonTlsLogJa3(JsonBuilder *js,
SSLState *ssl_state)
236 jb_open_object(js,
"ja3");
238 JsonTlsLogJa3Hash(js, ssl_state);
239 JsonTlsLogJa3String(js, ssl_state);
245 static void JsonTlsLogSCJA4(JsonBuilder *js,
SSLState *ssl_state)
251 jb_set_string_from_bytes(js,
"ja4", buffer, 36);
255 static void JsonTlsLogJa3SHash(JsonBuilder *js,
SSLState *ssl_state)
258 jb_set_string(js,
"hash",
263 static void JsonTlsLogJa3SString(JsonBuilder *js,
SSLState *ssl_state)
267 jb_set_string(js,
"string",
272 static void JsonTlsLogJa3S(JsonBuilder *js,
SSLState *ssl_state)
277 jb_open_object(js,
"ja3s");
279 JsonTlsLogJa3SHash(js, ssl_state);
280 JsonTlsLogJa3SString(js, ssl_state);
286 static void JsonTlsLogAlpns(JsonBuilder *js,
SSLStateConnp *connp,
const char *
object)
297 jb_open_array(js,
object);
299 jb_append_string_from_bytes(js, a->
alpn, a->
size);
304 static void JsonTlsLogCertificate(JsonBuilder *js,
SSLStateConnp *connp)
318 static void JsonTlsLogChain(JsonBuilder *js,
SSLStateConnp *connp)
324 jb_open_array(js,
"chain");
341 static void JsonTlsLogClientCert(
342 JsonBuilder *js,
SSLStateConnp *connp,
const bool log_cert,
const bool log_chain)
360 jb_set_string(js,
"notbefore", timebuf);
366 jb_set_string(js,
"notafter", timebuf);
370 JsonTlsLogCertificate(js, connp);
373 JsonTlsLogChain(js, connp);
377 static void JsonTlsLogFields(JsonBuilder *js,
SSLState *ssl_state, uint64_t fields)
381 JsonTlsLogSubject(js, ssl_state);
385 JsonTlsLogIssuer(js, ssl_state);
389 JsonTlsLogSAN(js, ssl_state);
393 JsonTlsLogSessionResumed(js, ssl_state);
397 JsonTlsLogSerial(js, ssl_state);
401 JsonTlsLogFingerprint(js, ssl_state);
405 JsonTlsLogSni(js, ssl_state);
409 JsonTlsLogVersion(js, ssl_state);
413 JsonTlsLogNotBefore(js, ssl_state);
417 JsonTlsLogNotAfter(js, ssl_state);
429 JsonTlsLogJa3(js, ssl_state);
433 JsonTlsLogJa3S(js, ssl_state);
437 JsonTlsLogSCJA4(js, ssl_state);
440 JsonTlsLogAlpns(js, &ssl_state->
client_connp,
"client_alpns");
444 JsonTlsLogAlpns(js, &ssl_state->
server_connp,
"server_alpns");
451 jb_open_object(js,
"client");
452 JsonTlsLogClientCert(js, &ssl_state->
client_connp, log_cert, log_chain);
461 jb_open_object(tjs,
"tls");
463 return jb_close(tjs);
467 Flow *f,
void *state,
void *txptr, uint64_t tx_id)
490 jb_open_object(js,
"tls");
492 JsonTlsLogFields(js, ssl_state, tls_ctx->
fields);
497 jb_set_string(js,
"from_proto",
510 static TmEcode JsonTlsLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
517 if (initdata == NULL) {
518 SCLogDebug(
"Error getting context for eve-log tls 'initdata' argument NULL");
580 for ( ; valid_fields->
name != NULL; valid_fields++) {
581 if (strcasecmp(field->
val, valid_fields->
name) == 0) {
595 if (session_resumption == NULL ||
ConfValIsTrue(session_resumption)) {
602 SCLogWarning(
"Both 'certificate' and 'chain' contains the top "
603 "certificate, so only one of them should be enabled "
608 SCLogWarning(
"Both 'client_certificate' and 'client_chain' contains the top "
609 "certificate, so only one of them should be enabled "
615 SCLogConfig(
"enabling \"client\" as a dependency of \"client_certificate\"");
619 SCLogConfig(
"enabling \"client\" as a dependency of \"client_chain\"");
627 static void OutputTlsLogDeinitSub(
OutputCtx *output_ctx)
653 SCLogWarning(
"Both 'certificate' and 'chain' contains the top "
654 "certificate, so only one of them should be enabled "
658 output_ctx->
data = tls_ctx;
659 output_ctx->
DeInit = OutputTlsLogDeinitSub;
663 result.
ctx = output_ctx;
673 JsonTlsLogThreadInit, JsonTlsLogThreadDeinit);