--- sasl.lua v0.1
--- Copyright (C) 2008 Tobias Markmann
+-- sasl.lua v0.4
+-- Copyright (C) 2008-2009 Tobias Markmann
--
-- All rights reserved.
--
if not response["cnonce"] then return "failure", "malformed-request", "Missing entry for cnonce in SASL message." end
if not response["qop"] then response["qop"] = "auth" end
- if response["realm"] == nil then
- response["realm"] = ""
+ if response["realm"] == nil or response["realm"] == "" then
+ response["realm"] = self.realm;
elseif response["realm"] ~= self.realm then
return "failure", "not-authorized", "Incorrect realm value";
end
- local decoder;
+ local decoder;
if response["charset"] == nil then
decoder = utf8tolatin1ifpossible;
elseif response["charset"] ~= "utf-8" then
elseif Y == false then return "failure", "account-disabled" end
local A1 = Y..":"..response["nonce"]..":"..response["cnonce"]--:authzid
- local A2 = "AUTHENTICATE:"..protocol.."/"..idna_ascii(domain)
+ local A2 = "AUTHENTICATE:"..protocol.."/"..domain;
local HA1 = md5(A1, true)
local HA2 = md5(A2, true)
if response_value == response["response"] then
-- calculate rspauth
- A2 = ":"..protocol.."/"..idna_ascii(domain)
+ A2 = ":"..protocol.."/"..domain;
HA1 = md5(A1, true)
HA2 = md5(A2, true)
return object
end
+local function new_anonymous(realm, password_handler)
+ local object = { mechanism = "ANONYMOUS", realm = realm, password_handler = password_handler}
+ function object.feed(self, message)
+ return "success"
+ end
+ --TODO: From XEP-0175 "It is RECOMMENDED for the node identifier to be a UUID as specified in RFC 4122 [5]." So util.uuid() should (or have an option to) behave as specified in RFC 4122.
+ object["username"] = generate_uuid()
+ return object
+end
+
+
function new(mechanism, realm, password_handler)
local object
if mechanism == "PLAIN" then object = new_plain(realm, password_handler)
elseif mechanism == "DIGEST-MD5" then object = new_digest_md5(realm, password_handler)
+ elseif mechanism == "ANONYMOUS" then object = new_anonymous(realm, password_handler)
else
log("debug", "Unsupported SASL mechanism: "..tostring(mechanism));
return nil