]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-tls-cert-serial: use *_Register2 API functions
authorMats Klepsland <mats.klepsland@gmail.com>
Fri, 16 Mar 2018 21:17:34 +0000 (22:17 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 21 Mar 2018 09:43:43 +0000 (10:43 +0100)
Use *_Register2 API functions when registering 'tls_cert_serial'
detection keyword.

src/detect-engine-tls.c
src/detect-engine-tls.h
src/detect-tls-cert-serial.c

index 155f7faf6eebdba26e7f54e16b9570efeb0b9960..5039b16df621b8f2c2506642e7710edc281e1f60 100644 (file)
@@ -123,83 +123,6 @@ int DetectEngineInspectTlsSni(ThreadVars *tv,
     return cnt;
 }
 
-/** \brief TLS Serial Mpm prefilter callback
- *
- *  \param det_ctx detection engine thread ctx
- *  \param p packet to inspect
- *  \param f flow to inspect
- *  \param txv tx to inspect
- *  \param pectx inspection context
- */
-static void PrefilterTxTlsSerial(DetectEngineThreadCtx *det_ctx, const void *pectx,
-                                 Packet *p, Flow *f, void *txv, const uint64_t idx,
-                                 const uint8_t flags)
-{
-    SCEnter();
-
-    const MpmCtx *mpm_ctx = (MpmCtx *)pectx;
-    SSLState *ssl_state = f->alstate;
-
-    if (ssl_state->server_connp.cert0_serial == NULL)
-        return;
-
-    const uint8_t *buffer = (const uint8_t *)ssl_state->server_connp.cert0_serial;
-    const uint32_t buffer_len = strlen(ssl_state->server_connp.cert0_serial);
-
-    if (buffer_len >= mpm_ctx->minlen) {
-        (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx, &det_ctx->mtcu,
-                &det_ctx->pmq, buffer, buffer_len);
-    }
-}
-
-int PrefilterTxTlsSerialRegister(DetectEngineCtx *de_ctx,
-        SigGroupHead *sgh, MpmCtx *mpm_ctx)
-{
-    SCEnter();
-
-    return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxTlsSerial, ALPROTO_TLS,
-                                   TLS_STATE_CERT_READY, mpm_ctx, NULL,
-                                   "tls_cert_serial");
-}
-
-/** \brief Do the content inspection and validation for a signature
- *
- *  \param de_ctx   Detection engine context
- *  \param det_ctx  Detection engine thread context
- *  \param s        Signature to inspect
- *  \param sm       SigMatch to inspect
- *  \param f        Flow
- *  \param flags    App layer flags
- *  \param state    App layer state
- *
- *  \retval 0       No match
- *  \retval 1       Match
- */
-int DetectEngineInspectTlsSerial(ThreadVars *tv, DetectEngineCtx *de_ctx,
-                                 DetectEngineThreadCtx *det_ctx, const Signature *s,
-                                 const SigMatchData *smd, Flow *f,
-                                 uint8_t flags, void *alstate, void *txv,
-                                 uint64_t tx_id)
-{
-    uint8_t *buffer;
-    uint32_t buffer_len;
-    int cnt = 0;
-
-    SSLState *ssl_state = (SSLState *)alstate;
-
-    if (ssl_state->server_connp.cert0_serial == NULL)
-        return 0;
-
-    buffer = (uint8_t *)ssl_state->server_connp.cert0_serial;
-    buffer_len = strlen(ssl_state->server_connp.cert0_serial);
-
-    cnt = DetectEngineContentInspection(de_ctx, det_ctx, s, smd,
-           f, buffer, buffer_len, 0, DETECT_CI_FLAGS_SINGLE,
-           DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE, NULL);
-
-    return cnt;
-}
-
 int DetectEngineInspectTlsValidity(ThreadVars *tv,
         DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
         const Signature *s, const SigMatchData *smd,
index d79fa43f0819afd046f00227727b820f1aacf6c2..76e4e88856f11df28e2b2b2bab6d8b971257518d 100644 (file)
 
 int PrefilterTxTlsSniRegister(DetectEngineCtx *de_ctx,
         SigGroupHead *sgh, MpmCtx *mpm_ctx);
-int PrefilterTxTlsSerialRegister(DetectEngineCtx *de_ctx,
-        SigGroupHead *sgh, MpmCtx *mpm_ctx);
 
 int DetectEngineInspectTlsSni(ThreadVars *tv,
         DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
         const Signature *s, const SigMatchData *smd,
         Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
 
-int DetectEngineInspectTlsSerial(ThreadVars *tv,
-        DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
-        const Signature *s, const SigMatchData *smd,
-        Flow *f, uint8_t flags,
-        void *alstate, void *txv, uint64_t tx_id);
-
 int DetectEngineInspectTlsValidity(ThreadVars *tv,
         DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
         const Signature *s, const SigMatchData *smd,
index c275b96faf699e90e8e0ee46db839ad5f1374f21..6208d5b91ed5a254216cf222fe6090ddbbfa6147 100644 (file)
@@ -32,7 +32,7 @@
 #include "detect-parse.h"
 #include "detect-engine.h"
 #include "detect-engine-mpm.h"
-#include "detect-engine-tls.h"
+#include "detect-engine-prefilter.h"
 #include "detect-content.h"
 #include "detect-pcre.h"
 
 
 static int DetectTlsSerialSetup(DetectEngineCtx *, Signature *, const char *);
 static void DetectTlsSerialRegisterTests(void);
+static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
+        const DetectEngineTransforms *transforms,
+        Flow *_f, const uint8_t _flow_flags,
+        void *txv, const int list_id);
 static int g_tls_cert_serial_buffer_id = 0;
 
 /**
@@ -73,12 +77,16 @@ void DetectTlsSerialRegister(void)
 
     sigmatch_table[DETECT_AL_TLS_CERT_SERIAL].flags |= SIGMATCH_NOOPT;
 
-    DetectAppLayerMpmRegister("tls_cert_serial", SIG_FLAG_TOCLIENT, 2,
-            PrefilterTxTlsSerialRegister);
-
-    DetectAppLayerInspectEngineRegister("tls_cert_serial", ALPROTO_TLS,
+    DetectAppLayerInspectEngineRegister2("tls_cert_serial", ALPROTO_TLS,
             SIG_FLAG_TOCLIENT, TLS_STATE_CERT_READY,
-            DetectEngineInspectTlsSerial);
+            DetectEngineInspectBufferGeneric, GetData);
+
+    DetectAppLayerMpmRegister2("tls_cert_serial", SIG_FLAG_TOCLIENT, 2,
+            PrefilterGenericMpmRegister, GetData, ALPROTO_TLS,
+            TLS_STATE_CERT_READY);
+
+    DetectBufferTypeSetDescriptionByName("tls_cert_serial",
+            "TLS certificate serial number");
 
     g_tls_cert_serial_buffer_id = DetectBufferTypeGetByName("tls_cert_serial");
 }
@@ -94,7 +102,7 @@ void DetectTlsSerialRegister(void)
  */
 static int DetectTlsSerialSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
 {
-    s->init_data->list = g_tls_cert_serial_buffer_id;
+    DetectBufferSetActiveList(s, g_tls_cert_serial_buffer_id);
 
     if (DetectSignatureSetAppProto(s, ALPROTO_TLS) != 0)
         return -1;
@@ -102,6 +110,30 @@ static int DetectTlsSerialSetup(DetectEngineCtx *de_ctx, Signature *s, const cha
     return 0;
 }
 
+static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
+        const DetectEngineTransforms *transforms, Flow *_f,
+        const uint8_t _flow_flags, void *txv, const int list_id)
+{
+    BUG_ON(det_ctx->inspect_buffers == NULL);
+    InspectionBuffer *buffer = &det_ctx->inspect_buffers[list_id];
+
+    if (buffer->inspect == NULL) {
+        SSLState *ssl_state = (SSLState *)_f->alstate;
+
+        if (ssl_state->server_connp.cert0_serial == NULL) {
+            return NULL;
+        }
+
+        const uint32_t data_len = strlen(ssl_state->server_connp.cert0_serial);
+        const uint8_t *data = (uint8_t *)ssl_state->server_connp.cert0_serial;
+
+        InspectionBufferSetup(buffer, data, data_len);
+        InspectionBufferApplyTransforms(buffer, transforms);
+    }
+
+    return buffer;
+}
+
 #ifdef UNITTESTS
 
 /**