summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2017-03-14 02:31:51 +0300
committerAlexey Shchepin <alexey@process-one.net>2017-03-14 02:31:51 +0300
commit069d28b1eda5384a67fa5fb2ac14b7cdc86eec31 (patch)
treec5c7b26c6703746ae128eccae264ead5a3d44ff2 /src
parentFix handling of xmlrpc request without authentication structure (diff)
Get rid of p1_sha calls
Diffstat (limited to 'src')
-rw-r--r--src/cyrsasl_digest.erl2
-rw-r--r--src/ejabberd_bosh.erl4
-rw-r--r--src/ejabberd_captcha.erl4
-rw-r--r--src/ejabberd_config.erl4
-rw-r--r--src/ejabberd_service.erl4
-rw-r--r--src/mod_http_upload.erl2
-rw-r--r--src/mod_legacy_auth.erl2
-rw-r--r--src/mod_mix.erl4
-rw-r--r--src/mod_muc.erl2
-rw-r--r--src/mod_proxy65_service.erl2
-rw-r--r--src/mod_roster.erl4
-rw-r--r--src/mod_s2s_dialback.erl4
-rw-r--r--src/mod_sip_proxy.erl2
-rw-r--r--src/mod_vcard_xupdate.erl2
-rw-r--r--src/str.erl21
-rw-r--r--src/xmpp_stream_in.erl2
16 files changed, 42 insertions, 23 deletions
diff --git a/src/cyrsasl_digest.erl b/src/cyrsasl_digest.erl
index a91566b6..eedb5366 100644
--- a/src/cyrsasl_digest.erl
+++ b/src/cyrsasl_digest.erl
@@ -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
diff --git a/src/ejabberd_bosh.erl b/src/ejabberd_bosh.erl
index 204c7b6e..ad1dcfd5 100644
--- a/src/ejabberd_bosh.erl
+++ b/src/ejabberd_bosh.erl
@@ -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}]}).
diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl
index 9d0835bf..0a1e1a9e 100644
--- a/src/ejabberd_captcha.erl
+++ b/src/ejabberd_captcha.erl
@@ -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, "
diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl
index 720e4caf..74c18072 100644
--- a/src/ejabberd_config.erl
+++ b/src/ejabberd_config.erl
@@ -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),
diff --git a/src/ejabberd_service.erl b/src/ejabberd_service.erl
index 16cdf5ca..716606b4 100644
--- a/src/ejabberd_service.erl
+++ b/src/ejabberd_service.erl
@@ -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,
diff --git a/src/mod_http_upload.erl b/src/mod_http_upload.erl
index 9fdd3438..59570b0b 100644
--- a/src/mod_http_upload.erl
+++ b/src/mod_http_upload.erl
@@ -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}]).
diff --git a/src/mod_legacy_auth.erl b/src/mod_legacy_auth.erl
index 49e210ec..5a4ff910 100644
--- a/src/mod_legacy_auth.erl
+++ b/src/mod_legacy_auth.erl
@@ -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,
diff --git a/src/mod_mix.erl b/src/mod_mix.erl
index 940e9898..714a6b02 100644
--- a/src/mod_mix.erl
+++ b/src/mod_mix.erl
@@ -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).
diff --git a/src/mod_muc.erl b/src/mod_muc.erl
index 563f4c68..f9488cf9 100644
--- a/src/mod_muc.erl
+++ b/src/mod_muc.erl
@@ -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}).
diff --git a/src/mod_proxy65_service.erl b/src/mod_proxy65_service.erl
index 58aee60c..dd58b4a3 100644
--- a/src/mod_proxy65_service.erl
+++ b/src/mod_proxy65_service.erl
@@ -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
diff --git a/src/mod_roster.erl b/src/mod_roster.erl
index 5f499ec7..cf281528 100644
--- a/src/mod_roster.erl
+++ b/src/mod_roster.erl
@@ -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.
diff --git a/src/mod_s2s_dialback.erl b/src/mod_s2s_dialback.erl
index 4d9ae1af..f4572848 100644
--- a/src/mod_s2s_dialback.erl
+++ b/src/mod_s2s_dialback.erl
@@ -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().
diff --git a/src/mod_sip_proxy.erl b/src/mod_sip_proxy.erl
index 08c90c23..b57e431d 100644
--- a/src/mod_sip_proxy.erl
+++ b/src/mod_sip_proxy.erl
@@ -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) ->
diff --git a/src/mod_vcard_xupdate.erl b/src/mod_vcard_xupdate.erl
index 2a754d40..4c9c0b71 100644
--- a/src/mod_vcard_xupdate.erl
+++ b/src/mod_vcard_xupdate.erl
@@ -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).
diff --git a/src/str.erl b/src/str.erl
index 28537da0..0b30be33 100644
--- a/src/str.erl
+++ b/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.
diff --git a/src/xmpp_stream_in.erl b/src/xmpp_stream_in.erl
index 54168261..b781bdf1 100644
--- a/src/xmpp_stream_in.erl
+++ b/src/xmpp_stream_in.erl
@@ -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 ->