comparison plugins/muc/muc.lib.lua @ 12109:83bec90a352c

MUC: Switch ID algorithm for IQ relay (fixes #1266, #1435)
author Kim Alvefur <zash@zash.se>
date Tue, 05 Oct 2021 18:15:06 +0200
parents 631b2afa7bc1
children 3dfcdcab5446
comparison
equal deleted inserted replaced
12108:e9882c4c397f 12109:83bec90a352c
20 local jid_join = require "util.jid".join; 20 local jid_join = require "util.jid".join;
21 local jid_resource = require "util.jid".resource; 21 local jid_resource = require "util.jid".resource;
22 local resourceprep = require "util.encodings".stringprep.resourceprep; 22 local resourceprep = require "util.encodings".stringprep.resourceprep;
23 local st = require "util.stanza"; 23 local st = require "util.stanza";
24 local base64 = require "util.encodings".base64; 24 local base64 = require "util.encodings".base64;
25 local md5 = require "util.hashes".md5; 25 local hmac_sha256 = require "util.hashes".hmac_sha256;
26 local new_id = require "util.id".medium; 26 local new_id = require "util.id".medium;
27 27
28 local log = module._log; 28 local log = module._log;
29 29
30 local occupant_lib = module:require "muc/occupant" 30 local occupant_lib = module:require "muc/occupant"
836 local from_jid, orig_id, to_jid_hash = (base64.decode(id) or ""):match("^(%Z+)%z(%Z*)%z(.+)$"); 836 local from_jid, orig_id, to_jid_hash = (base64.decode(id) or ""):match("^(%Z+)%z(%Z*)%z(.+)$");
837 if not(from == from_jid or from == jid_bare(from_jid)) then return nil; end 837 if not(from == from_jid or from == jid_bare(from_jid)) then return nil; end
838 local from_occupant_jid = self:get_occupant_jid(from_jid); 838 local from_occupant_jid = self:get_occupant_jid(from_jid);
839 if from_occupant_jid == nil then return nil; end 839 if from_occupant_jid == nil then return nil; end
840 local session_jid 840 local session_jid
841 local salt = self:get_salt();
841 for to_jid in occupant:each_session() do 842 for to_jid in occupant:each_session() do
842 if md5(to_jid) == to_jid_hash then 843 if hmac_sha256(salt, to_jid):sub(1,8) == to_jid_hash then
843 session_jid = to_jid; 844 session_jid = to_jid;
844 break; 845 break;
845 end 846 end
846 end 847 end
847 if session_jid == nil then return nil; end 848 if session_jid == nil then return nil; end
865 if to == current_nick and stanza.attr.type == "get" and stanza:get_child("ping", "urn:xmpp:ping") then 866 if to == current_nick and stanza.attr.type == "get" and stanza:get_child("ping", "urn:xmpp:ping") then
866 self:route_stanza(st.reply(stanza)); 867 self:route_stanza(st.reply(stanza));
867 return true; 868 return true;
868 end 869 end
869 do -- construct_stanza_id 870 do -- construct_stanza_id
870 stanza.attr.id = base64.encode(occupant.jid.."\0"..stanza.attr.id.."\0"..md5(from)); 871 local salt = self:get_salt();
872 stanza.attr.id = base64.encode(occupant.jid.."\0"..stanza.attr.id.."\0"..hmac_sha256(salt, from):sub(1,8));
871 end 873 end
872 stanza.attr.from, stanza.attr.to = current_nick, occupant.jid; 874 stanza.attr.from, stanza.attr.to = current_nick, occupant.jid;
873 log("debug", "%s sent private iq stanza to %s (%s)", from, to, occupant.jid); 875 log("debug", "%s sent private iq stanza to %s (%s)", from, to, occupant.jid);
874 local iq_ns = stanza.tags[1].attr.xmlns; 876 local iq_ns = stanza.tags[1].attr.xmlns;
875 if iq_ns == 'vcard-temp' or iq_ns == "http://jabber.org/protocol/pubsub" or iq_ns == "urn:ietf:params:xml:ns:vcard-4.0" then 877 if iq_ns == 'vcard-temp' or iq_ns == "http://jabber.org/protocol/pubsub" or iq_ns == "urn:ietf:params:xml:ns:vcard-4.0" then