comparison mod_e2e_policy/mod_e2e_policy.lua @ 2331:611a787e6d08

mod_e2e_policy: Do not reply to error stenzas
author Michel Le Bihan <michel@lebihan.pl>
date Thu, 13 Oct 2016 16:53:40 +0200
parents 57dcad6543c9
children 58d61459cdb1
comparison
equal deleted inserted replaced
2330:f933e3909795 2331:611a787e6d08
8 local e2e_policy_message_required_chat = module:get_option_string("e2e_policy_message_required_chat", "For security reasons, OMEMO, OTR or PGP encryption is required for conversations on this server."); 8 local e2e_policy_message_required_chat = module:get_option_string("e2e_policy_message_required_chat", "For security reasons, OMEMO, OTR or PGP encryption is required for conversations on this server.");
9 local e2e_policy_message_optional_muc = module:get_option_string("e2e_policy_message_optional_muc", "For security reasons, OMEMO, OTR or PGP encryption is STRONGLY recommended for MUC on this server."); 9 local e2e_policy_message_optional_muc = module:get_option_string("e2e_policy_message_optional_muc", "For security reasons, OMEMO, OTR or PGP encryption is STRONGLY recommended for MUC on this server.");
10 local e2e_policy_message_required_muc = module:get_option_string("e2e_policy_message_required_muc", "For security reasons, OMEMO, OTR or PGP encryption is required for MUC on this server."); 10 local e2e_policy_message_required_muc = module:get_option_string("e2e_policy_message_required_muc", "For security reasons, OMEMO, OTR or PGP encryption is required for MUC on this server.");
11 11
12 function warn_on_plaintext_messages(event) 12 function warn_on_plaintext_messages(event)
13 if e2e_policy_whitelist:contains(event.stanza.attr.from) or e2e_policy_whitelist:contains(event.stanza.attr.to) then -- check if JID is whitelisted 13 -- check if JID is whitelisted
14 if e2e_policy_whitelist:contains(event.stanza.attr.from) or e2e_policy_whitelist:contains(event.stanza.attr.to) then
14 return nil; 15 return nil;
15 end 16 end
16 local body = event.stanza:get_child_text("body"); 17 local body = event.stanza:get_child_text("body");
17 -- do not warn for status messages 18 -- do not warn for status messages
18 if not body then 19 if not body or event.stanza.attr.type == "error" then
19 return nil; 20 return nil;
20 end 21 end
21 -- check otr 22 -- check otr
22 if body and body:sub(1,4) == "?OTR" then 23 if body and body:sub(1,4) == "?OTR" then
23 return nil; 24 return nil;
28 end 29 end
29 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html 30 -- check xep27 pgp https://xmpp.org/extensions/xep-0027.html
30 if event.stanza:get_child("x", "jabber:x:encrypted") then 31 if event.stanza:get_child("x", "jabber:x:encrypted") then
31 return nil; 32 return nil;
32 end 33 end
33 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html 34 -- check xep373 pgp (OX) https://xmpp.org/extensions/xep-0373.html
34 if event.stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then 35 if event.stanza:get_child("openpgp", "urn:xmpp:openpgp:0") then
35 return nil; 36 return nil;
36 end 37 end
37 -- no valid encryption found 38 -- no valid encryption found
38 if e2e_policy_chat == "optional" and event.stanza.attr.type ~= "groupchat" then 39 if e2e_policy_chat == "optional" and event.stanza.attr.type ~= "groupchat" then