diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-02-03 17:28:46 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-02-03 17:28:46 +0200 |
commit | 7ccfd4d345fe6b8a4b491e77a0da615eab6f1068 (patch) | |
tree | 62fb8bd1d42c13da660ab6373af75ceb2bc904b6 | |
parent | c0e76d49b5133638cee11846a1fc79d8929c865a (diff) | |
download | rspamd-7ccfd4d345fe6b8a4b491e77a0da615eab6f1068.tar.gz rspamd-7ccfd4d345fe6b8a4b491e77a0da615eab6f1068.zip |
[Feature] RBL module: support hashing for emails and helo RBL
-rw-r--r-- | src/plugins/lua/rbl.lua | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index 5d3a70e63..5fde08b69 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -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 |