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) {
294 char value1[20] =
"";
295 char value2[20] =
"";
298 pcre2_match_data *match = NULL;
300 if (ret < 3 || ret > 5) {
305 size_t pcre2len =
sizeof(mode);
308 SCLogError(
"pcre2_substring_copy_bynumber failed");
313 pcre2len =
sizeof(value1);
314 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)value1, &pcre2len);
316 SCLogError(
"pcre2_substring_copy_bynumber failed");
322 pcre2len =
sizeof(range);
323 res = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)range, &pcre2len);
325 SCLogError(
"pcre2_substring_copy_bynumber failed");
331 pcre2len =
sizeof(value2);
332 res = pcre2_substring_copy_bynumber(match, 4, (PCRE2_UCHAR8 *)value2, &pcre2len);
334 SCLogError(
"pcre2_substring_copy_bynumber failed");
349 if (strlen(mode) > 0) {
352 else if (mode[0] ==
'>')
356 if (strlen(range) > 0) {
357 if (strcmp(
"<>", range) == 0)
361 if (strlen(range) != 0 && strlen(mode) != 0) {
362 SCLogError(
"Range specified but mode also set");
371 dd->
epoch = DateStringToEpoch(value1);
372 if (dd->
epoch == LONG_MIN)
376 if (strlen(value2) > 0) {
378 SCLogError(
"Multiple tls validity values specified but mode is not range");
382 dd->
epoch2 = DateStringToEpoch(value2);
383 if (dd->
epoch2 == LONG_MIN)
387 SCLogError(
"Second value in range must not be smaller than the first");
391 pcre2_match_data_free(match);
396 pcre2_match_data_free(match);
425 SCLogError(
"Allocation \'%s\' failed", rawstr);
438 g_tls_validity_buffer_id) == NULL) {
444 DetectTlsValidityFree(
de_ctx, dd);
470 SCLogError(
"Allocation \'%s\' failed", rawstr);
483 g_tls_validity_buffer_id) == NULL) {
489 DetectTlsValidityFree(
de_ctx, dd);
507 int r = DetectTlsValiditySetup(
de_ctx, s, rawstr,
type);
526 int r = DetectTlsValiditySetup(
de_ctx, s, rawstr,
type);
543 const char *rawstr, uint8_t
type)
552 dd = DetectTlsValidityParse(rawstr);
572 g_tls_validity_buffer_id) == NULL) {
578 DetectTlsValidityFree(
de_ctx, dd);
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
SSLv[2.0|3.[0|1|2|3]] state structure.
SigTableElmt * sigmatch_table
#define DETECT_TLS_TYPE_NOTAFTER
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.
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
#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)
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
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
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
@ DETECT_AL_TLS_NOTBEFORE
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
int SCStringPatternToTime(char *string, const char **patterns, int num_patterns, struct tm *tp)
Parse a date string based on specified patterns.
void TlsExpiredRegisterTests(void)
Register unit tests for tls_cert_expired.
void(* RegisterTests)(void)