diff options
author | Tobias Markmann <tm@ayena.de> | 2008-08-26 00:57:46 +0200 |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2008-08-26 00:57:46 +0200 |
commit | a7012d49236954006b922d2f41ecadf87b105d1f (patch) | |
tree | 7c213aa5c6f1d9e2c7a5689deae1caf0effb9fc2 /util | |
parent | 0dadc00f7ef1fa7fd0898fa4235a992f22d4859c (diff) | |
download | prosody-a7012d49236954006b922d2f41ecadf87b105d1f.tar.gz prosody-a7012d49236954006b922d2f41ecadf87b105d1f.zip |
adding SASL lib with PLAIN support, not tested yet
Diffstat (limited to 'util')
-rw-r--r-- | util/sasl.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/util/sasl.lua b/util/sasl.lua new file mode 100644 index 00000000..3f82350b --- /dev/null +++ b/util/sasl.lua @@ -0,0 +1,33 @@ +require "base64" + +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 = 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" |