aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-08-26 13:15:06 +0100
committerMatthew Wild <mwild1@gmail.com>2008-08-26 13:15:06 +0100
commit3c5654cfc8fb53672714cdb8309c0a6d71018ead (patch)
treeedb2558a7c524935b81ed95fbb4263fbbbb2f4de
parent5f1085df7eeb44e7b2e0271c86cf43b4780270e2 (diff)
parent53b44292cbf272619c73a04fd7bfeaa58e32b8be (diff)
downloadprosody-3c5654cfc8fb53672714cdb8309c0a6d71018ead.tar.gz
prosody-3c5654cfc8fb53672714cdb8309c0a6d71018ead.zip
Merged in Tobias's SASL lib
-rw-r--r--util/sasl.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/util/sasl.lua b/util/sasl.lua
new file mode 100644
index 00000000..fb3aff94
--- /dev/null
+++ b/util/sasl.lua
@@ -0,0 +1,34 @@
+require "base64"
+sasl = {}
+
+function sasl:new_plain(onAuth, onSuccess, onFail, onWrite)
+ local object = { mechanism = "PLAIN", onAuth = onAuth, onSuccess = onSuccess, onFail = onFail,
+ onWrite = onWrite}
+ local challenge = base64.encode("");
+ onWrite(stanza.stanza("challenge", {xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"}):text(challenge))
+ object.feed = function(self, stanza)
+ if (stanza.name ~= "response") then self.onFail() end
+ if (stanza.attr.xmlns ~= "urn:ietf:params:xml:ns:xmpp-sasl") then self.onFail() end
+ local response = base64.decode(stanza.tag[1])
+ local authorization = string.match(response, [[([^&\0]+)]])
+ local authentication = string.match(response, [[\0([^&\0]+)\0]])
+ local password = string.match(response, [[\0[^&\0]+\0([^&\0]+)]])
+ if self.onAuth(authorization, password) == true then
+ self.onWrite(stanza.stanza("success", {xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"}))
+ self.onSuccess()
+ else
+ self.onWrite(stanza.stanza("failure", {xmlns = "urn:ietf:params:xml:ns:xmpp-sasl"}):tag("temporary-auth-failure"));
+ end
+ end
+ return object
+end
+
+function sasl:new(mechanism, onAuth, onSuccess, onFail, onWrite)
+ local object
+ if mechanism == "PLAIN" then object = new_plain(onAuth, onSuccess, onFail, onWrite)
+ else onFail()
+ end
+ return object
+end
+
+module "sasl"