Support scrammed passwords in ejabberdctl import_prosody (#1549)

This commit is contained in:
Badlop 2017-02-20 12:47:56 +01:00
parent 9426c67302
commit 7d767fac7f
4 changed files with 25 additions and 5 deletions

View File

@ -174,7 +174,7 @@ try_register(User, Server, PasswordList) ->
US = {LUser, LServer}, US = {LUser, LServer},
if (LUser == error) or (LServer == error) -> if (LUser == error) or (LServer == error) ->
{error, invalid_jid}; {error, invalid_jid};
LPassword == error -> (LPassword == error) and not is_record(Password, scram) ->
{error, invalid_password}; {error, invalid_password};
true -> true ->
F = fun () -> F = fun () ->

View File

@ -148,7 +148,7 @@ try_register(User, Server, PasswordList) ->
US = {LUser, LServer}, US = {LUser, LServer},
if (LUser == error) or (LServer == error) -> if (LUser == error) or (LServer == error) ->
{error, invalid_jid}; {error, invalid_jid};
LPassword == error -> LPassword == error and not is_record(Password, scram) ->
{error, invalid_password}; {error, invalid_password};
true -> true ->
case ejabberd_riak:get(passwd, passwd_schema(), US) of case ejabberd_riak:get(passwd, passwd_schema(), US) of

View File

@ -201,12 +201,15 @@ try_register(User, Server, Password) ->
{error, invalid_jid}; {error, invalid_jid};
(LUser == <<>>) or (LServer == <<>>) -> (LUser == <<>>) or (LServer == <<>>) ->
{error, invalid_jid}; {error, invalid_jid};
LPassword == error -> LPassword == error and not is_record(Password, scram) ->
{error, invalid_password}; {error, invalid_password};
true -> true ->
case is_scrammed() of case is_scrammed() of
true -> true ->
Scram = password_to_scram(Password), Scram = case is_record(Password, scram) of
true -> Password;
false -> password_to_scram(Password)
end,
case catch sql_queries:add_user_scram( case catch sql_queries:add_user_scram(
LServer, LServer,
LUser, LUser,

View File

@ -109,8 +109,25 @@ eval_file(Path) ->
Err Err
end. end.
maybe_get_scram_auth(Data) ->
case proplists:get_value(<<"iteration_count">>, Data, no_ic) of
IC when is_float(IC) -> %% A float like 4096.0 is read
#scram{
storedkey = proplists:get_value(<<"stored_key">>, Data, <<"">>),
serverkey = proplists:get_value(<<"server_key">>, Data, <<"">>),
salt = proplists:get_value(<<"salt">>, Data, <<"">>),
iterationcount = round(IC)
};
_ -> <<"">>
end.
convert_data(Host, "accounts", User, [Data]) -> convert_data(Host, "accounts", User, [Data]) ->
Password = proplists:get_value(<<"password">>, Data, <<>>), Password = case proplists:get_value(<<"password">>, Data, no_pass) of
no_pass ->
maybe_get_scram_auth(Data);
Pass when is_binary(Pass) ->
Pass
end,
case ejabberd_auth:try_register(User, Host, Password) of case ejabberd_auth:try_register(User, Host, Password) of
{atomic, ok} -> {atomic, ok} ->
ok; ok;