Go to the documentation of this file.
54 #define PARSE_REGEX "^\\s*(<|>)?\\s*([ -:TW0-9]+)\\s*(?:(<>)\\s*([ -:TW0-9]+))?\\s*$"
58 uint8_t,
void *,
void *,
const Signature *,
61 static time_t DateStringToEpoch (
char *);
75 static int g_tls_validity_buffer_id = 0;
156 if (ssl_state == NULL) {
164 if (
flags & STREAM_TOSERVER)
171 time_t cert_epoch = 0;
187 cert_epoch >= dd->
epoch && cert_epoch <= dd->epoch2)
206 static time_t StringIsEpoch (
char *
string)
208 if (strlen(
string) == 0)
215 if (isdigit(*sp++) == 0)
219 return strtol(
string, NULL, 10);
231 static time_t DateStringToEpoch (
char *
string)
235 const char *patterns[] = {
250 while (isspace(*
string))
253 size_t inlen, oldlen;
255 oldlen = inlen = strlen(
string);
258 while (inlen > 0 && isspace(
string[inlen - 1]))
263 if (inlen < oldlen) {
264 strlcpy(tmp,
string, inlen + 1);
268 time_t epoch = StringIsEpoch(
string);
269 if (epoch != LONG_MIN) {
293 int ret = 0, res = 0;
296 char value1[20] =
"";
297 char value2[20] =
"";
301 if (ret < 3 || ret > 5) {
306 pcre2len =
sizeof(mode);
309 SCLogError(
"pcre2_substring_copy_bynumber failed");
314 pcre2len =
sizeof(value1);
315 res = pcre2_substring_copy_bynumber(parse_regex.
match, 2, (PCRE2_UCHAR8 *)value1, &pcre2len);
317 SCLogError(
"pcre2_substring_copy_bynumber failed");
323 pcre2len =
sizeof(range);
324 res = pcre2_substring_copy_bynumber(parse_regex.
match, 3, (PCRE2_UCHAR8 *)range, &pcre2len);
326 SCLogError(
"pcre2_substring_copy_bynumber failed");
332 pcre2len =
sizeof(value2);
333 res = pcre2_substring_copy_bynumber(
334 parse_regex.
match, 4, (PCRE2_UCHAR8 *)value2, &pcre2len);
336 SCLogError(
"pcre2_substring_copy_bynumber failed");
351 if (strlen(mode) > 0) {
354 else if (mode[0] ==
'>')
358 if (strlen(range) > 0) {
359 if (strcmp(
"<>", range) == 0)
363 if (strlen(range) != 0 && strlen(mode) != 0) {
364 SCLogError(
"Range specified but mode also set");
373 dd->
epoch = DateStringToEpoch(value1);
374 if (dd->
epoch == LONG_MIN)
378 if (strlen(value2) > 0) {
380 SCLogError(
"Multiple tls validity values specified but mode is not range");
384 dd->
epoch2 = DateStringToEpoch(value2);
385 if (dd->
epoch2 == LONG_MIN)
389 SCLogError(
"Second value in range must not be smaller than the first");
424 SCLogError(
"Allocation \'%s\' failed", rawstr);
440 sm->
ctx = (
void *)dd;
446 DetectTlsValidityFree(
de_ctx, dd);
475 SCLogError(
"Allocation \'%s\' failed", rawstr);
491 sm->
ctx = (
void *)dd;
497 DetectTlsValidityFree(
de_ctx, dd);
517 int r = DetectTlsValiditySetup(
de_ctx, s, rawstr,
type);
536 int r = DetectTlsValiditySetup(
de_ctx, s, rawstr,
type);
553 const char *rawstr, uint8_t
type)
563 dd = DetectTlsValidityParse(rawstr);
587 sm->
ctx = (
void *)dd;
593 DetectTlsValidityFree(
de_ctx, dd);
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
SSLv[2.0|3.[0|1|2|3]] state structure.
#define DETECT_TLS_TYPE_NOTAFTER
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
void(* Free)(DetectEngineCtx *, void *)
SSLStateConnp client_connp
#define DETECT_TLS_VALIDITY_EQ
void TlsNotBeforeRegisterTests(void)
Register unit tests for tls_cert_notbefore.
SSLStateConnp server_connp
void TlsNotAfterRegisterTests(void)
Register unit tests for tls_cert_notafter.
main detection engine ctx
time_t SCMkTimeUtc(struct tm *tp)
Convert broken-down time to seconds since Unix epoch.
#define DETECT_TLS_VALIDITY_RA
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
void DetectTlsValidityRegister(void)
Registration function for tls validity keywords.
#define SIG_FLAG_TOCLIENT
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
int DetectBufferTypeGetByName(const char *name)
size_t strlcpy(char *dst, const char *src, size_t siz)
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
SigMatch * SigMatchAlloc(void)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
#define DETECT_TLS_VALIDITY_LT
#define DETECT_TLS_VALIDITY_EX
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
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.
#define DETECT_TLS_VALIDITY_GT
#define DETECT_TLS_VALIDITY_VA
#define SCLogError(...)
Macro used to log ERROR messages.
void TlsValidRegisterTests(void)
Register unit tests for tls_cert_valid.
#define DETECT_TLS_TYPE_NOTBEFORE
a single match condition for a signature
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
@ DETECT_AL_TLS_NOTBEFORE
int SCStringPatternToTime(char *string, const char **patterns, int num_patterns, struct tm *tp)
Parse a date string based on specified patterns.
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
void TlsExpiredRegisterTests(void)
Register unit tests for tls_cert_expired.
void(* RegisterTests)(void)