Software /
code /
prosody-modules
File
mod_inject_ecaps2/mod_inject_ecaps2.lua @ 6110:1a6cd0bbb7ab
mod_compliance_2023: Add 2023 Version of the compliance module, basis is the 2021 Version.
diff --git a/mod_compliance_2023/README.md b/mod_compliance_2023/README.md
new file mode 100644
--- /dev/null
+++ b/mod_compliance_2023/README.md
@@ -0,0 +1,22 @@
+---
+summary: XMPP Compliance Suites 2023 self-test
+labels:
+- Stage-Beta
+rockspec:
+ dependencies:
+ - mod_cloud_notify
+
+...
+
+Compare the list of enabled modules with
+[XEP-0479: XMPP Compliance Suites 2023] and produce basic report to the
+Prosody log file.
+
+If installed with the Prosody plugin installer then all modules needed for a green checkmark should be included. (With prosody 0.12 only [mod_cloud_notify] is not included with prosody and we need the community module)
+
+# Compatibility
+
+ Prosody-Version Status
+ --------------- ----------------------
+ trunk Works as of 2024-12-21
+ 0.12 Works
diff --git a/mod_compliance_2023/mod_compliance_2023.lua b/mod_compliance_2023/mod_compliance_2023.lua
new file mode 100644
--- /dev/null
+++ b/mod_compliance_2023/mod_compliance_2023.lua
@@ -0,0 +1,79 @@
+-- Copyright (c) 2021 Kim Alvefur
+--
+-- This module is MIT licensed.
+
+local hostmanager = require "core.hostmanager";
+
+local array = require "util.array";
+local set = require "util.set";
+
+local modules_enabled = module:get_option_inherited_set("modules_enabled");
+
+for host in pairs(hostmanager.get_children(module.host)) do
+ local component = module:context(host):get_option_string("component_module");
+ if component then
+ modules_enabled:add(component);
+ modules_enabled:include(module:context(host):get_option_set("modules_enabled", {}));
+ end
+end
+
+local function check(suggested, alternate, ...)
+ if set.intersection(modules_enabled, set.new({suggested; alternate; ...})):empty() then return suggested; end
+ return false;
+end
+
+local compliance = {
+ array {"Server"; check("tls"); check("disco")};
+
+ array {"Advanced Server"; check("pep", "pep_simple")};
+
+ array {"Web"; check("bosh"); check("websocket")};
+
+ -- No Server requirements for Advanced Web
+
+ array {"IM"; check("vcard_legacy", "vcard"); check("carbons"); check("http_file_share", "http_upload")};
+
+ array {
+ "Advanced IM";
+ check("vcard_legacy", "vcard");
+ check("blocklist");
+ check("muc");
+ check("private");
+ check("smacks");
+ check("mam");
+ check("bookmarks");
+ };
+
+ array {"Mobile"; check("smacks"); check("csi_simple", "csi_battery_saver")};
+
+ array {"Advanced Mobile"; check("cloud_notify")};
+
+ array {"A/V Calling"; check("turn_external", "external_services", "turncredentials", "extdisco")};
+
+};
+
+function check_compliance()
+ local compliant = true;
+ for _, suite in ipairs(compliance) do
+ local section = suite:pop(1);
+ if module:get_option_boolean("compliance_" .. section:lower():gsub("%A", "_"), true) then
+ local missing = set.new(suite:filter(function(m) return type(m) == "string" end):map(function(m) return "mod_" .. m end));
+ if suite[1] then
+ if compliant then
+ compliant = false;
+ module:log("warn", "Missing some modules for XMPP Compliance 2023");
+ end
+ module:log("info", "%s Compliance: %s", section, missing);
+ end
+ end
+ end
+
+ if compliant then module:log("info", "XMPP Compliance 2023: Compliant ✔️"); end
+end
+
+if prosody.start_time then
+ check_compliance()
+else
+ module:hook_global("server-started", check_compliance);
+end
+
author | Menel <menel@snikket.de> |
---|---|
date | Sun, 22 Dec 2024 16:06:28 +0100 |
parent | 3105:ce946d9d982e |
line wrap: on
line source
module:depends("cache_c2s_caps"); local st = require "util.stanza"; local hashes = require "util.hashes"; local base64 = require "util.encodings".base64; local t_insert, t_sort, t_concat = table.insert, table.sort, table.concat; local algorithms = module:get_option_set("ecaps2_hashes", { "sha-256", "sha-512" }); -- TODO: Add all of the other hashes supported. local algorithm_map = { ["sha-256"] = hashes.sha256; ["sha-512"] = hashes.sha512; }; -- TODO: move that to util.caps maybe. local function calculate_hash(disco_info) local identities, features, extensions = {}, {}, {}; for _, tag in ipairs(disco_info) do if tag.name == "identity" then t_insert(identities, ((tag.attr.category or "").."\31".. (tag.attr.type or "").."\31".. (tag.attr["xml:lang"] or "").."\31".. (tag.attr.name or "").."\31\30")); elseif tag.name == "feature" then t_insert(features, (tag.attr.var or "").."\31"); elseif tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then local form = {}; for _, field in ipairs(tag.tags) do if field.name == "field" and field.attr.xmlns == "jabber:x:data" and field.attr.var then local values = {}; for _, value in ipairs(field.tags) do if value.name == "value" and value.attr.xmlns == "jabber:x:data" then value = #value.tags == 0 and value:get_text(); if value then t_insert(values, value.."\31"); end end end t_sort(values); if #values > 0 then t_insert(form, field.attr.var.."\31"..t_concat(values, "\31").."\31\30"); else t_insert(form, field.attr.var.."\31\30"); end end end t_sort(form); form = t_concat(form, "\29").."\29"; t_insert(extensions, form); else return nil, "Unknown element in disco#info"; end end t_sort(identities); t_sort(features); t_sort(extensions); if #identities > 0 then identities = t_concat(identities, "\28").."\28"; else identities = "\28"; end if #features > 0 then features = t_concat(features).."\28"; else features = "\28"; end if #extensions > 0 then extensions = t_concat(extensions, "\28").."\28"; else extensions = "\28"; end return features..identities..extensions; end local function caps_handler(event) local origin = event.origin; if origin.presence == nil or origin.presence:get_child("c", "urn:xmpp:caps") then return; end local disco_info = origin.caps_cache; if disco_info == nil then return; end local extension_string, err = calculate_hash(disco_info); if extension_string == nil then module:log("warn", "Failed to calculate ecaps2 hash: %s", err) return; end local ecaps2 = st.stanza("c", { xmlns = "urn:xmpp:caps" }); for algo in algorithms do local func = algorithm_map[algo]; if func ~= nil then local hash = base64.encode(func(extension_string)); ecaps2:tag("hash", { xmlns = "urn:xmpp:hashes:2"; algo = algo }) :text(hash) :up(); end end module:log("debug", "Injected ecaps2 element in presence"); origin.presence:add_child(ecaps2); end module:hook("c2s-capabilities-changed", caps_handler);