Mercurial > prosody-hg
comparison core/stanza_router.lua @ 191:e64c8a44060f
Fix s2s once and for all
- Moved dialback to the new mod_dialback (mostly).
- Modules can now supply a list of origins to handle to add_handler
- Modules can now handle and process any stanza, overriding the core
- Modules handle non-jabber:client/jabber:server xmlns'd stanzas
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 01 Nov 2008 21:07:14 +0000 |
| parents | 1e993b7deae7 |
| children | 71c389c6fc2e |
comparison
equal
deleted
inserted
replaced
| 190:1e993b7deae7 | 191:e64c8a44060f |
|---|---|
| 14 local rostermanager = require "core.rostermanager"; | 14 local rostermanager = require "core.rostermanager"; |
| 15 local sessionmanager = require "core.sessionmanager"; | 15 local sessionmanager = require "core.sessionmanager"; |
| 16 | 16 |
| 17 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; | 17 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; |
| 18 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; | 18 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; |
| 19 | |
| 20 local modules_handle_stanza = require "core.modulemanager".handle_stanza; | |
| 21 | |
| 19 local format = string.format; | 22 local format = string.format; |
| 20 local tostring = tostring; | 23 local tostring = tostring; |
| 21 | 24 |
| 22 local jid_split = require "util.jid".split; | 25 local jid_split = require "util.jid".split; |
| 23 local print = print; | 26 local print = print; |
| 55 handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); | 58 handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare); |
| 56 elseif hosts[to] and hosts[to].type == "local" then | 59 elseif hosts[to] and hosts[to].type == "local" then |
| 57 core_handle_stanza(origin, stanza); | 60 core_handle_stanza(origin, stanza); |
| 58 elseif stanza.name == "iq" and not select(3, jid_split(to)) then | 61 elseif stanza.name == "iq" and not select(3, jid_split(to)) then |
| 59 core_handle_stanza(origin, stanza); | 62 core_handle_stanza(origin, stanza); |
| 63 elseif stanza.attr.xmlns ~= "jabber:client" and stanza.attr.xmlns ~= "jabber:server" then | |
| 64 modules_handle_stanza(origin, stanza); | |
| 60 elseif origin.type == "c2s" or origin.type == "s2sin" then | 65 elseif origin.type == "c2s" or origin.type == "s2sin" then |
| 61 core_route_stanza(origin, stanza); | 66 core_route_stanza(origin, stanza); |
| 62 end | 67 end |
| 63 end | 68 end |
| 64 | 69 |
| 65 -- This function handles stanzas which are not routed any further, | 70 -- This function handles stanzas which are not routed any further, |
| 66 -- that is, they are handled by this server | 71 -- that is, they are handled by this server |
| 67 function core_handle_stanza(origin, stanza) | 72 function core_handle_stanza(origin, stanza) |
| 68 -- Handlers | 73 -- Handlers |
| 74 if modules_handle_stanza(origin, stanza) then return; end | |
| 69 if origin.type == "c2s" or origin.type == "c2s_unauthed" then | 75 if origin.type == "c2s" or origin.type == "c2s_unauthed" then |
| 70 local session = origin; | 76 local session = origin; |
| 71 | 77 |
| 72 if stanza.name == "presence" and origin.roster then | 78 if stanza.name == "presence" and origin.roster then |
| 73 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then | 79 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then |
| 105 end | 111 end |
| 106 origin.presence = stanza; | 112 origin.presence = stanza; |
| 107 stanza.attr.to = nil; -- reset it | 113 stanza.attr.to = nil; -- reset it |
| 108 else | 114 else |
| 109 -- TODO error, bad type | 115 -- TODO error, bad type |
| 110 end | |
| 111 else | |
| 112 log("debug", "Routing stanza to local"); | |
| 113 handle_stanza(session, stanza); | |
| 114 end | |
| 115 elseif origin.type == "s2sin_unauthed" or origin.type == "s2sin" then | |
| 116 if stanza.attr.xmlns == "jabber:server:dialback" then | |
| 117 if stanza.name == "verify" then | |
| 118 -- We are being asked to verify the key, to ensure it was generated by us | |
| 119 log("debug", "verifying dialback key..."); | |
| 120 local attr = stanza.attr; | |
| 121 print(tostring(attr.to), tostring(attr.from)) | |
| 122 print(tostring(origin.to_host), tostring(origin.from_host)) | |
| 123 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 | |
| 124 --if attr.from ~= origin.to_host then error("invalid-from"); end | |
| 125 local type; | |
| 126 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then | |
| 127 type = "valid" | |
| 128 else | |
| 129 type = "invalid" | |
| 130 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); | |
| 131 end | |
| 132 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])); | |
| 133 elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then | |
| 134 -- he wants to be identified through dialback | |
| 135 -- We need to check the key with the Authoritative server | |
| 136 local attr = stanza.attr; | |
| 137 origin.from_host = attr.from; | |
| 138 origin.to_host = attr.to; | |
| 139 origin.dialback_key = stanza[1]; | |
| 140 log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); | |
| 141 send_s2s(origin.to_host, origin.from_host, format("<db:verify from='%s' to='%s' id='%s'>%s</db:verify>", origin.to_host, origin.from_host, origin.streamid, origin.dialback_key)); | |
| 142 hosts[origin.from_host].dialback_verifying = origin; | |
| 143 end | |
| 144 end | |
| 145 elseif origin.type == "s2sout_unauthed" or origin.type == "s2sout" then | |
| 146 if stanza.attr.xmlns == "jabber:server:dialback" then | |
| 147 if stanza.name == "result" then | |
| 148 if stanza.attr.type == "valid" then | |
| 149 s2s_make_authenticated(origin); | |
| 150 else | |
| 151 -- FIXME | |
| 152 error("dialback failed!"); | |
| 153 end | |
| 154 elseif stanza.name == "verify" and origin.dialback_verifying then | |
| 155 local valid; | |
| 156 local attr = stanza.attr; | |
| 157 if attr.type == "valid" then | |
| 158 s2s_make_authenticated(origin.dialback_verifying); | |
| 159 valid = "valid"; | |
| 160 else | |
| 161 -- Warn the original connection that is was not verified successfully | |
| 162 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); | |
| 163 valid = "invalid"; | |
| 164 end | |
| 165 origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); | |
| 166 end | 116 end |
| 167 end | 117 end |
| 168 else | 118 else |
| 169 log("warn", "Unhandled origin: %s", origin.type); | 119 log("warn", "Unhandled origin: %s", origin.type); |
| 170 end | 120 end |
