diff options
author | Holger Weiss <holger@zedat.fu-berlin.de> | 2017-03-16 23:15:08 +0100 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2017-03-16 23:15:08 +0100 |
commit | 0ef6973457da0a6d9c85344c1b26241ea5b77954 (patch) | |
tree | 078b28bb1bc5cbcecf7ac2659b210c64be792c0a | |
parent | Encode in base64 when getting scram data with import_prosody (#1549) (diff) |
prosody2ejabberd: Fix SCRAM hash conversion
Closes #1549.
-rw-r--r-- | src/jlib.erl | 18 | ||||
-rw-r--r-- | src/prosody2ejabberd.erl | 6 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/jlib.erl b/src/jlib.erl index 580ad1ffa..6913542f9 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -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). diff --git a/src/prosody2ejabberd.erl b/src/prosody2ejabberd.erl index 34e8ac9e1..6131acab6 100644 --- a/src/prosody2ejabberd.erl +++ b/src/prosody2ejabberd.erl @@ -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) }; _ -> <<"">> |