24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-10 21:47:01 +02:00

Fix SCRAM code (EJAB-1196)

This commit is contained in:
Badlop 2011-08-16 19:26:18 +02:00
parent 24f5c964cd
commit 4a4a7afe22

View File

@ -188,17 +188,17 @@ check_password(User, Server, Password, Digest, DigestGen) ->
US = {LUser, LServer}, US = {LUser, LServer},
case catch gen_storage:dirty_read(LServer, {passwd, US}) of case catch gen_storage:dirty_read(LServer, {passwd, US}) of
[#passwd{password = ""} = Passwd] -> [#passwd{password = ""} = Passwd] ->
Passwd = base64:decode(Passwd#passwd.storedkey), Storedkey = base64:decode(Passwd#passwd.storedkey),
DigRes = if DigRes = if
Digest /= "" -> Digest /= "" ->
Digest == DigestGen(Passwd); Digest == DigestGen(Storedkey);
true -> true ->
false false
end, end,
if DigRes -> if DigRes ->
true; true;
true -> true ->
(Passwd == Password) and (Password /= "") (Storedkey == Password) and (Password /= "")
end; end;
[#passwd{password = Passwd}] -> [#passwd{password = Passwd}] ->
DigRes = if DigRes = if
@ -589,10 +589,10 @@ scram_passwords(Host) ->
end, end,
scram_passwords(Host, Backend). scram_passwords(Host, Backend).
scram_passwords(Host, mnesia) -> scram_passwords(Host, mnesia) ->
?INFO_MSG("Converting the passwords stored in odbc for host ~p into SCRAM bits", [Host]), ?INFO_MSG("Converting the passwords stored in mnesia for host ~p into SCRAM bits", [Host]),
gen_storage_migration:migrate_mnesia( gen_storage_migration:migrate_mnesia(
Host, passwd, Host, passwd,
[{passwd, [user_host, password, storedkey, serverkey, iterationcount, salt], [{passwd, [user_host, password, storedkey, serverkey, salt, iterationcount],
fun(#passwd{password = Password} = Passwd) -> fun(#passwd{password = Password} = Passwd) ->
password_to_scram(Password, Passwd) password_to_scram(Password, Passwd)
end}]); end}]);
@ -600,7 +600,7 @@ scram_passwords(Host, odbc) ->
?INFO_MSG("Converting the passwords stored in odbc for host ~p into SCRAM bits", [Host]), ?INFO_MSG("Converting the passwords stored in odbc for host ~p into SCRAM bits", [Host]),
gen_storage_migration:migrate_odbc( gen_storage_migration:migrate_odbc(
Host, [passwd], Host, [passwd],
[{"passwd", ["user", "host", "password", "storedkey", "serverkey", "iterationcount", "salt"], [{"passwd", ["user", "host", "password", "storedkey", "serverkey", "salt", "iterationcount"],
fun(_, User, Host2, Password, _Storedkey, _Serverkey, _Iterationcount, _Salt) -> fun(_, User, Host2, Password, _Storedkey, _Serverkey, _Iterationcount, _Salt) ->
password_to_scram(Password, #passwd{user_host = {User, Host2}}) password_to_scram(Password, #passwd{user_host = {User, Host2}})
end}]). end}]).