]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] RBL module: support hashing for emails and helo RBL 1394/head
authorAndrew Lewis <nerf@judo.za.org>
Fri, 3 Feb 2017 15:28:46 +0000 (17:28 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Fri, 3 Feb 2017 15:28:46 +0000 (17:28 +0200)
src/plugins/lua/rbl.lua

index 5d3a70e630d30d420d1e11ddc88916c4efe1438d..5fde08b69e0e0a6905b2c7264c6fc3ea51c3d756 100644 (file)
@@ -25,6 +25,7 @@ local N = 'rbl'
 local rbls = {}
 local local_exclusions = nil
 
+local hash = require 'rspamd_cryptobox_hash'
 local rspamd_logger = require 'rspamd_logger'
 local rspamd_util = require 'rspamd_util'
 local fun = require 'fun'
@@ -51,6 +52,24 @@ local function validate_dns(lstr)
   return true
 end
 
+local hash_alg = {
+  sha1 = true,
+  md5 = true,
+  sha256 = true,
+  sha384 = true,
+  sha512 = true,
+}
+
+local function make_hash(data, specific)
+  local h
+  if not hash_alg[specific] then
+    h = hash.create(data)
+  else
+    h = hash.create_specific(specific, data)
+  end
+  return h:hex()
+end
+
 local function is_excluded_ip(rip)
   if local_exclusions and local_exclusions:get_key(rip) then
     return true
@@ -180,10 +199,21 @@ local function rbl_cb (task)
         return false
       end
       if not havegot['helo'] then
-        havegot['helo'] = task:get_helo()
-        if havegot['helo'] == nil or not validate_dns(havegot['helo']) then
-          notgot['helo'] = true
-          return false
+        if rbl['hash'] then
+          havegot['helo'] = task:get_helo()
+          if havegot['helo'] then
+            havegot['helo'] = make_hash(havegot['helo'], rbl['hash'])
+          else
+            notgot['helo'] = true
+            return false
+          end
+        else
+          havegot['helo'] = task:get_helo()
+          if havegot['helo'] == nil or not validate_dns(havegot['helo']) then
+            havegot['helo'] = nil
+            notgot['helo'] = true
+            return false
+          end
         end
       end
     elseif rbl['dkim'] then
@@ -221,8 +251,12 @@ local function rbl_cb (task)
               cleanList[domainpart] = true
             end
           else
-            if validate_dns(localpart) and validate_dns(domainpart) then
-              table.insert(cleanList, localpart .. '.' .. domainpart)
+            if rbl['hash'] then
+              table.insert(cleanList, make_hash(tostring(e), rbl['hash']))
+            else
+              if validate_dns(localpart) and validate_dns(domainpart) then
+                table.insert(cleanList, localpart .. '.' .. domainpart)
+              end
             end
           end
         end