view mod_tls_policy/mod_tls_policy.lua @ 4565:3b2ae854842c

mod_muc_bot: Save occupant to room This has some side-effects: Firstly, the bot shows up in occupant list, which is nice. Secondly, the bot starts receiving messages from the room which might be wanted, but it would be better to join the room for real in this case.
author Kim Alvefur <zash@zash.se>
date Sat, 10 Apr 2021 19:23:25 +0200
parents a43ed0d28918
children 1b701f208b1b
line wrap: on
line source


assert(require"ssl.core".info, "Incompatible LuaSec version");

local function hook(event_name, typ, policy)
	if not policy then return end
	if policy == "FS" then
		policy = { cipher = "^E?C?DHE%-" };
	elseif type(policy) == "string" then
		policy = { cipher = policy };
	end

	module:hook(event_name, function (event)
		local origin = event.origin;
		if origin.encrypted then
			local info = origin.conn:socket():info();
			for key, what in pairs(policy) do
				module:log("debug", "Does info[%q] = %s match %s ?", key, tostring(info[key]), tostring(what));
				if (type(what) == "number" and what < info[key] ) or (type(what) == "string" and not info[key]:match(what)) then
					origin:close({ condition = "policy-violation", text = ("TLS %s '%s' not acceptable"):format(key, tostring(info[key])) });
					return false;
				end
				module:log("debug", "Seems so");
			end
			module:log("debug", "Policy matches");
		end
	end, 1000);
end

local policy = module:get_option(module.name, {});

if type(policy) == "string" then
	policy = { c2s = policy, s2s = policy };
end

hook("stream-features", "c2s", policy.c2s);
hook("s2s-stream-features", "s2sin", policy.s2sin or policy.s2s);
hook("stanza/http://etherx.jabber.org/streams:features", "s2sout", policy.s2sout or policy.s2s);