mod_c2s: Remove connection object from session object when connection disconnected...
[prosody.git] / plugins / mod_dialback.lua
index 34d8a2fb9e0db6b51895a75699fcf3c2552f9184..dc3c3f10a7a06cf8a52ec9aa8463c2039ed62ab4 100644 (file)
@@ -7,12 +7,12 @@
 --
 
 local hosts = _G.hosts;
-local s2s_make_authenticated = require "core.s2smanager".make_authenticated;
 
 local log = module._log;
 
 local st = require "util.stanza";
 local sha256_hash = require "util.hashes".sha256;
+local sha256_hmac = require "util.hashes".hmac_sha256;
 local nameprep = require "util.encodings".stringprep.nameprep;
 
 local xmlns_stream = "http://etherx.jabber.org/streams";
@@ -20,7 +20,7 @@ local xmlns_stream = "http://etherx.jabber.org/streams";
 local dialback_requests = setmetatable({}, { __mode = 'v' });
 
 function generate_dialback(id, to, from)
-       return sha256_hash(id..to..from..hosts[from].dialback_secret, true);
+       return sha256_hmac(sha256_hash(hosts[from].dialback_secret), to .. ' ' .. from .. ' ' .. id, true);
 end
 
 function initiate_dialback(session)
@@ -110,7 +110,7 @@ module:hook("stanza/jabber:server:dialback:verify", function(event)
                if dialback_verifying and attr.from == origin.to_host then
                        local valid;
                        if attr.type == "valid" then
-                               s2s_make_authenticated(dialback_verifying, attr.from);
+                               module:fire_event("s2s-authenticated", { session = dialback_verifying, host = attr.from });
                                valid = "valid";
                        else
                                -- Warn the original connection that is was not verified successfully
@@ -146,7 +146,7 @@ module:hook("stanza/jabber:server:dialback:result", function(event)
                        return true;
                end
                if stanza.attr.type == "valid" then
-                       s2s_make_authenticated(origin, attr.from);
+                       module:fire_event("s2s-authenticated", { session = origin, host = attr.from });
                else
                        origin:close("not-authorized", "dialback authentication failed");
                end