]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Fix several issues with dkim check results
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 1 Dec 2018 14:03:23 +0000 (14:03 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 1 Dec 2018 14:03:23 +0000 (14:03 +0000)
src/libserver/dkim.c
src/lua/lua_task.c

index e952ccb225d70df94bc2b912515764d4584cab26..5047531d7d478ba55f737b807969bed0d9148d87 100644 (file)
@@ -36,6 +36,8 @@
 
 #define DKIM_CANON_DEFAULT  DKIM_CANON_SIMPLE
 
+#define RSPAMD_SHORT_BH_LEN 8
+
 /* Params */
 enum rspamd_dkim_param_type {
        DKIM_PARAM_UNKNOWN = -1,
@@ -111,6 +113,7 @@ enum rspamd_arc_seal_cv {
        RSPAMD_ARC_PASS
 };
 
+
 struct rspamd_dkim_context_s {
        struct rspamd_dkim_common_ctx common;
        rspamd_mempool_t *pool;
@@ -123,6 +126,7 @@ struct rspamd_dkim_context_s {
        gchar *domain;
        gchar *selector;
        gint8 *b;
+       gchar *short_b;
        gint8 *bh;
        gchar *dns_key;
        enum rspamd_arc_seal_cv cv;
@@ -264,6 +268,8 @@ rspamd_dkim_parse_signature (rspamd_dkim_context_t * ctx,
        GError **err)
 {
        ctx->b = rspamd_mempool_alloc0 (ctx->pool, len);
+       ctx->short_b = rspamd_mempool_alloc0 (ctx->pool, RSPAMD_SHORT_BH_LEN + 1);
+       rspamd_strlcpy (ctx->short_b, param, MIN (len, RSPAMD_SHORT_BH_LEN + 1));
        (void)rspamd_cryptobox_base64_decode (param, len, ctx->b, &ctx->blen);
 
        return TRUE;
@@ -2283,9 +2289,8 @@ rspamd_dkim_check (rspamd_dkim_context_t *ctx,
        res->selector = ctx->selector;
        res->domain = ctx->domain;
        res->fail_reason = NULL;
-       res->short_b = rspamd_encode_base64 (ctx->b, 4, 0, NULL);
+       res->short_b = ctx->short_b;
        res->rcode = DKIM_CONTINUE;
-       rspamd_mempool_add_destructor (task->task_pool, g_free, (gpointer)res->short_b);
 
        if (!body_start) {
                res->rcode = DKIM_ERROR;
@@ -2530,8 +2535,7 @@ rspamd_dkim_create_result (rspamd_dkim_context_t *ctx,
        res->selector = ctx->selector;
        res->domain = ctx->domain;
        res->fail_reason = NULL;
-       res->short_b = rspamd_encode_base64 (ctx->b, 4, 0, NULL);
-       rspamd_mempool_add_destructor (task->task_pool, g_free, (gpointer)res->short_b);
+       res->short_b = ctx->short_b;
 
        return res;
 }
index 18ec67305643f5e0e178e336376fe58dd5f57259..6f4923dc8c99cfa2868b85811b5f33b0c068cc74 100644 (file)
@@ -562,6 +562,7 @@ LUA_FUNCTION_DEF (task, get_archives);
  * * `domain` - dkim domain
  * * `selector` - dkim selector
  * * `bhash` - short version of b tag (8 base64 symbols)
+ * * `fail_reason` - reason of failure (if applicable)
  * @return {list of maps} dkim check results
  */
 LUA_FUNCTION_DEF (task, get_dkim_results);
@@ -3484,7 +3485,7 @@ lua_task_get_dkim_results (lua_State *L)
                                        }
 
                                        if (res->fail_reason) {
-                                               rspamd_lua_table_set (L, "fail", res->fail_reason);
+                                               rspamd_lua_table_set (L, "fail_reason", res->fail_reason);
                                        }
 
                                        lua_rawseti (L, -2, i + 1);