Comparison

plugins/muc/occupant_id.lib.lua @ 12108:e9882c4c397f

MUC: Add method for getting the occupant id salt to allow reuse
author Kim Alvefur <zash@zash.se>
date Tue, 05 Oct 2021 18:13:51 +0200
parent 11215:9ce0a899ff07
child 12977:74b9e05af71e
comparison
equal deleted inserted replaced
12107:8a5a9c1adb90 12108:e9882c4c397f
8 local hmac_sha256 = require "util.hashes".hmac_sha256; 8 local hmac_sha256 = require "util.hashes".hmac_sha256;
9 local b64encode = require "util.encodings".base64.encode; 9 local b64encode = require "util.encodings".base64.encode;
10 10
11 local xmlns_occupant_id = "urn:xmpp:occupant-id:0"; 11 local xmlns_occupant_id = "urn:xmpp:occupant-id:0";
12 12
13 local function get_room_salt(room)
14 local salt = room._data.occupant_id_salt;
15 if not salt then
16 salt = uuid.generate();
17 room._data.occupant_id_salt = salt;
18 end
19 return salt;
20 end
21
13 local function get_occupant_id(room, occupant) 22 local function get_occupant_id(room, occupant)
14 if occupant.stable_id then 23 if occupant.stable_id then
15 return occupant.stable_id; 24 return occupant.stable_id;
16 end 25 end
17 26
18 local salt = room._data.occupant_id_salt; 27 local salt = get_room_salt(room)
19 if not salt then
20 salt = uuid.generate();
21 room._data.occupant_id_salt = salt;
22 end
23 28
24 occupant.stable_id = b64encode(hmac_sha256(occupant.bare_jid, salt)); 29 occupant.stable_id = b64encode(hmac_sha256(occupant.bare_jid, salt));
25 30
26 return occupant.stable_id; 31 return occupant.stable_id;
27 end 32 end
64 module:hook("muc-occupant-groupchat", update_occupant); 69 module:hook("muc-occupant-groupchat", update_occupant);
65 module:hook("muc-private-message", muc_private); 70 module:hook("muc-private-message", muc_private);
66 end 71 end
67 72
68 return { 73 return {
74 get_room_salt = get_room_salt;
69 get_occupant_id = get_occupant_id; 75 get_occupant_id = get_occupant_id;
70 }; 76 };