suricata
detect-tls-cert-validity.c
Go to the documentation of this file.
1 /* Copyright (C) 2015-2020 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Mats Klepsland <mats.klepsland@gmail.com>
22  *
23  * Implements tls certificate validity keywords
24  */
25 
26 #include "suricata-common.h"
27 #include "threads.h"
28 #include "decode.h"
29 #include "detect.h"
30 
31 #include "detect-parse.h"
32 #include "detect-engine.h"
33 #include "detect-engine-mpm.h"
34 #include "detect-content.h"
35 #include "detect-pcre.h"
37 
38 #include "flow.h"
39 #include "flow-util.h"
40 #include "flow-var.h"
41 
42 #include "stream-tcp.h"
43 
44 #include "app-layer.h"
45 #include "app-layer-ssl.h"
46 
47 #include "util-time.h"
48 #include "util-unittest.h"
49 #include "util-unittest-helper.h"
50 
51 /**
52  * [tls_notbefore|tls_notafter]:[<|>]<date string>[<><date string>];
53  */
54 #define PARSE_REGEX "^\\s*(<|>)?\\s*([ -:TW0-9]+)\\s*(?:(<>)\\s*([ -:TW0-9]+))?\\s*$"
55 static DetectParseRegex parse_regex;
56 
57 static int DetectTlsValidityMatch (DetectEngineThreadCtx *, Flow *,
58  uint8_t, void *, void *, const Signature *,
59  const SigMatchCtx *);
60 
61 static time_t DateStringToEpoch (char *);
62 static DetectTlsValidityData *DetectTlsValidityParse (const char *);
63 static int DetectTlsExpiredSetup (DetectEngineCtx *, Signature *s, const char *str);
64 static int DetectTlsValidSetup (DetectEngineCtx *, Signature *s, const char *str);
65 static int DetectTlsNotBeforeSetup (DetectEngineCtx *, Signature *s, const char *str);
66 static int DetectTlsNotAfterSetup (DetectEngineCtx *, Signature *s, const char *str);
67 static int DetectTlsValiditySetup (DetectEngineCtx *, Signature *s, const char *str, uint8_t);
68 #ifdef UNITTESTS
69 static void TlsNotBeforeRegisterTests(void);
70 static void TlsNotAfterRegisterTests(void);
71 static void TlsExpiredRegisterTests(void);
72 static void TlsValidRegisterTests(void);
73 #endif /* UNITTESTS */
74 static void DetectTlsValidityFree(DetectEngineCtx *, void *);
75 static int g_tls_validity_buffer_id = 0;
76 
77 /**
78  * \brief Registration function for tls validity keywords.
79  */
81 {
82  sigmatch_table[DETECT_AL_TLS_NOTBEFORE].name = "tls_cert_notbefore";
83  sigmatch_table[DETECT_AL_TLS_NOTBEFORE].desc = "match TLS certificate notBefore field";
84  sigmatch_table[DETECT_AL_TLS_NOTBEFORE].url = "/rules/tls-keywords.html#tls-cert-notbefore";
85  sigmatch_table[DETECT_AL_TLS_NOTBEFORE].AppLayerTxMatch = DetectTlsValidityMatch;
86  sigmatch_table[DETECT_AL_TLS_NOTBEFORE].Setup = DetectTlsNotBeforeSetup;
87  sigmatch_table[DETECT_AL_TLS_NOTBEFORE].Free = DetectTlsValidityFree;
88 #ifdef UNITTESTS
90 #endif
91 
92  sigmatch_table[DETECT_AL_TLS_NOTAFTER].name = "tls_cert_notafter";
93  sigmatch_table[DETECT_AL_TLS_NOTAFTER].desc = "match TLS certificate notAfter field";
94  sigmatch_table[DETECT_AL_TLS_NOTAFTER].url = "/rules/tls-keywords.html#tls-cert-notafter";
95  sigmatch_table[DETECT_AL_TLS_NOTAFTER].AppLayerTxMatch = DetectTlsValidityMatch;
96  sigmatch_table[DETECT_AL_TLS_NOTAFTER].Setup = DetectTlsNotAfterSetup;
97  sigmatch_table[DETECT_AL_TLS_NOTAFTER].Free = DetectTlsValidityFree;
98 #ifdef UNITTESTS
100 #endif
101 
102  sigmatch_table[DETECT_AL_TLS_EXPIRED].name = "tls_cert_expired";
103  sigmatch_table[DETECT_AL_TLS_EXPIRED].desc = "match expired TLS certificates";
104  sigmatch_table[DETECT_AL_TLS_EXPIRED].url = "/rules/tls-keywords.html#tls-cert-expired";
105  sigmatch_table[DETECT_AL_TLS_EXPIRED].AppLayerTxMatch = DetectTlsValidityMatch;
106  sigmatch_table[DETECT_AL_TLS_EXPIRED].Setup = DetectTlsExpiredSetup;
107  sigmatch_table[DETECT_AL_TLS_EXPIRED].Free = DetectTlsValidityFree;
109 #ifdef UNITTESTS
111 #endif
112 
113  sigmatch_table[DETECT_AL_TLS_VALID].name = "tls_cert_valid";
114  sigmatch_table[DETECT_AL_TLS_VALID].desc = "match valid TLS certificates";
115  sigmatch_table[DETECT_AL_TLS_VALID].url = "/rules/tls-keywords.html#tls-cert-valid";
116  sigmatch_table[DETECT_AL_TLS_VALID].AppLayerTxMatch = DetectTlsValidityMatch;
117  sigmatch_table[DETECT_AL_TLS_VALID].Setup = DetectTlsValidSetup;
118  sigmatch_table[DETECT_AL_TLS_VALID].Free = DetectTlsValidityFree;
120 #ifdef UNITTESTS
122 #endif
123 
124  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
125 
128 
129  g_tls_validity_buffer_id = DetectBufferTypeGetByName("tls_validity");
130 }
131 
132 /**
133  * \internal
134  * \brief Function to match validity field in a tls certificate.
135  *
136  * \param t Pointer to thread vars.
137  * \param det_ctx Pointer to the pattern matcher thread.
138  * \param f Pointer to the current flow.
139  * \param flags Flags.
140  * \param state App layer state.
141  * \param s Pointer to the Signature.
142  * \param m Pointer to the sigmatch that we will cast into
143  * DetectTlsValidityData.
144  *
145  * \retval 0 no match.
146  * \retval 1 match.
147  */
148 static int DetectTlsValidityMatch (DetectEngineThreadCtx *det_ctx,
149  Flow *f, uint8_t flags, void *state,
150  void *txv, const Signature *s,
151  const SigMatchCtx *ctx)
152 {
153  SCEnter();
154 
155  SSLState *ssl_state = (SSLState *)state;
156  if (ssl_state == NULL) {
157  SCLogDebug("no tls state, no match");
158  SCReturnInt(0);
159  }
160 
161  int ret = 0;
162 
163  SSLStateConnp *connp = NULL;
164  if (flags & STREAM_TOSERVER)
165  connp = &ssl_state->client_connp;
166  else
167  connp = &ssl_state->server_connp;
168 
169  const DetectTlsValidityData *dd = (const DetectTlsValidityData *)ctx;
170 
171  time_t cert_epoch = 0;
172  if (dd->type == DETECT_TLS_TYPE_NOTBEFORE)
173  cert_epoch = connp->cert0_not_before;
174  else if (dd->type == DETECT_TLS_TYPE_NOTAFTER)
175  cert_epoch = connp->cert0_not_after;
176 
177  if (cert_epoch == 0)
178  SCReturnInt(0);
179 
180  if ((dd->mode & DETECT_TLS_VALIDITY_EQ) && cert_epoch == dd->epoch)
181  ret = 1;
182  else if ((dd->mode & DETECT_TLS_VALIDITY_LT) && cert_epoch <= dd->epoch)
183  ret = 1;
184  else if ((dd->mode & DETECT_TLS_VALIDITY_GT) && cert_epoch >= dd->epoch)
185  ret = 1;
186  else if ((dd->mode & DETECT_TLS_VALIDITY_RA) &&
187  cert_epoch >= dd->epoch && cert_epoch <= dd->epoch2)
188  ret = 1;
189  else if ((dd->mode & DETECT_TLS_VALIDITY_EX) &&
190  f->lastts.tv_sec > cert_epoch)
191  ret = 1;
192  else if ((dd->mode & DETECT_TLS_VALIDITY_VA) &&
193  f->lastts.tv_sec <= cert_epoch)
194  ret = 1;
195 
196  SCReturnInt(ret);
197 }
198 
199 /**
200  * \internal
201  * \brief Function to check if string is epoch.
202  *
203  * \param string Date string.
204  *
205  * \retval epoch time on success.
206  * \retval 0 on failure.
207  */
208 static time_t StringIsEpoch (char *string)
209 {
210  if (strlen(string) == 0)
211  return -1;
212 
213  /* We assume that the date string is epoch if it consists of only
214  digits. */
215  char *sp = string;
216  while (*sp) {
217  if (isdigit(*sp++) == 0)
218  return -1;
219  }
220 
221  return strtol(string, NULL, 10);
222 }
223 
224 /**
225  * \internal
226  * \brief Function to convert date string to epoch.
227  *
228  * \param string Date string.
229  *
230  * \retval epoch on success.
231  * \retval 0 on failure.
232  */
233 static time_t DateStringToEpoch (char *string)
234 {
235  int r = 0;
236  struct tm tm;
237  const char *patterns[] = {
238  /* ISO 8601 */
239  "%Y-%m",
240  "%Y-%m-%d",
241  "%Y-%m-%d %H",
242  "%Y-%m-%d %H:%M",
243  "%Y-%m-%d %H:%M:%S",
244  "%Y-%m-%dT%H",
245  "%Y-%m-%dT%H:%M",
246  "%Y-%m-%dT%H:%M:%S",
247  "%H:%M",
248  "%H:%M:%S",
249  };
250 
251  /* Skip leading whitespace. */
252  while (isspace(*string))
253  string++;
254 
255  size_t inlen, oldlen;
256 
257  oldlen = inlen = strlen(string);
258 
259  /* Skip trailing whitespace */
260  while (inlen > 0 && isspace(string[inlen - 1]))
261  inlen--;
262 
263  char tmp[inlen + 1];
264 
265  if (inlen < oldlen) {
266  strlcpy(tmp, string, inlen + 1);
267  string = tmp;
268  }
269 
270  time_t epoch = StringIsEpoch(string);
271  if (epoch != -1) {
272  return epoch;;
273  }
274 
275  r = SCStringPatternToTime(string, patterns, 10, &tm);
276 
277  if (r != 0)
278  return -1;
279 
280  return SCMkTimeUtc(&tm);
281 }
282 
283 /**
284  * \internal
285  * \brief Function to parse options passed via tls validity keywords.
286  *
287  * \param rawstr Pointer to the user provided options.
288  *
289  * \retval dd pointer to DetectTlsValidityData on success.
290  * \retval NULL on failure.
291  */
292 static DetectTlsValidityData *DetectTlsValidityParse (const char *rawstr)
293 {
294  DetectTlsValidityData *dd = NULL;
295  int ret = 0, res = 0;
296  size_t pcre2len;
297  char mode[2] = "";
298  char value1[20] = "";
299  char value2[20] = "";
300  char range[3] = "";
301 
302  ret = DetectParsePcreExec(&parse_regex, rawstr, 0, 0);
303  if (ret < 3 || ret > 5) {
304  SCLogError(SC_ERR_PCRE_MATCH, "Parse error %s", rawstr);
305  goto error;
306  }
307 
308  pcre2len = sizeof(mode);
309  res = SC_Pcre2SubstringCopy(parse_regex.match, 1, (PCRE2_UCHAR8 *)mode, &pcre2len);
310  if (res < 0) {
311  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
312  goto error;
313  }
314  SCLogDebug("mode \"%s\"", mode);
315 
316  pcre2len = sizeof(value1);
317  res = pcre2_substring_copy_bynumber(parse_regex.match, 2, (PCRE2_UCHAR8 *)value1, &pcre2len);
318  if (res < 0) {
319  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
320  goto error;
321  }
322  SCLogDebug("value1 \"%s\"", value1);
323 
324  if (ret > 3) {
325  pcre2len = sizeof(range);
326  res = pcre2_substring_copy_bynumber(parse_regex.match, 3, (PCRE2_UCHAR8 *)range, &pcre2len);
327  if (res < 0) {
328  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
329  goto error;
330  }
331  SCLogDebug("range \"%s\"", range);
332 
333  if (ret > 4) {
334  pcre2len = sizeof(value2);
335  res = pcre2_substring_copy_bynumber(
336  parse_regex.match, 4, (PCRE2_UCHAR8 *)value2, &pcre2len);
337  if (res < 0) {
338  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
339  goto error;
340  }
341  SCLogDebug("value2 \"%s\"", value2);
342  }
343  }
344 
345  dd = SCMalloc(sizeof(DetectTlsValidityData));
346  if (unlikely(dd == NULL))
347  goto error;
348 
349  dd->epoch = 0;
350  dd->epoch2 = 0;
351  dd->mode = 0;
352 
353  if (strlen(mode) > 0) {
354  if (mode[0] == '<')
356  else if (mode[0] == '>')
358  }
359 
360  if (strlen(range) > 0) {
361  if (strcmp("<>", range) == 0)
363  }
364 
365  if (strlen(range) != 0 && strlen(mode) != 0) {
367  "Range specified but mode also set");
368  goto error;
369  }
370 
371  if (dd->mode == 0) {
373  }
374 
375  /* set the first value */
376  dd->epoch = DateStringToEpoch(value1);
377  if (dd->epoch == -1)
378  goto error;
379 
380  /* set the second value if specified */
381  if (strlen(value2) > 0) {
382  if (!(dd->mode & DETECT_TLS_VALIDITY_RA)) {
384  "Multiple tls validity values specified but mode is not range");
385  goto error;
386  }
387 
388  dd->epoch2 = DateStringToEpoch(value2);
389  if (dd->epoch2 == -1)
390  goto error;
391 
392  if (dd->epoch2 <= dd->epoch) {
394  "Second value in range must not be smaller than the first");
395  goto error;
396  }
397  }
398  return dd;
399 
400 error:
401  if (dd)
402  SCFree(dd);
403  return NULL;
404 }
405 
406 /**
407  * \brief Function to add the parsed tls_cert_expired into the current signature.
408  *
409  * \param de_ctx Pointer to the Detection Engine Context.
410  * \param s Pointer to the Current Signature.
411  * \param rawstr Pointer to the user provided flags options.
412  *
413  * \retval 0 on Success.
414  * \retval -1 on Failure.
415  */
416 static int DetectTlsExpiredSetup (DetectEngineCtx *de_ctx, Signature *s,
417  const char *rawstr)
418 {
419  DetectTlsValidityData *dd = NULL;
420  SigMatch *sm = NULL;
421 
422  SCLogDebug("\'%s\'", rawstr);
423 
425  return -1;
426 
427  dd = SCCalloc(1, sizeof(DetectTlsValidityData));
428  if (dd == NULL) {
429  SCLogError(SC_ERR_INVALID_ARGUMENT,"Allocation \'%s\' failed", rawstr);
430  goto error;
431  }
432 
433  /* okay so far so good, lets get this into a SigMatch
434  * and put it in the Signature. */
435  sm = SigMatchAlloc();
436  if (sm == NULL)
437  goto error;
438 
441  dd->epoch = 0;
442  dd->epoch2 = 0;
443 
445  sm->ctx = (void *)dd;
446 
447  SigMatchAppendSMToList(s, sm, g_tls_validity_buffer_id);
448  return 0;
449 
450 error:
451  DetectTlsValidityFree(de_ctx, dd);
452  if (sm)
453  SCFree(sm);
454  return -1;
455 }
456 
457 /**
458  * \brief Function to add the parsed tls_cert_valid into the current signature.
459  *
460  * \param de_ctx Pointer to the Detection Engine Context.
461  * \param s Pointer to the Current Signature.
462  * \param rawstr Pointer to the user provided flags options.
463  *
464  * \retval 0 on Success.
465  * \retval -1 on Failure.
466  */
467 static int DetectTlsValidSetup (DetectEngineCtx *de_ctx, Signature *s,
468  const char *rawstr)
469 {
470  DetectTlsValidityData *dd = NULL;
471  SigMatch *sm = NULL;
472 
473  SCLogDebug("\'%s\'", rawstr);
474 
476  return -1;
477 
478  dd = SCCalloc(1, sizeof(DetectTlsValidityData));
479  if (dd == NULL) {
480  SCLogError(SC_ERR_INVALID_ARGUMENT,"Allocation \'%s\' failed", rawstr);
481  goto error;
482  }
483 
484  /* okay so far so good, lets get this into a SigMatch
485  * and put it in the Signature. */
486  sm = SigMatchAlloc();
487  if (sm == NULL)
488  goto error;
489 
492  dd->epoch = 0;
493  dd->epoch2 = 0;
494 
496  sm->ctx = (void *)dd;
497 
498  SigMatchAppendSMToList(s, sm, g_tls_validity_buffer_id);
499  return 0;
500 
501 error:
502  DetectTlsValidityFree(de_ctx, dd);
503  if (sm)
504  SCFree(sm);
505  return -1;
506 }
507 
508 /**
509  * \brief Function to add the parsed tls_notbefore into the current signature.
510  *
511  * \param de_ctx Pointer to the Detection Engine Context.
512  * \param s Pointer to the Current Signature.
513  * \param rawstr Pointer to the user provided flags options.
514  *
515  * \retval 0 on Success.
516  * \retval -1 on Failure.
517  */
518 static int DetectTlsNotBeforeSetup (DetectEngineCtx *de_ctx, Signature *s,
519  const char *rawstr)
520 {
522  int r = DetectTlsValiditySetup(de_ctx, s, rawstr, type);
523 
524  SCReturnInt(r);
525 }
526 
527 /**
528  * \brief Function to add the parsed tls_notafter into the current signature.
529  *
530  * \param de_ctx Pointer to the Detection Engine Context.
531  * \param s Pointer to the Current Signature.
532  * \param rawstr Pointer to the user provided flags options.
533  *
534  * \retval 0 on Success.
535  * \retval -1 on Failure.
536  */
537 static int DetectTlsNotAfterSetup (DetectEngineCtx *de_ctx, Signature *s,
538  const char *rawstr)
539 {
540  uint8_t type = DETECT_TLS_TYPE_NOTAFTER;
541  int r = DetectTlsValiditySetup(de_ctx, s, rawstr, type);
542 
543  SCReturnInt(r);
544 }
545 
546 /**
547  * \brief Function to add the parsed tls validity field into the current signature.
548  *
549  * \param de_ctx Pointer to the Detection Engine Context.
550  * \param s Pointer to the Current Signature.
551  * \param rawstr Pointer to the user provided flags options.
552  * \param type Defines if this is notBefore or notAfter.
553  *
554  * \retval 0 on Success.
555  * \retval -1 on Failure.
556  */
557 static int DetectTlsValiditySetup (DetectEngineCtx *de_ctx, Signature *s,
558  const char *rawstr, uint8_t type)
559 {
560  DetectTlsValidityData *dd = NULL;
561  SigMatch *sm = NULL;
562 
563  SCLogDebug("\'%s\'", rawstr);
564 
566  return -1;
567 
568  dd = DetectTlsValidityParse(rawstr);
569  if (dd == NULL) {
570  SCLogError(SC_ERR_INVALID_ARGUMENT,"Parsing \'%s\' failed", rawstr);
571  goto error;
572  }
573 
574  /* okay so far so good, lets get this into a SigMatch
575  * and put it in the Signature. */
576  sm = SigMatchAlloc();
577  if (sm == NULL)
578  goto error;
579 
583  }
584  else if (type == DETECT_TLS_TYPE_NOTAFTER) {
587  }
588  else {
589  goto error;
590  }
591 
592  sm->ctx = (void *)dd;
593 
594  SigMatchAppendSMToList(s, sm, g_tls_validity_buffer_id);
595  return 0;
596 
597 error:
598  DetectTlsValidityFree(de_ctx, dd);
599  if (sm)
600  SCFree(sm);
601  return -1;
602 }
603 
604 /**
605  * \internal
606  * \brief Function to free memory associated with DetectTlsValidityData.
607  *
608  * \param de_ptr Pointer to DetectTlsValidityData.
609  */
610 void DetectTlsValidityFree(DetectEngineCtx *de_ctx, void *de_ptr)
611 {
613  if (dd)
614  SCFree(dd);
615 }
616 
617 #ifdef UNITTESTS
619 #endif
DETECT_AL_TLS_EXPIRED
@ DETECT_AL_TLS_EXPIRED
Definition: detect-engine-register.h:119
SSLStateConnp_::cert0_not_before
time_t cert0_not_before
Definition: app-layer-ssl.h:255
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:47
SigTableElmt_::url
const char * url
Definition: detect.h:1238
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1493
SSLState_
SSLv[2.0|3.[0|1|2|3]] state structure.
Definition: app-layer-ssl.h:288
detect-content.h
DetectTlsValidityData_::type
uint8_t type
Definition: detect-tls-cert-validity.h:45
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1237
DETECT_TLS_TYPE_NOTAFTER
#define DETECT_TLS_TYPE_NOTAFTER
Definition: detect-tls-cert-validity.h:39
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2488
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1225
flow-util.h
DetectParseRegex
Definition: detect-parse.h:44
SigTableElmt_::name
const char * name
Definition: detect.h:1235
stream-tcp.h
detect-tls-cert-validity.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SSLState_::client_connp
SSLStateConnp client_connp
Definition: app-layer-ssl.h:306
ALPROTO_TLS
@ ALPROTO_TLS
Definition: app-layer-protos.h:33
DETECT_TLS_VALIDITY_EQ
#define DETECT_TLS_VALIDITY_EQ
Definition: detect-tls-cert-validity.h:27
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:296
TlsNotBeforeRegisterTests
void TlsNotBeforeRegisterTests(void)
Register unit tests for tls_cert_notbefore.
Definition: detect-tls-cert-validity.c:1334
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-tls-cert-validity.c:54
SSLState_::server_connp
SSLStateConnp server_connp
Definition: app-layer-ssl.h:307
SSLStateConnp_
Definition: app-layer-ssl.h:231
TlsNotAfterRegisterTests
void TlsNotAfterRegisterTests(void)
Register unit tests for tls_cert_notafter.
Definition: detect-tls-cert-validity.c:1354
threads.h
Flow_
Flow data structure.
Definition: flow.h:356
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1229
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:784
SCMkTimeUtc
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
Definition: util-time.c:451
DETECT_TLS_VALIDITY_RA
#define DETECT_TLS_VALIDITY_RA
Definition: detect-tls-cert-validity.h:30
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1206
DetectTlsValidityRegister
void DetectTlsValidityRegister(void)
Registration function for tls validity keywords.
Definition: detect-tls-cert-validity.c:80
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
TLS_STATE_CERT_READY
@ TLS_STATE_CERT_READY
Definition: app-layer-ssl.h:78
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:229
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1220
detect-pcre.h
util-unittest.h
util-unittest-helper.h
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1086
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
SSLStateConnp_::cert0_not_after
time_t cert0_not_after
Definition: app-layer-ssl.h:256
decode.h
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
type
uint8_t type
Definition: decode-icmpv4.h:0
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1024
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2611
SCEnter
#define SCEnter(...)
Definition: util-debug.h:298
detect-engine-mpm.h
detect.h
DetectTlsValidityData_
Definition: detect-tls-cert-validity.h:41
util-time.h
DetectTlsValidityData_::mode
uint8_t mode
Definition: detect-tls-cert-validity.h:44
SC_ERR_INVALID_ARGUMENT
@ SC_ERR_INVALID_ARGUMENT
Definition: util-error.h:43
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:316
DetectAppLayerInspectEngineRegister2
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:228
detect-tls-cert-validity.c
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:238
DETECT_AL_TLS_NOTAFTER
@ DETECT_AL_TLS_NOTAFTER
Definition: detect-engine-register.h:118
Flow_::lastts
struct timeval lastts
Definition: flow.h:417
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:308
flags
uint8_t flags
Definition: decode-gre.h:0
DETECT_TLS_VALIDITY_LT
#define DETECT_TLS_VALIDITY_LT
Definition: detect-tls-cert-validity.h:28
suricata-common.h
DETECT_TLS_VALIDITY_EX
#define DETECT_TLS_VALIDITY_EX
Definition: detect-tls-cert-validity.h:33
SigMatch_::type
uint16_t type
Definition: detect.h:314
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:76
DetectTlsValidityData_::epoch2
time_t epoch2
Definition: detect-tls-cert-validity.h:43
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:255
DetectEngineInspectGenericList
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1951
DETECT_TLS_VALIDITY_GT
#define DETECT_TLS_VALIDITY_GT
Definition: detect-tls-cert-validity.h:29
DETECT_TLS_VALIDITY_VA
#define DETECT_TLS_VALIDITY_VA
Definition: detect-tls-cert-validity.h:36
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
str
#define str(s)
Definition: suricata-common.h:280
SCFree
#define SCFree(p)
Definition: util-mem.h:61
TlsValidRegisterTests
void TlsValidRegisterTests(void)
Register unit tests for tls_cert_valid.
Definition: detect-tls-cert-validity.c:1380
DetectTlsValidityData_::epoch
time_t epoch
Definition: detect-tls-cert-validity.h:42
DETECT_TLS_TYPE_NOTBEFORE
#define DETECT_TLS_TYPE_NOTBEFORE
Definition: detect-tls-cert-validity.h:38
detect-parse.h
Signature_
Signature container.
Definition: detect.h:539
SigMatch_
a single match condition for a signature
Definition: detect.h:313
SC_Pcre2SubstringCopy
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:2587
DETECT_AL_TLS_NOTBEFORE
@ DETECT_AL_TLS_NOTBEFORE
Definition: detect-engine-register.h:117
DETECT_AL_TLS_VALID
@ DETECT_AL_TLS_VALID
Definition: detect-engine-register.h:120
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1421
SCStringPatternToTime
int SCStringPatternToTime(char *string, const char **patterns, int num_patterns, struct tm *tp)
Parse a date string based on specified patterns.
Definition: util-time.c:494
flow.h
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:302
flow-var.h
app-layer-ssl.h
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:352
TlsExpiredRegisterTests
void TlsExpiredRegisterTests(void)
Register unit tests for tls_cert_expired.
Definition: detect-tls-cert-validity.c:1372
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1227
app-layer.h