X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=util%2Fsasl%2Fscram.lua;h=b3c4edc8f090ab6287b103a0a599f9ded9bcd1ad;hb=65f6c27a309f437de75aad3f8eeed1bfb27345ef;hp=0d2852bf8141d9d22c7fef8c38393378e5dfb487;hpb=38e539bc0be80a3b6a784e06c9b33e347f9524fa;p=prosody.git diff --git a/util/sasl/scram.lua b/util/sasl/scram.lua index 0d2852bf..b3c4edc8 100644 --- a/util/sasl/scram.lua +++ b/util/sasl/scram.lua @@ -25,7 +25,7 @@ local t_concat = table.concat; local char = string.char; local byte = string.byte; -module "sasl.scram" +local _ENV = nil; --========================= --SASL SCRAM-SHA-1 according to RFC 5802 @@ -87,7 +87,7 @@ local function hashprep(hashname) return hashname:lower():gsub("-", "_"); end -function getAuthenticationDatabaseSHA1(password, salt, iteration_count) +local function getAuthenticationDatabaseSHA1(password, salt, iteration_count) if type(password) ~= "string" or type(salt) ~= "string" or type(iteration_count) ~= "number" then return false, "inappropriate argument types" end @@ -150,9 +150,9 @@ local function scram_gen(hash_name, H_f, HMAC_f) -- retreive credentials local stored_key, server_key, salt, iteration_count; if self.profile.plain then - local password, state = self.profile.plain(self, username, self.realm) - if state == nil then return "failure", "not-authorized" - elseif state == false then return "failure", "account-disabled" end + local password, status = self.profile.plain(self, username, self.realm) + if status == nil then return "failure", "not-authorized" + elseif status == false then return "failure", "account-disabled" end password = saslprep(password); if not password then @@ -170,8 +170,8 @@ local function scram_gen(hash_name, H_f, HMAC_f) return "failure", "temporary-auth-failure"; end elseif self.profile[profile_name] then - local state; - stored_key, server_key, iteration_count, salt, state = self.profile[profile_name](self, username, self.realm); + local status; + stored_key, server_key, iteration_count, salt, status = self.profile[profile_name](self, username, self.realm); if state == nil then return "failure", "not-authorized" elseif state == false then return "failure", "account-disabled" end end @@ -235,7 +235,7 @@ local function scram_gen(hash_name, H_f, HMAC_f) return scram_hash; end -function init(registerMechanism) +local function init(registerMechanism) local function registerSCRAMMechanism(hash_name, hash, hmac_hash) registerMechanism("SCRAM-"..hash_name, {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash)); @@ -246,4 +246,7 @@ function init(registerMechanism) registerSCRAMMechanism("SHA-1", sha1, hmac_sha1); end -return _M; +return { + getAuthenticationDatabaseSHA1 = getAuthenticationDatabaseSHA1; + init = init; +}