]> source.dussan.org Git - rspamd.git/commitdiff
[Rework] Another rework of the dkim signing logic 4866/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 9 Mar 2024 14:50:47 +0000 (14:50 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 9 Mar 2024 14:50:47 +0000 (14:50 +0000)
lualib/lua_dkim_tools.lua
src/plugins/lua/dkim_signing.lua

index ad780c0f0c7c6ac8bdd0a6b39a9aaf1bb537a6a1..b7f520fae6d65309410093bed6d7857b36edf6a7 100644 (file)
@@ -614,12 +614,12 @@ exports.sign_using_redis = function(N, task, settings, selectors, sign_func, err
   end
 end
 
-exports.sign_using_vault = function(N, task, settings, selectors, sign_func, err_func)
+exports.sign_using_vault = function(N, task, settings, selector, sign_func, err_func)
   local http = require "rspamd_http"
   local ucl = require "ucl"
 
   local full_url = string.format('%s/v1/%s/%s',
-      settings.vault_url, settings.vault_path or 'dkim', selectors.domain)
+      settings.vault_url, settings.vault_path or 'dkim', selector.domain)
   local upstream_list = lua_util.http_upstreams_by_url(rspamd_config:get_mempool(), settings.vault_url)
 
   local function vault_callback(err, code, body, _)
@@ -671,7 +671,7 @@ exports.sign_using_vault = function(N, task, settings, selectors, sign_func, err
             local dkim_sign_data = {
               rawkey = p.key,
               selector = p.selector,
-              domain = p.domain or selectors.domain,
+              domain = p.domain or selector.domain,
               alg = p.alg,
             }
             lua_util.debugm(N, task, 'found and parsed key for %s:%s in Vault',
@@ -707,7 +707,7 @@ exports.sign_using_vault = function(N, task, settings, selectors, sign_func, err
 
   if not ret then
     err_func(task, string.format("cannot make HTTP request to load DKIM data domain %s",
-        selectors.domain))
+        selector.domain))
   end
 end
 
index 4d16bdf373fd8ebec58369661afa9e672a589373..326ebab51673b4e697c58eb7052fced566876e4e 100644 (file)
@@ -111,31 +111,28 @@ local function dkim_signing_cb(task)
   if not ret or #selectors == 0 then
     return
   end
-
   if settings.use_redis then
+    -- Use only redis stuff here
     dkim_sign_tools.sign_using_redis(N, task, settings, selectors, do_sign, sign_error)
-  else
-    if selectors.vault then
-      dkim_sign_tools.sign_using_vault(N, task, settings, selectors, do_sign, sign_error)
+    return
+  end
+
+  for _, k in ipairs(selectors) do
+    if k.vault then
+      dkim_sign_tools.sign_using_vault(N, task, settings, k, do_sign, sign_error)
     else
-      if #selectors > 0 then
-        for _, k in ipairs(selectors) do
-          -- templates
-          if k.key then
-            k.key = lua_util.template(k.key, {
-              domain = k.domain,
-              selector = k.selector
-            })
-            lua_util.debugm(N, task, 'using key "%s", use selector "%s" for domain "%s"',
-                k.key, k.selector, k.domain)
-          end
-
-          do_sign(task, k)
-        end
-      else
-        rspamd_logger.infox(task, 'key path or dkim selector unconfigured; no signing')
-        return false
+      -- templates
+      if k.key then
+        k.key = lua_util.template(k.key, {
+          domain = k.domain,
+          selector = k.selector
+        })
+        lua_util.debugm(N, task, 'using key "%s", use selector "%s" for domain "%s"',
+            k.key, k.selector, k.domain)
       end
+
+      do_sign(task, k)
+
     end
   end
 end