mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Get rid of p1_sha calls
This commit is contained in:
parent
301b1b7a7a
commit
069d28b1ed
@ -237,7 +237,7 @@ get_local_fqdn2() ->
|
||||
end.
|
||||
|
||||
hex(S) ->
|
||||
p1_sha:to_hexlist(S).
|
||||
str:to_hexlist(S).
|
||||
|
||||
proplists_get_bin_value(Key, Pairs, Default) ->
|
||||
case proplists:get_value(Key, Pairs, Default) of
|
||||
|
@ -773,7 +773,7 @@ bounce_els_from_obuf(State) ->
|
||||
|
||||
is_valid_key(<<"">>, <<"">>) -> true;
|
||||
is_valid_key(PrevKey, Key) ->
|
||||
p1_sha:sha(Key) == PrevKey.
|
||||
str:sha(Key) == PrevKey.
|
||||
|
||||
is_overactivity(undefined) -> false;
|
||||
is_overactivity(PrevPoll) ->
|
||||
@ -999,7 +999,7 @@ http_error(Status, Reason, Type) ->
|
||||
end,
|
||||
{Status, Reason, ?HEADER(CType), <<"">>}.
|
||||
|
||||
make_sid() -> p1_sha:sha(randoms:get_string()).
|
||||
make_sid() -> str:sha(randoms:get_string()).
|
||||
|
||||
-compile({no_auto_import, [{min, 2}]}).
|
||||
|
||||
|
@ -90,7 +90,7 @@ create_captcha(SID, From, To, Lang, Limiter, Args) ->
|
||||
{ok, Type, Key, Image} ->
|
||||
Id = <<(randoms:get_string())/binary>>,
|
||||
JID = jid:encode(From),
|
||||
CID = <<"sha1+", (p1_sha:sha(Image))/binary, "@bob.xmpp.org">>,
|
||||
CID = <<"sha1+", (str:sha(Image))/binary, "@bob.xmpp.org">>,
|
||||
Data = #bob_data{cid = CID, 'max-age' = 0, type = Type,
|
||||
data = Image},
|
||||
Fs = [mk_field(hidden, <<"FORM_TYPE">>, ?NS_CAPTCHA),
|
||||
@ -120,7 +120,7 @@ create_captcha_x(SID, To, Lang, Limiter, #xdata{fields = Fs} = X) ->
|
||||
case create_image(Limiter) of
|
||||
{ok, Type, Key, Image} ->
|
||||
Id = <<(randoms:get_string())/binary>>,
|
||||
CID = <<"sha1+", (p1_sha:sha(Image))/binary, "@bob.xmpp.org">>,
|
||||
CID = <<"sha1+", (str:sha(Image))/binary, "@bob.xmpp.org">>,
|
||||
Data = #bob_data{cid = CID, 'max-age' = 0, type = Type, data = Image},
|
||||
HelpTxt = translate:translate(Lang,
|
||||
<<"If you don't see the CAPTCHA image here, "
|
||||
|
@ -71,9 +71,9 @@ start() ->
|
||||
UnixTime = p1_time_compat:system_time(seconds),
|
||||
SharedKey = case erlang:get_cookie() of
|
||||
nocookie ->
|
||||
p1_sha:sha(randoms:get_string());
|
||||
str:sha(randoms:get_string());
|
||||
Cookie ->
|
||||
p1_sha:sha(jlib:atom_to_binary(Cookie))
|
||||
str:sha(jlib:atom_to_binary(Cookie))
|
||||
end,
|
||||
State2 = set_option({node_start, global}, UnixTime, State1),
|
||||
State3 = set_option({shared_key, global}, SharedKey, State2),
|
||||
|
@ -78,13 +78,13 @@ init([State, Opts]) ->
|
||||
fun({H, Os}, D) ->
|
||||
P = proplists:get_value(
|
||||
password, Os,
|
||||
p1_sha:sha(randoms:bytes(20))),
|
||||
str:sha(randoms:bytes(20))),
|
||||
dict:store(H, P, D)
|
||||
end, dict:new(), HOpts);
|
||||
false ->
|
||||
Pass = proplists:get_value(
|
||||
password, Opts,
|
||||
p1_sha:sha(randoms:bytes(20))),
|
||||
str:sha(randoms:bytes(20))),
|
||||
dict:from_list([{global, Pass}])
|
||||
end,
|
||||
CheckFrom = gen_mod:get_opt(check_from, Opts,
|
||||
|
@ -669,7 +669,7 @@ mk_slot(PutURL, GetURL, XMLNS) ->
|
||||
-spec make_user_string(jid(), sha1 | node) -> binary().
|
||||
|
||||
make_user_string(#jid{luser = U, lserver = S}, sha1) ->
|
||||
p1_sha:sha(<<U/binary, $@, S/binary>>);
|
||||
str:sha(<<U/binary, $@, S/binary>>);
|
||||
make_user_string(#jid{luser = U}, node) ->
|
||||
re:replace(U, <<"[^a-zA-Z0-9_.-]">>, <<$_>>, [global, {return, binary}]).
|
||||
|
||||
|
@ -111,7 +111,7 @@ authenticate(#{stream_id := StreamID, server := Server,
|
||||
resource = R}]} = IQ) ->
|
||||
P = if is_binary(P0) -> P0; true -> <<>> end,
|
||||
D = if is_binary(D0) -> D0; true -> <<>> end,
|
||||
DGen = fun (PW) -> p1_sha:sha(<<StreamID/binary, PW/binary>>) end,
|
||||
DGen = fun (PW) -> str:sha(<<StreamID/binary, PW/binary>>) end,
|
||||
JID = jid:make(U, Server, R),
|
||||
case JID /= error andalso
|
||||
acl:access_matches(Access,
|
||||
|
@ -261,7 +261,7 @@ publish_participant(From, To) ->
|
||||
LFrom = jid:tolower(BareFrom),
|
||||
LTo = jid:tolower(jid:remove_resource(To)),
|
||||
Participant = #mix_participant{jid = BareFrom},
|
||||
ItemID = p1_sha:sha(jid:encode(LFrom)),
|
||||
ItemID = str:sha(jid:encode(LFrom)),
|
||||
mod_pubsub:publish_item(
|
||||
LTo, To#jid.lserver, ?NS_MIX_NODES_PARTICIPANTS,
|
||||
From, ItemID, [xmpp:encode(Participant)]).
|
||||
@ -284,7 +284,7 @@ delete_presence(From, To) ->
|
||||
|
||||
delete_participant(From, To) ->
|
||||
LFrom = jid:tolower(jid:remove_resource(From)),
|
||||
ItemID = p1_sha:sha(jid:encode(LFrom)),
|
||||
ItemID = str:sha(jid:encode(LFrom)),
|
||||
delete_presence(From, To),
|
||||
delete_item(From, To, ?NS_MIX_NODES_PARTICIPANTS, ItemID).
|
||||
|
||||
|
@ -609,7 +609,7 @@ process_muc_unique(#iq{type = set, lang = Lang} = IQ) ->
|
||||
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
||||
process_muc_unique(#iq{from = From, type = get,
|
||||
sub_els = [#muc_unique{}]} = IQ) ->
|
||||
Name = p1_sha:sha(term_to_binary([From, p1_time_compat:timestamp(),
|
||||
Name = str:sha(term_to_binary([From, p1_time_compat:timestamp(),
|
||||
randoms:get_string()])),
|
||||
xmpp:make_iq_result(IQ, #muc_unique{name = Name}).
|
||||
|
||||
|
@ -217,7 +217,7 @@ process_bytestreams(#iq{type = set, lang = Lang, from = InitiatorJID, to = To,
|
||||
Node = ejabberd_cluster:get_node_by_id(To#jid.lresource),
|
||||
Target = jid:encode(jid:tolower(TargetJID)),
|
||||
Initiator = jid:encode(jid:tolower(InitiatorJID)),
|
||||
SHA1 = p1_sha:sha(<<SID/binary, Initiator/binary, Target/binary>>),
|
||||
SHA1 = str:sha(<<SID/binary, Initiator/binary, Target/binary>>),
|
||||
Mod = gen_mod:ram_db_mod(global, mod_proxy65),
|
||||
MaxConnections = max_connections(ServerHost),
|
||||
case Mod:activate_stream(SHA1, Initiator, MaxConnections, Node) of
|
||||
|
@ -216,7 +216,7 @@ process_local_iq(#iq{lang = Lang} = IQ) ->
|
||||
xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
|
||||
|
||||
roster_hash(Items) ->
|
||||
p1_sha:sha(term_to_binary(lists:sort([R#roster{groups =
|
||||
str:sha(term_to_binary(lists:sort([R#roster{groups =
|
||||
lists:sort(Grs)}
|
||||
|| R = #roster{groups = Grs}
|
||||
<- Items]))).
|
||||
@ -270,7 +270,7 @@ write_roster_version_t(LUser, LServer) ->
|
||||
write_roster_version(LUser, LServer, true).
|
||||
|
||||
write_roster_version(LUser, LServer, InTransaction) ->
|
||||
Ver = p1_sha:sha(term_to_binary(p1_time_compat:unique_integer())),
|
||||
Ver = str:sha(term_to_binary(p1_time_compat:unique_integer())),
|
||||
Mod = gen_mod:db_mod(LServer, ?MODULE),
|
||||
Mod:write_roster_version(LUser, LServer, InTransaction, Ver),
|
||||
Ver.
|
||||
|
@ -266,8 +266,8 @@ s2s_out_packet(State, _) ->
|
||||
-spec make_key(binary(), binary(), binary()) -> binary().
|
||||
make_key(From, To, StreamID) ->
|
||||
Secret = ejabberd_config:get_option(shared_key, fun(V) -> V end),
|
||||
p1_sha:to_hexlist(
|
||||
crypto:hmac(sha256, p1_sha:to_hexlist(crypto:hash(sha256, Secret)),
|
||||
str:to_hexlist(
|
||||
crypto:hmac(sha256, str:to_hexlist(crypto:hash(sha256, Secret)),
|
||||
[To, " ", From, " ", StreamID])).
|
||||
|
||||
-spec send_verify_request(ejabberd_s2s_out:state()) -> ejabberd_s2s_out:state().
|
||||
|
@ -332,7 +332,7 @@ make_sign(TS, Hdrs) ->
|
||||
FromTag = esip:get_param(<<"tag">>, FParams),
|
||||
CallID = esip:get_hdr('call-id', Hdrs),
|
||||
SharedKey = ejabberd_config:get_option(shared_key, fun(V) -> V end),
|
||||
p1_sha:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
|
||||
str:sha([SharedKey, LFUser, LFServer, LTUser, LTServer,
|
||||
FromTag, CallID, TS]).
|
||||
|
||||
is_signed_by_me(TS_Sign, Hdrs) ->
|
||||
|
@ -99,7 +99,7 @@ vcard_set(LUser, LServer, VCARD) ->
|
||||
<<>> -> remove_xupdate(LUser, LServer);
|
||||
BinVal ->
|
||||
add_xupdate(LUser, LServer,
|
||||
p1_sha:sha(jlib:decode_base64(BinVal)))
|
||||
str:sha(jlib:decode_base64(BinVal)))
|
||||
end,
|
||||
ejabberd_sm:force_update_presence(US).
|
||||
|
||||
|
21
src/str.erl
21
src/str.erl
@ -65,7 +65,9 @@
|
||||
prefix/2,
|
||||
suffix/2,
|
||||
format/2,
|
||||
to_integer/1]).
|
||||
to_integer/1,
|
||||
sha/1,
|
||||
to_hexlist/1]).
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
@ -286,6 +288,20 @@ suffix(B1, B2) ->
|
||||
format(Format, Args) ->
|
||||
iolist_to_binary(io_lib:format(Format, Args)).
|
||||
|
||||
|
||||
-spec sha(binary()) -> binary().
|
||||
|
||||
sha(Text) ->
|
||||
Bin = crypto:hash(sha, Text),
|
||||
to_hexlist(Bin).
|
||||
|
||||
-spec to_hexlist(binary()) -> binary().
|
||||
|
||||
to_hexlist(S) when is_list(S) ->
|
||||
to_hexlist(iolist_to_binary(S));
|
||||
to_hexlist(Bin) when is_binary(Bin) ->
|
||||
<< <<(digit_to_xchar(N div 16)), (digit_to_xchar(N rem 16))>> || <<N>> <= Bin >>.
|
||||
|
||||
%%%===================================================================
|
||||
%%% Internal functions
|
||||
%%%===================================================================
|
||||
@ -293,3 +309,6 @@ join_s([], _Sep) ->
|
||||
[];
|
||||
join_s([H|T], Sep) ->
|
||||
[H, [[Sep, X] || X <- T]].
|
||||
|
||||
digit_to_xchar(D) when (D >= 0) and (D < 10) -> D + $0;
|
||||
digit_to_xchar(D) -> D + $a - 10.
|
||||
|
@ -636,7 +636,7 @@ process_handshake(#handshake{data = Digest},
|
||||
{false, _} ->
|
||||
false;
|
||||
{Password, _} ->
|
||||
p1_sha:sha(<<StreamID/binary, Password/binary>>) == Digest
|
||||
str:sha(<<StreamID/binary, Password/binary>>) == Digest
|
||||
end,
|
||||
case AuthRes of
|
||||
true ->
|
||||
|
Loading…
Reference in New Issue
Block a user