commit 0044f31: [Minor] Lua_util: Add maybe_obfuscate_subject utility
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Feb 12 16:28:04 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-02-12 16:12:13 +0000
URL: https://github.com/rspamd/rspamd/commit/0044f31571c0e87152d8765861fc1472c8d279f7
[Minor] Lua_util: Add maybe_obfuscate_subject utility
---
lualib/lua_util.lua | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 34bafcc4b..8d7f2bd69 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -876,5 +876,35 @@ exports.get_task_verdict = function(task)
return 'uncertain'
end
+---[[[
+-- @function lua_util.maybe_obfuscate_subject(subject, settings)
+-- Obfuscate subject if enabled in settings. Also checks utf8 validity.
+-- Supported settings:
+-- * subject_privacy = false - subject privacy is off
+-- * subject_privacy_alg = 'blake2' - default hash-algorithm to obfuscate subject
+-- * subject_privacy_prefix = 'obf' - prefix to show it's obfuscated
+-- * subject_privacy_length = 16 - cut the length of the hash
+-- @return obfuscated or validated subject
+--]]
+
+exports.maybe_obfuscate_subject = function(subject, settings)
+ local hash = require 'rspamd_cryptobox_hash'
+ if subject and not rspamd_util.is_valid_utf8(subject) then
+ subject = '???'
+ elseif settings.subject_privacy then
+ local hash_alg = settings.subject_privacy_alg or 'blake2'
+ local subject_hash = hash.create_specific(hash_alg, subject)
+
+ if settings.subject_privacy_length then
+ subject = (settings.subject_privacy_prefix or 'obf') .. ':' ..
+ subject_hash:hex():sub(1, settings.subject_privacy_length)
+ else
+ subject = (settings.subject_privacy_prefix or '') .. ':' ..
+ subject_hash:hex()
+ end
+ end
+
+ return subject
+end
return exports
More information about the Commits
mailing list