comparison mod_push2/mod_push2.lua @ 6180:051974b4c900

mod_push2: Fix counting bugs If padding would be negative size, we obviously can't generate it.
author Stephen Paul Weber <singpolyma@singpolyma.net>
date Mon, 24 Mar 2025 08:51:30 -0500
parents aa240145aa22
children 811bd0872682
comparison
equal deleted inserted replaced
6179:a1a33f0f6f6e 6180:051974b4c900
220 end) 220 end)
221 envelope_bytes = tostring(envelope) 221 envelope_bytes = tostring(envelope)
222 end 222 end
223 if string.len(envelope_bytes) > max_data_size then 223 if string.len(envelope_bytes) > max_data_size then
224 local body = stanza:get_child_text("body") 224 local body = stanza:get_child_text("body")
225 if string.len(body) > 50 then 225 if body and string.len(body) > 50 then
226 stanza_clone:maptags(function(el) 226 stanza_clone:maptags(function(el)
227 if el.name == "body" then 227 if el.name == "body" then
228 return nil 228 return nil
229 else 229 else
230 return el 230 return el
249 return nil 249 return nil
250 end 250 end
251 end) 251 end)
252 envelope_bytes = tostring(envelope) 252 envelope_bytes = tostring(envelope)
253 end 253 end
254 if string.len(envelope_bytes) < max_data_size/2 then 254 local padding_size = math.min(150, max_data_size/3 - string.len(envelope_bytes))
255 envelope:text_tag("rpad", base64.encode(random.bytes(math.min(150, max_data_size/3 - string.len(envelope_bytes))))) 255 if padding_size > 0 then
256 envelope:text_tag("rpad", base64.encode(random.bytes(padding_size)))
256 envelope_bytes = tostring(envelope) 257 envelope_bytes = tostring(envelope)
257 end 258 end
258 259
259 local p256dh_raw = base64.decode(match.ua_public .. "==") 260 local p256dh_raw = base64.decode(match.ua_public .. "==")
260 local p256dh = crypto.import_public_ec_raw(p256dh_raw, "prime256v1") 261 local p256dh = crypto.import_public_ec_raw(p256dh_raw, "prime256v1")