Software / code / prosody
Comparison
plugins/mod_dialback.lua @ 219:f06e97f525bc
Fixed some whitespace.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Thu, 06 Nov 2008 16:57:10 +0500 |
| parent | 191:e64c8a44060f |
| child | 259:1485d272400d |
comparison
equal
deleted
inserted
replaced
| 218:1263896ab2f1 | 219:f06e97f525bc |
|---|---|
| 7 local log = require "util.logger".init("mod_dialback"); | 7 local log = require "util.logger".init("mod_dialback"); |
| 8 | 8 |
| 9 local xmlns_dialback = "jabber:server:dialback"; | 9 local xmlns_dialback = "jabber:server:dialback"; |
| 10 | 10 |
| 11 add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, | 11 add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, |
| 12 function (origin, stanza) | 12 function (origin, stanza) |
| 13 -- We are being asked to verify the key, to ensure it was generated by us | 13 -- We are being asked to verify the key, to ensure it was generated by us |
| 14 log("debug", "verifying dialback key..."); | 14 log("debug", "verifying dialback key..."); |
| 15 local attr = stanza.attr; | 15 local attr = stanza.attr; |
| 16 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 | 16 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 |
| 17 --if attr.from ~= origin.to_host then error("invalid-from"); end | 17 --if attr.from ~= origin.to_host then error("invalid-from"); end |
| 18 local type; | 18 local type; |
| 19 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then | 19 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then |
| 20 type = "valid" | 20 type = "valid" |
| 21 else | 21 else |
| 22 type = "invalid" | 22 type = "invalid" |
| 23 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); | 23 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); |
| 24 end | 24 end |
| 25 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])); | 25 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])); |
| 26 end); | 26 end); |
| 27 | 27 |
| 28 add_handler("s2sin_unauthed", "result", xmlns_dialback, | 28 add_handler("s2sin_unauthed", "result", xmlns_dialback, |
| 29 function (origin, stanza) | 29 function (origin, stanza) |
| 30 -- he wants to be identified through dialback | 30 -- he wants to be identified through dialback |
| 31 -- We need to check the key with the Authoritative server | 31 -- We need to check the key with the Authoritative server |
| 32 local attr = stanza.attr; | 32 local attr = stanza.attr; |
| 33 local attr = stanza.attr; | 33 local attr = stanza.attr; |
| 34 origin.from_host = attr.from; | 34 origin.from_host = attr.from; |
| 35 origin.to_host = attr.to; | 35 origin.to_host = attr.to; |
| 36 origin.dialback_key = stanza[1]; | 36 origin.dialback_key = stanza[1]; |
| 37 log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); | 37 log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); |
| 38 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)); | 38 send_s2s(origin.to_host, origin.from_host, |
| 39 hosts[origin.from_host].dialback_verifying = origin; | 39 format("<db:verify from='%s' to='%s' id='%s'>%s</db:verify>", origin.to_host, origin.from_host, |
| 40 end); | 40 origin.streamid, origin.dialback_key)); |
| 41 hosts[origin.from_host].dialback_verifying = origin; | |
| 42 end); | |
| 41 | 43 |
| 42 add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, | 44 add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, |
| 43 function (origin, stanza) | 45 function (origin, stanza) |
| 44 if origin.dialback_verifying then | 46 if origin.dialback_verifying then |
| 45 local valid; | 47 local valid; |
| 46 local attr = stanza.attr; | 48 local attr = stanza.attr; |
| 47 if attr.type == "valid" then | 49 if attr.type == "valid" then |
| 48 s2s_make_authenticated(origin.dialback_verifying); | 50 s2s_make_authenticated(origin.dialback_verifying); |
| 49 valid = "valid"; | 51 valid = "valid"; |
| 50 else | 52 else |
| 51 -- Warn the original connection that is was not verified successfully | 53 -- Warn the original connection that is was not verified successfully |
| 52 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); | 54 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); |
| 53 valid = "invalid"; | 55 valid = "invalid"; |
| 54 end | |
| 55 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)); | |
| 56 end | 56 end |
| 57 end); | 57 origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", |
| 58 attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key)); | |
| 59 end | |
| 60 end); | |
| 58 | 61 |
| 59 add_handler({ "s2sout_unauthed", "s2sout" }, "result", xmlns_dialback, | 62 add_handler({ "s2sout_unauthed", "s2sout" }, "result", xmlns_dialback, |
| 60 function (origin, stanza) | 63 function (origin, stanza) |
| 61 if stanza.attr.type == "valid" then | 64 if stanza.attr.type == "valid" then |
| 62 s2s_make_authenticated(origin); | 65 s2s_make_authenticated(origin); |
| 63 else | 66 else |
| 64 -- FIXME | 67 -- FIXME |
| 65 error("dialback failed!"); | 68 error("dialback failed!"); |
| 66 end | 69 end |
| 67 end); | 70 end); |