util/sasl/scram.lua
changeset 3540 bc139431830b
parent 3405 b1efe62c3c37
child 3981 2b0b8fe68df2
equal deleted inserted replaced
3539:8bbd965267b2 3540:bc139431830b
    65 end
    65 end
    66 
    66 
    67 -- hash algorithm independent Hi(PBKDF2) implementation
    67 -- hash algorithm independent Hi(PBKDF2) implementation
    68 function Hi(hmac, str, salt, i)
    68 function Hi(hmac, str, salt, i)
    69 	local Ust = hmac(str, salt.."\0\0\0\1");
    69 	local Ust = hmac(str, salt.."\0\0\0\1");
    70 	local res = Ust;	
    70 	local res = Ust;
    71 	for n=1,i-1 do
    71 	for n=1,i-1 do
    72 		local Und = hmac(str, Ust)
    72 		local Und = hmac(str, Ust)
    73 		res = binaryXOR(res, Und)
    73 		res = binaryXOR(res, Und)
    74 		Ust = Und
    74 		Ust = Und
    75 	end
    75 	end
    78 
    78 
    79 local function validate_username(username)
    79 local function validate_username(username)
    80 	-- check for forbidden char sequences
    80 	-- check for forbidden char sequences
    81 	for eq in username:gmatch("=(.?.?)") do
    81 	for eq in username:gmatch("=(.?.?)") do
    82 		if eq ~= "2D" and eq ~= "3D" then
    82 		if eq ~= "2D" and eq ~= "3D" then
    83 			return false 
    83 			return false
    84 		end 
    84 		end
    85 	end
    85 	end
    86 	
    86 	
    87 	-- replace =2D with , and =3D with =
    87 	-- replace =2D with , and =3D with =
    88 	username = username:gsub("=2D", ",");
    88 	username = username:gsub("=2D", ",");
    89 	username = username:gsub("=3D", "=");
    89 	username = username:gsub("=3D", "=");