aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Khramtsov <xramtsov@gmail.com>2017-03-21 15:44:29 +0400
committerGitHub <noreply@github.com>2017-03-21 15:44:29 +0400
commit44484fa4ae5f853da9e7c96a3d86823e03d93f27 (patch)
tree24e2b22bdf006b816497bc23c8ecfa66ac4660bf
parentReplace mod_http_bind by mod_bosh in config example (diff)
parentprosody2ejabberd: Fix SCRAM hash conversion (diff)
Merge pull request #1626 from weiss/fix-scram-import
prosody2ejabberd: Fix SCRAM hash conversion
-rw-r--r--src/jlib.erl18
-rw-r--r--src/prosody2ejabberd.erl6
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)
};
_ -> <<"">>