X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fsasl.lua;h=2740b4273359ee34137941ab1765614e87d6568f;hb=bd62232f6ebac03455d3bde36cfb5a819c99f901;hp=ee2ba0356e86ccf007f19d0814b5c8932d609069;hpb=bb0279c0f434c476270fe2784da98d41c44ebdb2;p=prosody.git diff --git a/util/sasl.lua b/util/sasl.lua index ee2ba035..2740b427 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -1,5 +1,5 @@ --- sasl.lua v0.2 --- Copyright (C) 2008 Tobias Markmann +-- sasl.lua v0.4 +-- Copyright (C) 2008-2009 Tobias Markmann -- -- All rights reserved. -- @@ -176,9 +176,9 @@ local function new_digest_md5(realm, password_handler) 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"] = ""; - elseif response["realm"] ~= self.realm and response["realm"] ~= "" then + 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 @@ -235,10 +235,22 @@ local function new_digest_md5(realm, password_handler) 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