Software /
code /
prosody
Comparison
util/sasl/scram.lua @ 6786:3deeb38d79ab
util.sasl.scram: Get rid of module call
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 07 Apr 2015 23:26:32 +0200 |
parent | 5871:e80916ce8d32 |
child | 7216:65e36b81d56a |
comparison
equal
deleted
inserted
replaced
6785:bf1f09a5bcf7 | 6786:3deeb38d79ab |
---|---|
23 local log = require "util.logger".init("sasl"); | 23 local log = require "util.logger".init("sasl"); |
24 local t_concat = table.concat; | 24 local t_concat = table.concat; |
25 local char = string.char; | 25 local char = string.char; |
26 local byte = string.byte; | 26 local byte = string.byte; |
27 | 27 |
28 module "sasl.scram" | 28 local _ENV = nil; |
29 | 29 |
30 --========================= | 30 --========================= |
31 --SASL SCRAM-SHA-1 according to RFC 5802 | 31 --SASL SCRAM-SHA-1 according to RFC 5802 |
32 | 32 |
33 --[[ | 33 --[[ |
85 | 85 |
86 local function hashprep(hashname) | 86 local function hashprep(hashname) |
87 return hashname:lower():gsub("-", "_"); | 87 return hashname:lower():gsub("-", "_"); |
88 end | 88 end |
89 | 89 |
90 function getAuthenticationDatabaseSHA1(password, salt, iteration_count) | 90 local function getAuthenticationDatabaseSHA1(password, salt, iteration_count) |
91 if type(password) ~= "string" or type(salt) ~= "string" or type(iteration_count) ~= "number" then | 91 if type(password) ~= "string" or type(salt) ~= "string" or type(iteration_count) ~= "number" then |
92 return false, "inappropriate argument types" | 92 return false, "inappropriate argument types" |
93 end | 93 end |
94 if iteration_count < 4096 then | 94 if iteration_count < 4096 then |
95 log("warn", "Iteration count < 4096 which is the suggested minimum according to RFC 5802.") | 95 log("warn", "Iteration count < 4096 which is the suggested minimum according to RFC 5802.") |
233 end | 233 end |
234 end | 234 end |
235 return scram_hash; | 235 return scram_hash; |
236 end | 236 end |
237 | 237 |
238 function init(registerMechanism) | 238 local function init(registerMechanism) |
239 local function registerSCRAMMechanism(hash_name, hash, hmac_hash) | 239 local function registerSCRAMMechanism(hash_name, hash, hmac_hash) |
240 registerMechanism("SCRAM-"..hash_name, {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash)); | 240 registerMechanism("SCRAM-"..hash_name, {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash)); |
241 | 241 |
242 -- register channel binding equivalent | 242 -- register channel binding equivalent |
243 registerMechanism("SCRAM-"..hash_name.."-PLUS", {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash), {"tls-unique"}); | 243 registerMechanism("SCRAM-"..hash_name.."-PLUS", {"plain", "scram_"..(hashprep(hash_name))}, scram_gen(hash_name:lower(), hash, hmac_hash), {"tls-unique"}); |
244 end | 244 end |
245 | 245 |
246 registerSCRAMMechanism("SHA-1", sha1, hmac_sha1); | 246 registerSCRAMMechanism("SHA-1", sha1, hmac_sha1); |
247 end | 247 end |
248 | 248 |
249 return _M; | 249 return { |
250 getAuthenticationDatabaseSHA1 = getAuthenticationDatabaseSHA1; | |
251 init = init; | |
252 } |