]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add support of validity checks in the vault
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Apr 2019 11:50:10 +0000 (12:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 23 Apr 2019 11:50:10 +0000 (12:50 +0100)
lualib/lua_dkim_tools.lua

index ea84d58de476f2558da8deb650d80e38d349d44f..2e5856d3c6bc6535f0c41a77906efbdfa32d4f17 100644 (file)
@@ -21,6 +21,7 @@ local E = {}
 local lua_util = require "lua_util"
 local rspamd_util = require "rspamd_util"
 local logger = require "rspamd_logger"
+local fun = require "fun"
 
 local function check_violation(N, task, domain)
   -- Check for DKIM_REJECT
@@ -576,16 +577,37 @@ exports.sign_using_vault = function(N, task, settings, selectors, sign_func, err
         else
           local elts = obj.data.selectors or {}
 
-          for _,p in ipairs(elts) do
+          -- Filter selectors by time/sanity
+          local function is_selector_valid(p)
+            if not p.key or not p.selector then
+              return false
+            end
+
+            if p.valid_start then
+              -- Check start time
+              if rspamd_util.get_time() < tonumber(p.valid_start) then
+                return false
+              end
+            end
+
+            if p.valid_end then
+              if rspamd_util.get_time() >= tonumber(p.valid_end) then
+                return false
+              end
+            end
+
+            return true
+          end
+          fun.each(function(p)
             local dkim_sign_data = {
               rawkey = p.key,
               selector = p.selector,
-              domain = selectors.domain
+              domain = p.domain or selectors.domain
             }
             lua_util.debugm(N, task, 'found and parsed key for %s:%s in Vault',
                 dkim_sign_data.domain, dkim_sign_data.selector)
             sign_func(task, dkim_sign_data)
-          end
+          end, fun.filter(is_selector_valid, elts))
         end
       end
     end