Software /
code /
prosody
Annotate
util/sasl.lua @ 247:681b29aa134f
Added support for storing (and removing), loading and appending to lists of data to datamanager (for supporting offline messages)
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 13 Nov 2008 12:10:42 +0500 |
parent | 50:56272224ca4c |
child | 276:30893439d5d1 |
rev | line source |
---|---|
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
1 |
38 | 2 local base64 = require "base64" |
3 local log = require "util.logger".init("sasl"); | |
4 local tostring = tostring; | |
5 local st = require "util.stanza"; | |
6 local s_match = string.match; | |
7 module "sasl" | |
8 | |
9 | |
10 local function new_plain(onAuth, onSuccess, onFail, onWrite) | |
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
11 local object = { mechanism = "PLAIN", onAuth = onAuth, onSuccess = onSuccess, onFail = onFail, |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
12 onWrite = onWrite} |
38 | 13 --local challenge = base64.encode(""); |
14 --onWrite(st.stanza("challenge", {xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"}):text(challenge)) | |
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
15 object.feed = function(self, stanza) |
38 | 16 if stanza.name ~= "response" and stanza.name ~= "auth" then self.onFail("invalid-stanza-tag") end |
17 if stanza.attr.xmlns ~= "urn:ietf:params:xml:ns:xmpp-sasl" then self.onFail("invalid-stanza-namespace") end | |
18 local response = base64.decode(stanza[1]) | |
19 local authorization = s_match(response, "([^&%z]+)") | |
20 local authentication = s_match(response, "%z([^&%z]+)%z") | |
21 local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") | |
50
56272224ca4c
Fix for using wrong auth token as username (fixes Gajim login)
Matthew Wild <mwild1@gmail.com>
parents:
38
diff
changeset
|
22 if self.onAuth(authentication, password) == true then |
38 | 23 self.onWrite(st.stanza("success", {xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"})) |
24 self.onSuccess(authentication) | |
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
25 else |
38 | 26 self.onWrite(st.stanza("failure", {xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"}):tag("temporary-auth-failure")); |
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
27 end |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
28 end |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
29 return object |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
30 end |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
31 |
38 | 32 |
33 function new(mechanism, onAuth, onSuccess, onFail, onWrite) | |
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
34 local object |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
35 if mechanism == "PLAIN" then object = new_plain(onAuth, onSuccess, onFail, onWrite) |
38 | 36 else |
37 log("debug", "Unsupported SASL mechanism: "..tostring(mechanism)); | |
38 onFail("unsupported-mechanism") | |
15
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
39 end |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
40 return object |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
41 end |
c0d754774db2
adding SASL lib with PLAIN support, not tested yet
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
42 |
38 | 43 return _M; |