1 -- Prosody IM |
1 -- Prosody IM |
2 -- Copyright (C) 2008-2010 Matthew Wild |
2 -- Copyright (C) 2008-2010 Matthew Wild |
3 -- Copyright (C) 2008-2010 Waqas Hussain |
3 -- Copyright (C) 2008-2010 Waqas Hussain |
4 -- |
4 -- |
5 -- This project is MIT/X11 licensed. Please see the |
5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. |
6 -- COPYING file in the source package for more information. |
7 -- |
7 -- |
8 |
8 |
9 local hosts = _G.hosts; |
9 local hosts = _G.hosts; |
33 return key == generate_dialback(id, to, from); |
33 return key == generate_dialback(id, to, from); |
34 end |
34 end |
35 |
35 |
36 module:hook("stanza/jabber:server:dialback:verify", function(event) |
36 module:hook("stanza/jabber:server:dialback:verify", function(event) |
37 local origin, stanza = event.origin, event.stanza; |
37 local origin, stanza = event.origin, event.stanza; |
38 |
38 |
39 if origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
39 if origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
40 -- We are being asked to verify the key, to ensure it was generated by us |
40 -- We are being asked to verify the key, to ensure it was generated by us |
41 origin.log("debug", "verifying that dialback key is ours..."); |
41 origin.log("debug", "verifying that dialback key is ours..."); |
42 local attr = stanza.attr; |
42 local attr = stanza.attr; |
43 if attr.type then |
43 if attr.type then |
60 end |
60 end |
61 end); |
61 end); |
62 |
62 |
63 module:hook("stanza/jabber:server:dialback:result", function(event) |
63 module:hook("stanza/jabber:server:dialback:result", function(event) |
64 local origin, stanza = event.origin, event.stanza; |
64 local origin, stanza = event.origin, event.stanza; |
65 |
65 |
66 if origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
66 if origin.type == "s2sin_unauthed" or origin.type == "s2sin" then |
67 -- he wants to be identified through dialback |
67 -- he wants to be identified through dialback |
68 -- We need to check the key with the Authoritative server |
68 -- We need to check the key with the Authoritative server |
69 local attr = stanza.attr; |
69 local attr = stanza.attr; |
70 local to, from = nameprep(attr.to), nameprep(attr.from); |
70 local to, from = nameprep(attr.to), nameprep(attr.from); |
71 |
71 |
72 if not hosts[to] then |
72 if not hosts[to] then |
73 -- Not a host that we serve |
73 -- Not a host that we serve |
74 origin.log("info", "%s tried to connect to %s, which we don't serve", from, to); |
74 origin.log("info", "%s tried to connect to %s, which we don't serve", from, to); |
75 origin:close("host-unknown"); |
75 origin:close("host-unknown"); |
76 return true; |
76 return true; |
77 elseif not from then |
77 elseif not from then |
78 origin:close("improper-addressing"); |
78 origin:close("improper-addressing"); |
79 end |
79 end |
80 |
80 |
81 origin.hosts[from] = { dialback_key = stanza[1] }; |
81 origin.hosts[from] = { dialback_key = stanza[1] }; |
82 |
82 |
83 dialback_requests[from.."/"..origin.streamid] = origin; |
83 dialback_requests[from.."/"..origin.streamid] = origin; |
84 |
84 |
85 -- COMPAT: ejabberd, gmail and perhaps others do not always set 'to' and 'from' |
85 -- COMPAT: ejabberd, gmail and perhaps others do not always set 'to' and 'from' |
86 -- on streams. We fill in the session's to/from here instead. |
86 -- on streams. We fill in the session's to/from here instead. |
87 if not origin.from_host then |
87 if not origin.from_host then |
88 origin.from_host = from; |
88 origin.from_host = from; |
89 end |
89 end |
100 end |
100 end |
101 end); |
101 end); |
102 |
102 |
103 module:hook("stanza/jabber:server:dialback:verify", function(event) |
103 module:hook("stanza/jabber:server:dialback:verify", function(event) |
104 local origin, stanza = event.origin, event.stanza; |
104 local origin, stanza = event.origin, event.stanza; |
105 |
105 |
106 if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then |
106 if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then |
107 local attr = stanza.attr; |
107 local attr = stanza.attr; |
108 local dialback_verifying = dialback_requests[attr.from.."/"..(attr.id or "")]; |
108 local dialback_verifying = dialback_requests[attr.from.."/"..(attr.id or "")]; |
109 if dialback_verifying and attr.from == origin.to_host then |
109 if dialback_verifying and attr.from == origin.to_host then |
110 local valid; |
110 local valid; |
129 end |
129 end |
130 end); |
130 end); |
131 |
131 |
132 module:hook("stanza/jabber:server:dialback:result", function(event) |
132 module:hook("stanza/jabber:server:dialback:result", function(event) |
133 local origin, stanza = event.origin, event.stanza; |
133 local origin, stanza = event.origin, event.stanza; |
134 |
134 |
135 if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then |
135 if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then |
136 -- Remote server is telling us whether we passed dialback |
136 -- Remote server is telling us whether we passed dialback |
137 |
137 |
138 local attr = stanza.attr; |
138 local attr = stanza.attr; |
139 if not hosts[attr.to] then |
139 if not hosts[attr.to] then |
140 origin:close("host-unknown"); |
140 origin:close("host-unknown"); |
141 return true; |
141 return true; |
142 elseif hosts[attr.to].s2sout[attr.from] ~= origin then |
142 elseif hosts[attr.to].s2sout[attr.from] ~= origin then |