]> granicus.if.org Git - ejabberd/commitdiff
Get rid of p1_sha calls
authorAlexey Shchepin <alexey@process-one.net>
Mon, 13 Mar 2017 23:31:51 +0000 (02:31 +0300)
committerAlexey Shchepin <alexey@process-one.net>
Mon, 13 Mar 2017 23:31:51 +0000 (02:31 +0300)
16 files changed:
src/cyrsasl_digest.erl
src/ejabberd_bosh.erl
src/ejabberd_captcha.erl
src/ejabberd_config.erl
src/ejabberd_service.erl
src/mod_http_upload.erl
src/mod_legacy_auth.erl
src/mod_mix.erl
src/mod_muc.erl
src/mod_proxy65_service.erl
src/mod_roster.erl
src/mod_s2s_dialback.erl
src/mod_sip_proxy.erl
src/mod_vcard_xupdate.erl
src/str.erl
src/xmpp_stream_in.erl

index a91566b66f927da16fead460c63e380abb8055f3..eedb5366c8bb2f9ca62a16667634bd11f7d7c013 100644 (file)
@@ -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
index 204c7b6e58e519da0112cf18cac68bf887873b7d..ad1dcfd5fea989d7f30737dcbd7f8afc04b9a855 100644 (file)
@@ -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}]}).
 
index 9d0835bf2b371fa7bda26c39144c09d37b400f1d..0a1e1a9ebdc25a98df3cb19bc1100d98a4ce3a9c 100644 (file)
@@ -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, "
index 720e4cafa8b6ce7a71ba4dec2dc122467fbbf44f..74c180728e41346d3ac97d2398a751d7786fee4d 100644 (file)
@@ -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),
index 16cdf5ca9a63b75c827adfc8b7a81343fcf7d1b2..716606b4c2965a8eed861d5d0bf88e5a8ac46843 100644 (file)
@@ -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,
index 9fdd34381c30475e15130a1f490f1569e0f7f5f1..59570b0b5c339472584db0ab2ef7b1614a4154c0 100644 (file)
@@ -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}]).
 
index 49e210ec6f12e56c82003fa2d6f0e9d8965fb938..5a4ff91081990750e20727fb04b83d409409b897 100644 (file)
@@ -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,
index 940e9898fda86a717cfe991c7b3fc8a89f8e80b9..714a6b0200aaa1eb026d6f458fd9483b3d9bf3e0 100644 (file)
@@ -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).
 
index 563f4c68a65a003af4f62a8094b3ae28c7b62da9..f9488cf9a8af7df668a1020def0a63401761040a 100644 (file)
@@ -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}).
 
index 58aee60cace712a59a7f7a23c7246d669d853e18..dd58b4a3aafa6be2d0095153b791ea132023b36b 100644 (file)
@@ -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
index 5f499ec747992aa03b98c669ec63a99166b7a215..cf281528a14cd27f6ec47f6de73bd96254d2b61c 100644 (file)
@@ -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.
index 4d9ae1af28b07ba600e6bc40016563386d762060..f457284854784cb734cd59f2ab91d6a5fa66cf36 100644 (file)
@@ -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().
index 08c90c23d75d3f48f71d8ebc9cec371e9e251649..b57e431d683b08afb254853330f81b14d3631b59 100644 (file)
@@ -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) ->
index 2a754d408ce0384751d1bf6eff8835325088a8fa..4c9c0b71a031307c474a553616f470c579cf3ecd 100644 (file)
@@ -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).
 
index 28537da0fbaf1ee769e3541c72f63c6416691bdb..0b30be3331760142edcd37438283a53f2ced7411 100644 (file)
@@ -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.
index 54168261e3067974cbe28e97f3f44442ed60a757..b781bdf146cbc206133acd99bce541b900556e2d 100644 (file)
@@ -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 ->