aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-21 20:30:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-06-21 20:49:57 +0100
commit456198fdac726db604d2bbab85a0668b5c9dfa83 (patch)
tree2fccf36ec3aec8c8b62329bae6c4df603c57f050
parentf9e8c237c7a723746bc6b19360ed56e199df9e8f (diff)
downloadrspamd-456198fdac726db604d2bbab85a0668b5c9dfa83.tar.gz
rspamd-456198fdac726db604d2bbab85a0668b5c9dfa83.zip
[Rules] More fixes for bitcoin cash addresses decoding
-rw-r--r--rules/bitcoin.lua8
1 files changed, 7 insertions, 1 deletions
diff --git a/rules/bitcoin.lua b/rules/bitcoin.lua
index b7f9f1dbc..4331d8382 100644
--- a/rules/bitcoin.lua
+++ b/rules/bitcoin.lua
@@ -145,7 +145,13 @@ local function is_segwit_bech32_address(word)
if decoded then
local bytes = decoded:bytes()
- if bytes[1] == 0 then
+ -- The version byte’s most signficant bit is reserved and must be 0.
+ -- The 4 next bits indicate the type of address and the 3 least significant bits indicate the size of the hash.
+ local version = bit.band(bytes[1], 128)
+ local addr_type = bit.rshift(bit.band(bytes[1], 120), 3)
+ local _ = bit.band(bytes[1], 7) -- hash size
+
+ if version == 0 and (addr_type == 0 or addr_type == 8)then
-- TODO: Add checksum validation some day
return true