]> granicus.if.org Git - ejabberd/commitdiff
Support scrammed passwords in ejabberdctl import_prosody (#1549)
authorBadlop <badlop@process-one.net>
Mon, 20 Feb 2017 11:47:56 +0000 (12:47 +0100)
committerBadlop <badlop@process-one.net>
Mon, 20 Feb 2017 11:47:56 +0000 (12:47 +0100)
src/ejabberd_auth_mnesia.erl
src/ejabberd_auth_riak.erl
src/ejabberd_auth_sql.erl
src/prosody2ejabberd.erl

index a4e9c1f89b238297d130bdda57ddafb73384ef89..3145d90ca79e9b3bf4d0d2ae003e093a0ee12d9c 100644 (file)
@@ -174,7 +174,7 @@ try_register(User, Server, PasswordList) ->
     US = {LUser, LServer},
     if (LUser == error) or (LServer == error) ->
           {error, invalid_jid};
-       LPassword == error ->
+       (LPassword == error) and not is_record(Password, scram) ->
           {error, invalid_password};
        true ->
           F = fun () ->
index df332133204399b7c606fa66e90ef5673ee85564..6067c35edbea1dd3263c3a8ae18fa242cd055b0c 100644 (file)
@@ -148,7 +148,7 @@ try_register(User, Server, PasswordList) ->
     US = {LUser, LServer},
     if (LUser == error) or (LServer == error) ->
           {error, invalid_jid};
-       LPassword == error ->
+       LPassword == error and not is_record(Password, scram) ->
           {error, invalid_password};
        true ->
             case ejabberd_riak:get(passwd, passwd_schema(), US) of
index 4228b3345cd9ba2fa9c4a4f7af9fbd94c3c455b8..d8fc61703431537c977fad73b6e3f0e91192eea3 100644 (file)
@@ -201,12 +201,15 @@ try_register(User, Server, Password) ->
             {error, invalid_jid};
        (LUser == <<>>) or (LServer == <<>>) ->
             {error, invalid_jid};
-       LPassword == error ->
+       LPassword == error and not is_record(Password, scram) ->
           {error, invalid_password};
        true ->
             case is_scrammed() of
                 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(
                                  LServer,
                                  LUser,
index afb714d9bd3a2e18d157e4bd12d09402ddf63d60..881a5b3e732000306a56c2773ac531da044df20a 100644 (file)
@@ -109,8 +109,25 @@ eval_file(Path) ->
            Err
     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]) ->
-    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
        {atomic, ok} ->
            ok;