equal
deleted
inserted
replaced
39 local new_sasl = require "util.sasl".new; |
39 local new_sasl = require "util.sasl".new; |
40 |
40 |
41 local function build_reply(status, ret, err_msg) |
41 local function build_reply(status, ret, err_msg) |
42 local reply = st.stanza(status, {xmlns = xmlns_sasl}); |
42 local reply = st.stanza(status, {xmlns = xmlns_sasl}); |
43 if status == "challenge" then |
43 if status == "challenge" then |
|
44 log("challenge", ret or ""); |
44 reply:text(base64.encode(ret or "")); |
45 reply:text(base64.encode(ret or "")); |
45 elseif status == "failure" then |
46 elseif status == "failure" then |
46 reply:tag(ret):up(); |
47 reply:tag(ret):up(); |
47 if err_msg then reply:tag("text"):text(err_msg); end |
48 if err_msg then reply:tag("text"):text(err_msg); end |
48 elseif status == "success" then |
49 elseif status == "success" then |
|
50 log("success", ret or ""); |
49 reply:text(base64.encode(ret or "")); |
51 reply:text(base64.encode(ret or "")); |
50 else |
52 else |
51 error("Unknown sasl status: "..status); |
53 error("Unknown sasl status: "..status); |
52 end |
54 end |
53 return reply; |
55 return reply; |
63 session:reset_stream(); |
65 session:reset_stream(); |
64 end |
66 end |
65 end |
67 end |
66 |
68 |
67 local function password_callback(node, host, mechanism, raw_host) |
69 local function password_callback(node, host, mechanism, raw_host) |
68 local password = (datamanager.load(node, host, "accounts") or {}).password; -- FIXME handle hashed passwords |
70 log("host", host); |
|
71 log("raw_host", raw_host); |
|
72 local password = (datamanager.load(node, raw_host, "accounts") or {}).password; -- FIXME handle hashed passwords |
69 local func = function(x) return x; end; |
73 local func = function(x) return x; end; |
70 if password then |
74 if password then |
71 if mechanism == "PLAIN" then |
75 if mechanism == "PLAIN" then |
72 return func, password; |
76 return func, password; |
73 elseif mechanism == "DIGEST-MD5" then |
77 elseif mechanism == "DIGEST-MD5" then |
74 return func, md5(node..":"..raw_host..":"..password); |
78 return func, md5(node..":"..host..":"..password); |
75 end |
79 end |
76 end |
80 end |
77 return func, nil; |
81 return func, nil; |
78 end |
82 end |
79 |
83 |
85 return; -- FIXME ignoring out of order stanzas because ejabberd does |
89 return; -- FIXME ignoring out of order stanzas because ejabberd does |
86 end |
90 end |
87 local text = stanza[1]; |
91 local text = stanza[1]; |
88 if text then |
92 if text then |
89 text = base64.decode(text); |
93 text = base64.decode(text); |
|
94 log("recieved", text); |
90 if not text then |
95 if not text then |
91 session.sasl_handler = nil; |
96 session.sasl_handler = nil; |
92 session.send(build_reply("failure", "incorrect-encoding")); |
97 session.send(build_reply("failure", "incorrect-encoding")); |
93 return; |
98 return; |
94 end |
99 end |