comparison mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua @ 4650:44af84178cea

mod_cloud_notify_encrypted: For encrypted messages, push a friendly message instead of fallback body A fix for https://github.com/snikket-im/snikket-server/issues/18
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Aug 2021 10:46:31 +0100
parents 6d595857164a
children 8231774f5bfd
comparison
equal deleted inserted replaced
4649:62d41447615d 4650:44af84178cea
11 local xmlns_jingle_apps_rtp = "urn:xmpp:jingle:apps:rtp:1"; 11 local xmlns_jingle_apps_rtp = "urn:xmpp:jingle:apps:rtp:1";
12 local xmlns_push = "urn:xmpp:push:0"; 12 local xmlns_push = "urn:xmpp:push:0";
13 local xmlns_push_encrypt = "tigase:push:encrypt:0"; 13 local xmlns_push_encrypt = "tigase:push:encrypt:0";
14 local xmlns_push_encrypt_aes_128_gcm = "tigase:push:encrypt:aes-128-gcm"; 14 local xmlns_push_encrypt_aes_128_gcm = "tigase:push:encrypt:aes-128-gcm";
15 local xmlns_push_jingle = "tigase:push:jingle:0"; 15 local xmlns_push_jingle = "tigase:push:jingle:0";
16
17 local function detect_stanza_encryption(stanza)
18 local eme = stanza:get_child("encryption", "urn:xmpp:eme:0");
19 if eme then return eme.attr.namespace or ""; end
20 -- Fallback for legacy OMEMO clients without EME
21 local omemo = stanza:get_child("encrypted", "eu.siacs.conversations.axolotl");
22 if omemo then return "eu.siacs.conversations.axolotl"; end
23 end
16 24
17 -- https://xeps.tigase.net//docs/push-notifications/encrypt/#41-discovering-support 25 -- https://xeps.tigase.net//docs/push-notifications/encrypt/#41-discovering-support
18 local function account_disco_info(event) 26 local function account_disco_info(event)
19 event.reply:tag("feature", {var=xmlns_push_encrypt}):up(); 27 event.reply:tag("feature", {var=xmlns_push_encrypt}):up();
20 event.reply:tag("feature", {var=xmlns_push_encrypt_aes_128_gcm}):up(); 28 event.reply:tag("feature", {var=xmlns_push_encrypt_aes_128_gcm}):up();
59 end 67 end
60 68
61 local push_summary = event.push_summary; 69 local push_summary = event.push_summary;
62 70
63 local original_stanza = event.original_stanza; 71 local original_stanza = event.original_stanza;
64 local body = original_stanza:get_child_text("body"); 72 local is_encrypted_msg = detect_stanza_encryption(original_stanza);
65 if body and #body > 255 then 73 local body;
66 body = body:sub(1, 255); 74 if is_encrypted_msg then
75 -- TODO: localization
76 body = "You have received an encrypted message";
77 else
78 body = original_stanza:get_child_text("body");
79 if body and #body > 255 then
80 body = body:sub(1, 255);
81 end
67 end 82 end
68 83
69 local push_payload = { 84 local push_payload = {
70 unread = tonumber(push_summary["message-count"]) or 1; 85 unread = tonumber(push_summary["message-count"]) or 1;
71 sender = jid.bare(original_stanza.attr.from); 86 sender = jid.bare(original_stanza.attr.from);