25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Get rid of compile warnings for random/crypto modules on R19

This commit is contained in:
Evgeniy Khramtsov 2016-10-18 08:17:21 +03:00
parent 90acec8a2b
commit 4c5460f0bd
11 changed files with 29 additions and 17 deletions

View File

@ -71,6 +71,7 @@
{if_var_match, db_type, mssql, {d, 'mssql'}}, {if_var_match, db_type, mssql, {d, 'mssql'}},
{if_var_true, elixir, {d, 'ELIXIR_ENABLED'}}, {if_var_true, elixir, {d, 'ELIXIR_ENABLED'}},
{if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}}, {if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}},
{if_version_above, "18", {d, 'STRONG_RAND_BYTES'}},
{if_var_true, hipe, native}, {if_var_true, hipe, native},
{src_dirs, [asn1, src, {src_dirs, [asn1, src,
{if_var_true, tools, tools}, {if_var_true, tools, tools},

View File

@ -87,7 +87,7 @@ mech_step(#state{step = 2} = State, ClientIn) ->
if is_tuple(Ret) -> Ret; if is_tuple(Ret) -> Ret;
true -> true ->
TempSalt = TempSalt =
crypto:rand_bytes(?SALT_LENGTH), randoms:bytes(?SALT_LENGTH),
SaltedPassword = SaltedPassword =
scram:salted_password(Ret, scram:salted_password(Ret,
TempSalt, TempSalt,
@ -101,7 +101,7 @@ mech_step(#state{step = 2} = State, ClientIn) ->
str:substr(ClientIn, str:substr(ClientIn,
str:str(ClientIn, <<"n=">>)), str:str(ClientIn, <<"n=">>)),
ServerNonce = ServerNonce =
jlib:encode_base64(crypto:rand_bytes(?NONCE_LENGTH)), jlib:encode_base64(randoms:bytes(?NONCE_LENGTH)),
ServerFirstMessage = ServerFirstMessage =
iolist_to_binary( iolist_to_binary(
["r=", ["r=",

View File

@ -105,8 +105,6 @@ start_app([], _Type, _StartFlag) ->
ok. ok.
check_app_modules(App, StartFlag) -> check_app_modules(App, StartFlag) ->
{A, B, C} = p1_time_compat:timestamp(),
random:seed(A, B, C),
sleep(5000), sleep(5000),
case application:get_key(App, modules) of case application:get_key(App, modules) of
{ok, Mods} -> {ok, Mods} ->
@ -140,7 +138,7 @@ exit_or_halt(Reason, StartFlag) ->
end. end.
sleep(N) -> sleep(N) ->
timer:sleep(random:uniform(N)). timer:sleep(randoms:uniform(N)).
get_module_file(App, Mod) -> get_module_file(App, Mod) ->
BaseName = atom_to_list(Mod), BaseName = atom_to_list(Mod),

View File

@ -450,7 +450,7 @@ password_to_scram(Password) ->
?SCRAM_DEFAULT_ITERATION_COUNT). ?SCRAM_DEFAULT_ITERATION_COUNT).
password_to_scram(Password, IterationCount) -> password_to_scram(Password, IterationCount) ->
Salt = crypto:rand_bytes(?SALT_LENGTH), Salt = randoms:bytes(?SALT_LENGTH),
SaltedPassword = scram:salted_password(Password, Salt, SaltedPassword = scram:salted_password(Password, Salt,
IterationCount), IterationCount),
StoredKey = StoredKey =

View File

@ -270,7 +270,7 @@ password_to_scram(Password) ->
?SCRAM_DEFAULT_ITERATION_COUNT). ?SCRAM_DEFAULT_ITERATION_COUNT).
password_to_scram(Password, IterationCount) -> password_to_scram(Password, IterationCount) ->
Salt = crypto:rand_bytes(?SALT_LENGTH), Salt = randoms:bytes(?SALT_LENGTH),
SaltedPassword = scram:salted_password(Password, Salt, SaltedPassword = scram:salted_password(Password, Salt,
IterationCount), IterationCount),
StoredKey = StoredKey =

View File

@ -406,7 +406,7 @@ password_to_scram(Password) ->
?SCRAM_DEFAULT_ITERATION_COUNT). ?SCRAM_DEFAULT_ITERATION_COUNT).
password_to_scram(Password, IterationCount) -> password_to_scram(Password, IterationCount) ->
Salt = crypto:rand_bytes(?SALT_LENGTH), Salt = randoms:bytes(?SALT_LENGTH),
SaltedPassword = scram:salted_password(Password, Salt, SaltedPassword = scram:salted_password(Password, Salt,
IterationCount), IterationCount),
StoredKey = StoredKey =

View File

@ -1099,13 +1099,12 @@ get_addr_port(Server) ->
?DEBUG("srv lookup of '~s': ~p~n", ?DEBUG("srv lookup of '~s': ~p~n",
[Server, HEnt#hostent.h_addr_list]), [Server, HEnt#hostent.h_addr_list]),
AddrList = HEnt#hostent.h_addr_list, AddrList = HEnt#hostent.h_addr_list,
random:seed(p1_time_compat:timestamp()),
case catch lists:map(fun ({Priority, Weight, Port, case catch lists:map(fun ({Priority, Weight, Port,
Host}) -> Host}) ->
N = case Weight of N = case Weight of
0 -> 0; 0 -> 0;
_ -> _ ->
(Weight + 1) * random:uniform() (Weight + 1) * randoms:uniform()
end, end,
{Priority * 65536 - N, Host, Port} {Priority * 65536 - N, Host, Port}
end, end,

View File

@ -135,13 +135,13 @@ init([{SockMod, Socket}, Opts]) ->
fun({H, Os}, D) -> fun({H, Os}, D) ->
P = proplists:get_value( P = proplists:get_value(
password, Os, password, Os,
p1_sha:sha(crypto:rand_bytes(20))), p1_sha:sha(randoms:bytes(20))),
dict:store(H, P, D) dict:store(H, P, D)
end, dict:new(), HOpts); end, dict:new(), HOpts);
false -> false ->
Pass = proplists:get_value( Pass = proplists:get_value(
password, Opts, password, Opts,
p1_sha:sha(crypto:rand_bytes(20))), p1_sha:sha(randoms:bytes(20))),
dict:from_list([{global, Pass}]) dict:from_list([{global, Pass}])
end, end,
%% privilege access to entities data %% privilege access to entities data

View File

@ -102,8 +102,7 @@ call_port(Server, Msg) ->
receive {eauth, Result} -> Result end. receive {eauth, Result} -> Result end.
random_instance(MaxNum) -> random_instance(MaxNum) ->
random:seed(p1_time_compat:timestamp()), randoms:uniform(MaxNum) - 1.
random:uniform(MaxNum) - 1.
get_instances(Server) -> get_instances(Server) ->
ejabberd_config:get_option( ejabberd_config:get_option(

View File

@ -172,7 +172,7 @@ do_client_version(disabled, _From, _To) -> ok;
do_client_version(enabled, From, To) -> do_client_version(enabled, From, To) ->
ToS = jid:to_string(To), ToS = jid:to_string(To),
Random_resource = Random_resource =
iolist_to_binary(integer_to_list(random:uniform(100000))), iolist_to_binary(integer_to_list(randoms:uniform(100000))),
From2 = From#jid{resource = Random_resource, From2 = From#jid{resource = Random_resource,
lresource = Random_resource}, lresource = Random_resource},
Packet = #xmlel{name = <<"iq">>, Packet = #xmlel{name = <<"iq">>,

View File

@ -27,14 +27,29 @@
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-export([get_string/0]). -export([get_string/0, uniform/0, uniform/1, bytes/1]).
-export([start/0]). -export([start/0]).
-define(THRESHOLD, 16#10000000000000000).
start() -> start() ->
ok. ok.
get_string() -> get_string() ->
R = crypto:rand_uniform(0, 16#10000000000000000), R = crypto:rand_uniform(0, ?THRESHOLD),
jlib:integer_to_binary(R). jlib:integer_to_binary(R).
uniform() ->
crypto:rand_uniform(0, ?THRESHOLD)/?THRESHOLD.
uniform(N) ->
crypto:rand_uniform(0, N).
-ifdef(STRONG_RAND_BYTES).
bytes(N) ->
crypto:strong_rand_bytes(N).
-else.
bytes(N) ->
crypto:rand_bytes(N).
-endif.