From e9ad2e5627880d2f2187024414aaf8ab61adf219 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 18 Jul 2017 10:42:23 +0200 Subject: [PATCH] Masking filter: added new obfuscation routine Masking filter: added new obfuscation routine --- server/modules/filter/masking/maskingrules.cc | 43 ++++++------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/server/modules/filter/masking/maskingrules.cc b/server/modules/filter/masking/maskingrules.cc index f866e5832..d51bc3329 100644 --- a/server/modules/filter/masking/maskingrules.cc +++ b/server/modules/filter/masking/maskingrules.cc @@ -1102,32 +1102,6 @@ bool MaskingRules::Rule::matches(const ComQueryResponse::ColumnDef& column_def, return match; } -/** - * Basic obfuscation routine - * - * @param c The bye to obfuscate - * - * @return The obfuscated byte - */ -static inline char maxscale_basic_obfuscation(const char c) -{ - if (c >= 'a' && c <= 'z') - { - return (c - 'a' + 13) % 26 + 'a'; - } - else if (c >= 'A' && c <= 'Z') - { - return (c - 'A' + 13) % 26 + 'A'; - } - else - { - char d = c + 32; - d = d > 127 ? 127 : d; - return d; - } - return c; -} - /** * Fills a buffer with a fill string * @@ -1217,11 +1191,18 @@ void MaskingRules::MatchRule::rewrite(LEncString& s) const void MaskingRules::ObfuscateRule::rewrite(LEncString& s) const { - // Basic Obfuscation routine - std::transform(s.begin(), - s.end(), - s.begin(), - maxscale_basic_obfuscation); + size_t i_len = s.length(); + LEncString::iterator i = s.begin(); + size_t c = *i + i_len; + + for (LEncString::iterator i = s.begin(); i <= s.end(); i++) + { + // ASCII 32 is first printable char + unsigned char d = abs((char)(*i ^ c)) + 32; + c += d << 3; + // ASCII 126 is last printable char + *i = d <= 126 ? d : 126; + } } void MaskingRules::ReplaceRule::rewrite(LEncString& s) const