Software /
code /
prosody
Annotate
plugins/mod_dialback.lua @ 559:fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 05 Dec 2008 05:23:42 +0000 |
parent | 519:cccd610a0ef9 |
child | 560:6c07f15a34f4 |
rev | line source |
---|---|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
1 -- Prosody IM v0.1 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
4 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
5 -- This program is free software; you can redistribute it and/or |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
6 -- modify it under the terms of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- as published by the Free Software Foundation; either version 2 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 -- of the License, or (at your option) any later version. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
10 -- This program is distributed in the hope that it will be useful, |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
13 -- GNU General Public License for more details. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
14 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
15 -- You should have received a copy of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
16 -- along with this program; if not, write to the Free Software |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
18 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
19 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
20 |
191 | 21 |
22 local format = string.format; | |
23 local send_s2s = require "core.s2smanager".send_to_host; | |
24 local s2s_make_authenticated = require "core.s2smanager".make_authenticated; | |
25 local s2s_verify_dialback = require "core.s2smanager".verify_dialback; | |
26 | |
559
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
519
diff
changeset
|
27 local st = require "util.stanza"; |
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
519
diff
changeset
|
28 |
191 | 29 local log = require "util.logger".init("mod_dialback"); |
30 | |
31 local xmlns_dialback = "jabber:server:dialback"; | |
32 | |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
352
diff
changeset
|
33 module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, |
219 | 34 function (origin, stanza) |
35 -- We are being asked to verify the key, to ensure it was generated by us | |
36 log("debug", "verifying dialback key..."); | |
37 local attr = stanza.attr; | |
38 -- FIXME: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 | |
39 --if attr.from ~= origin.to_host then error("invalid-from"); end | |
40 local type; | |
41 if s2s_verify_dialback(attr.id, attr.from, attr.to, stanza[1]) then | |
42 type = "valid" | |
43 else | |
44 type = "invalid" | |
45 log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to); | |
46 end | |
559
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
519
diff
changeset
|
47 log("debug", "verified dialback key... it is %s", type); |
219 | 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])); |
49 end); | |
191 | 50 |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
352
diff
changeset
|
51 module:add_handler("s2sin_unauthed", "result", xmlns_dialback, |
219 | 52 function (origin, stanza) |
53 -- he wants to be identified through dialback | |
54 -- We need to check the key with the Authoritative server | |
55 local attr = stanza.attr; | |
56 local attr = stanza.attr; | |
57 origin.from_host = attr.from; | |
58 origin.to_host = attr.to; | |
59 origin.dialback_key = stanza[1]; | |
60 log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); | |
61 send_s2s(origin.to_host, origin.from_host, | |
559
fa4a51fe6442
Remove an incorrect line which I didn't add, and fix the proper way. Corrects the sending of stanzas over unauthed s2sout's. Also fixes mod_dialback to send stanzas and not strings.
Matthew Wild <mwild1@gmail.com>
parents:
519
diff
changeset
|
62 st.stanza("db:verify", { from = origin.to_host, to = origin.from_host, id = origin.streamid }):text(origin.dialback_key)); |
260
182f0c895676
Now outgoing s2s sessions are associated with their from_host, fixes #15
Matthew Wild <mwild1@gmail.com>
parents:
259
diff
changeset
|
63 hosts[origin.to_host].s2sout[origin.from_host].dialback_verifying = origin; |
219 | 64 end); |
191 | 65 |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
352
diff
changeset
|
66 module:add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, |
219 | 67 function (origin, stanza) |
68 if origin.dialback_verifying then | |
69 local valid; | |
70 local attr = stanza.attr; | |
71 if attr.type == "valid" then | |
72 s2s_make_authenticated(origin.dialback_verifying); | |
73 valid = "valid"; | |
74 else | |
75 -- Warn the original connection that is was not verified successfully | |
76 log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); | |
77 valid = "invalid"; | |
191 | 78 end |
347
fba39fda0879
Don't error if the original s2s connection has closed before we get the dialback result
Matthew Wild <mwild1@gmail.com>
parents:
260
diff
changeset
|
79 if not origin.dialback_verifying.sends2s then |
348
aab28eacd84e
Show which session got disconnected in log message
Matthew Wild <mwild1@gmail.com>
parents:
347
diff
changeset
|
80 log("warn", "Incoming s2s session %s was closed in the meantime, so we can't notify it of the db result", tostring(origin.dialback_verifying):match("%w+$")); |
347
fba39fda0879
Don't error if the original s2s connection has closed before we get the dialback result
Matthew Wild <mwild1@gmail.com>
parents:
260
diff
changeset
|
81 else |
fba39fda0879
Don't error if the original s2s connection has closed before we get the dialback result
Matthew Wild <mwild1@gmail.com>
parents:
260
diff
changeset
|
82 origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", |
352
a73a5afd7da3
Fix the reversed to/from on the final db:result. Fixes M-Link and Gmail. Thanks dwd!!
Matthew Wild <mwild1@gmail.com>
parents:
348
diff
changeset
|
83 attr.to, attr.from, attr.id, valid, origin.dialback_verifying.dialback_key)); |
347
fba39fda0879
Don't error if the original s2s connection has closed before we get the dialback result
Matthew Wild <mwild1@gmail.com>
parents:
260
diff
changeset
|
84 end |
219 | 85 end |
86 end); | |
191 | 87 |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
352
diff
changeset
|
88 module:add_handler({ "s2sout_unauthed", "s2sout" }, "result", xmlns_dialback, |
219 | 89 function (origin, stanza) |
90 if stanza.attr.type == "valid" then | |
91 s2s_make_authenticated(origin); | |
92 else | |
93 -- FIXME | |
94 error("dialback failed!"); | |
95 end | |
96 end); |