22 local format = string.format; |
22 local format = string.format; |
23 local send_s2s = require "core.s2smanager".send_to_host; |
23 local send_s2s = require "core.s2smanager".send_to_host; |
24 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; |
24 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; |
25 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; |
25 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; |
26 |
26 |
|
27 local st = require "util.stanza"; |
|
28 |
27 local log = require "util.logger".init("mod_dialback"); |
29 local log = require "util.logger".init("mod_dialback"); |
28 |
30 |
29 local xmlns_dialback = "jabber:server:dialback"; |
31 local xmlns_dialback = "jabber:server:dialback"; |
30 |
32 |
31 module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, |
33 module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, |
40 type = "valid" |
42 type = "valid" |
41 else |
43 else |
42 type = "invalid" |
44 type = "invalid" |
43 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
45 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
44 end |
46 end |
45 log("debug", "verifyied dialback key... it is %s", type); |
47 log("debug", "verified dialback key... it is %s", type); |
46 origin.sends2s(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); |
48 origin.sends2s(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1])); |
47 end); |
49 end); |
48 |
50 |
49 module:add_handler("s2sin_unauthed", "result", xmlns_dialback, |
51 module:add_handler("s2sin_unauthed", "result", xmlns_dialback, |
50 function (origin, stanza) |
52 function (origin, stanza) |
55 origin.from_host = attr.from; |
57 origin.from_host = attr.from; |
56 origin.to_host = attr.to; |
58 origin.to_host = attr.to; |
57 origin.dialback_key = stanza[1]; |
59 origin.dialback_key = stanza[1]; |
58 log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); |
60 log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); |
59 send_s2s(origin.to_host, origin.from_host, |
61 send_s2s(origin.to_host, origin.from_host, |
60 format("<db:verify from='%s' to='%s' id='%s'>%s</db:verify>", origin.to_host, origin.from_host, |
62 st.stanza("db:verify", { from = origin.to_host, to = origin.from_host, id = origin.streamid }):text(origin.dialback_key)); |
61 origin.streamid, origin.dialback_key)); |
|
62 hosts[origin.to_host].s2sout[origin.from_host].dialback_verifying = origin; |
63 hosts[origin.to_host].s2sout[origin.from_host].dialback_verifying = origin; |
63 end); |
64 end); |
64 |
65 |
65 module:add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, |
66 module:add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, |
66 function (origin, stanza) |
67 function (origin, stanza) |