31 origin.log("debug", "verifying that dialback key is ours..."); |
31 origin.log("debug", "verifying that dialback key is ours..."); |
32 local attr = stanza.attr; |
32 local attr = stanza.attr; |
33 -- COMPAT: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 |
33 -- COMPAT: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 |
34 --if attr.from ~= origin.to_host then error("invalid-from"); end |
34 --if attr.from ~= origin.to_host then error("invalid-from"); end |
35 local type; |
35 local type; |
36 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then |
36 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza:get_text()) then |
37 type = "valid" |
37 type = "valid" |
38 else |
38 else |
39 type = "invalid" |
39 type = "invalid" |
40 origin.log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
40 origin.log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
41 end |
41 end |
42 origin.log("debug", "verified dialback key... it is %s", type); |
42 origin.log("debug", "verified dialback key... it is %s", type); |
43 origin.sends2s(st.stanza("db:verify", { from = attr.to, to = attr.from, id = attr.id, type = type }):text(stanza[1])); |
43 origin.sends2s(st.stanza("db:verify", { from = attr.to, to = attr.from, id = attr.id, type = type }):text(stanza:get_text())); |
44 return true; |
44 return true; |
45 end |
45 end |
46 end); |
46 end); |
47 |
47 |
48 module:hook("stanza/jabber:server:dialback:result", function(event) |
48 module:hook("stanza/jabber:server:dialback:result", function(event) |
50 |
50 |
51 if origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
51 if origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
52 -- he wants to be identified through dialback |
52 -- he wants to be identified through dialback |
53 -- We need to check the key with the Authoritative server |
53 -- We need to check the key with the Authoritative server |
54 local attr = stanza.attr; |
54 local attr = stanza.attr; |
55 origin.hosts[attr.from] = { dialback_key = stanza[1] }; |
55 origin.hosts[attr.from] = { dialback_key = stanza:get_text() }; |
56 |
56 |
57 if not hosts[attr.to] then |
57 if not hosts[attr.to] then |
58 -- Not a host that we serve |
58 -- Not a host that we serve |
59 origin.log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to); |
59 origin.log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to); |
60 origin:close("host-unknown"); |
60 origin:close("host-unknown"); |
70 if not origin.to_host then |
70 if not origin.to_host then |
71 -- Just used for friendlier logging |
71 -- Just used for friendlier logging |
72 origin.to_host = attr.to; |
72 origin.to_host = attr.to; |
73 end |
73 end |
74 |
74 |
75 origin.log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]); |
75 origin.log("debug", "asking %s if key %s belongs to them", attr.from, stanza:get_text()); |
76 send_s2s(attr.to, attr.from, |
76 send_s2s(attr.to, attr.from, |
77 st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1])); |
77 st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza:get_text())); |
78 return true; |
78 return true; |
79 end |
79 end |
80 end); |
80 end); |
81 |
81 |
82 module:hook("stanza/jabber:server:dialback:verify", function(event) |
82 module:hook("stanza/jabber:server:dialback:verify", function(event) |