]> granicus.if.org Git - ejabberd/commitdiff
prosody2ejabberd: Fix SCRAM hash conversion
authorHolger Weiss <holger@zedat.fu-berlin.de>
Thu, 16 Mar 2017 22:15:08 +0000 (23:15 +0100)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Thu, 16 Mar 2017 22:15:08 +0000 (23:15 +0100)
Closes #1549.

src/jlib.erl
src/prosody2ejabberd.erl

index 580ad1ffaeff3df5699d343b0754e27468d310fa..6913542f9225aef39fbc738c4ad8aaca00691792 100644 (file)
@@ -37,6 +37,7 @@
 
 -export([tolower/1, term_to_base64/1, base64_to_term/1,
         decode_base64/1, encode_base64/1, ip_to_list/1,
+        hex_to_bin/1, hex_to_base64/1,
         atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1,
         l2i/1, i2l/1, i2l/2, expr_to_term/1, term_to_expr/1,
         queue_drop_while/2, queue_foldl/3, queue_foldr/3, queue_foreach/2]).
@@ -917,6 +918,23 @@ ip_to_list(undefined) ->
 ip_to_list(IP) ->
     list_to_binary(inet_parse:ntoa(IP)).
 
+-spec hex_to_bin(binary()) -> binary().
+
+hex_to_bin(Hex) ->
+    hex_to_bin(binary_to_list(Hex), []).
+
+-spec hex_to_bin(list(), list()) -> binary().
+
+hex_to_bin([], Acc) ->
+    list_to_binary(lists:reverse(Acc));
+hex_to_bin([H1, H2 | T], Acc) ->
+    {ok, [V], []} = io_lib:fread("~16u", [H1, H2]),
+    hex_to_bin(T, [V | Acc]).
+
+-spec hex_to_base64(binary()) -> binary().
+
+hex_to_base64(Hex) -> encode_base64(hex_to_bin(Hex)).
+
 binary_to_atom(Bin) ->
     erlang:binary_to_atom(Bin, utf8).
 
index 34e8ac9e16eb1a51f26a706b114efd4f35a83a60..6131acab6ba5bf5dde77ae1a37b0f0cfad2a7d57 100644 (file)
@@ -113,9 +113,9 @@ 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 = jlib:encode_base64(proplists:get_value(<<"stored_key">>, Data, <<"">>)),
-               serverkey = jlib:encode_base64(proplists:get_value(<<"server_key">>, Data, <<"">>)),
-               salt = jlib:encode_base64(proplists:get_value(<<"salt">>, Data, <<"">>)),
+               storedkey = jlib:hex_to_base64(proplists:get_value(<<"stored_key">>, Data, <<"">>)),
+               serverkey = jlib:hex_to_base64(proplists:get_value(<<"server_key">>, Data, <<"">>)),
+               salt = jlib:hex_to_base64(proplists:get_value(<<"salt">>, Data, <<"">>)),
                iterationcount = round(IC)
            };
        _ -> <<"">>