mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
Fix dialyzer errors
This commit is contained in:
parent
45f24c63cb
commit
c10f2a22b6
@ -362,16 +362,6 @@ process([<<"federation">>, <<"v2">>, <<"send_join">>, RoomID, EventID],
|
||||
case get_id_domain_exn(Sender) of
|
||||
Origin ->
|
||||
case mod_matrix_gw_room:send_join(Host, Origin, RoomID, EventID, JSON) of
|
||||
{error, room_not_found} ->
|
||||
Res = #{<<"errcode">> => <<"M_NOT_FOUND">>,
|
||||
<<"error">> => <<"Unknown room">>},
|
||||
{404, [{<<"Content-Type">>, <<"application/json;charset=UTF-8">>}],
|
||||
jiffy:encode(Res)};
|
||||
{error, not_invited} ->
|
||||
Res = #{<<"errcode">> => <<"M_FORBIDDEN">>,
|
||||
<<"error">> => <<"You are not invited to this room">>},
|
||||
{403, [{<<"Content-Type">>, <<"application/json;charset=UTF-8">>}],
|
||||
jiffy:encode(Res)};
|
||||
{error, Error} when is_binary(Error) ->
|
||||
Res = #{<<"errcode">> => <<"M_BAD_REQUEST">>,
|
||||
<<"error">> => Error},
|
||||
@ -733,13 +723,23 @@ sign_json(Host, JSON) ->
|
||||
Msg = encode_canonical_json(JSON2),
|
||||
SignatureName = mod_matrix_gw_opt:matrix_domain(Host),
|
||||
KeyName = mod_matrix_gw_opt:key_name(Host),
|
||||
{PubKey, PrivKey} = mod_matrix_gw_opt:key(Host),
|
||||
{_PubKey, PrivKey} = mod_matrix_gw_opt:key(Host),
|
||||
KeyID = <<"ed25519:", KeyName/binary>>,
|
||||
Sig = public_key:sign(Msg, ignored, {ed_pri, ed25519, PubKey, PrivKey}),
|
||||
Sig = crypto:sign(eddsa, none, Msg, [PrivKey, ed25519]),
|
||||
Sig64 = base64_encode(Sig),
|
||||
Signatures2 = Signatures#{SignatureName => #{KeyID => Sig64}},
|
||||
JSON#{<<"signatures">> => Signatures2}.
|
||||
|
||||
-spec send_request(
|
||||
binary(),
|
||||
get | post | put,
|
||||
binary(),
|
||||
[binary()],
|
||||
[{binary(), binary()}],
|
||||
none | jiffy:json_object(),
|
||||
[any()],
|
||||
[any()]) -> {ok, any()} | {error, any()}.
|
||||
|
||||
send_request(Host, Method, MatrixServer, Path, Query, JSON,
|
||||
HTTPOptions, Options) ->
|
||||
URI1 = iolist_to_binary(
|
||||
@ -751,13 +751,13 @@ send_request(Host, Method, MatrixServer, Path, Query, JSON,
|
||||
URI2 = str:join(
|
||||
lists:map(
|
||||
fun({K, V}) ->
|
||||
[uri_string:quote(K), $=, uri_string:quote(V)]
|
||||
iolist_to_binary(
|
||||
[uri_string:quote(K), $=,
|
||||
uri_string:quote(V)])
|
||||
end, Query), $&),
|
||||
<<URI1/binary, $?, URI2/binary>>
|
||||
end,
|
||||
% TODO
|
||||
{MHost, MPort} = mod_matrix_gw_s2s:get_matrix_host_port(Host, MatrixServer),
|
||||
%{MHost, MPort} = {MatrixServer, 8008},
|
||||
URL = <<"https://", MHost/binary,
|
||||
":", (integer_to_binary(MPort))/binary,
|
||||
URI/binary>>,
|
||||
|
@ -72,7 +72,7 @@
|
||||
|
||||
-record(data,
|
||||
{host :: binary(),
|
||||
local_user :: jid(),
|
||||
local_user :: jid() | undefined,
|
||||
remote_user :: binary() | undefined,
|
||||
remote_servers = #{},
|
||||
room_id :: binary(),
|
||||
@ -347,14 +347,7 @@ send_join(Host, Origin, RoomID, EventID, JSON) ->
|
||||
%% process to initialize.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
-spec init(Args :: term()) ->
|
||||
{gen_statem:callback_mode(),
|
||||
State :: term(), Data :: term()} |
|
||||
{gen_statem:callback_mode(),
|
||||
State :: term(), Data :: term(),
|
||||
[gen_statem:action()] | gen_statem:action()} |
|
||||
ignore |
|
||||
{stop, Reason :: term()}.
|
||||
-spec init(Args :: term()) -> gen_statem:init_result(term()).
|
||||
init([Host, RoomID]) ->
|
||||
mnesia:dirty_write(
|
||||
#matrix_room{room_id = RoomID,
|
||||
|
@ -216,14 +216,7 @@ check_signature(Host, JSON) ->
|
||||
%% process to initialize.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
-spec init(Args :: term()) ->
|
||||
{gen_statem:callback_mode(),
|
||||
State :: term(), Data :: term()} |
|
||||
{gen_statem:callback_mode(),
|
||||
State :: term(), Data :: term(),
|
||||
[gen_statem:action()] | gen_statem:action()} |
|
||||
ignore |
|
||||
{stop, Reason :: term()}.
|
||||
-spec init(Args :: term()) -> gen_statem:init_result(term()).
|
||||
init([Host, MatrixServer]) ->
|
||||
mnesia:dirty_write(
|
||||
#matrix_s2s{to = MatrixServer,
|
||||
@ -476,8 +469,9 @@ do_get_matrix_host_port(Data) ->
|
||||
"_matrix._tcp." ++ binary_to_list(MatrixServer),
|
||||
case inet_res:getbyname(SRVName, srv, 5000) of
|
||||
{ok, HostEntry} ->
|
||||
case h_addr_list_to_host_ports(
|
||||
HostEntry#hostent.h_addr_list) of
|
||||
{hostent, _Name, _Aliases, _AddrType, _Len,
|
||||
HAddrList} = HostEntry,
|
||||
case h_addr_list_to_host_ports(HAddrList) of
|
||||
{ok, [{Host, Port} | _]} ->
|
||||
{list_to_binary(Host), Port};
|
||||
_ ->
|
||||
@ -531,7 +525,7 @@ check_signature(JSON, SignatureName, KeyID, VerifyKey) ->
|
||||
Signature = mod_matrix_gw:base64_decode(SSignature),
|
||||
JSON2 = maps:without([<<"signatures">>, <<"unsigned">>], JSON),
|
||||
Msg = mod_matrix_gw:encode_canonical_json(JSON2),
|
||||
public_key:verify(Msg, ignored, Signature, {ed_pub, ed25519, VerifyKey})
|
||||
crypto:verify(eddsa, none, Msg, Signature, [VerifyKey, ed25519])
|
||||
catch
|
||||
_:_ ->
|
||||
false
|
||||
|
Loading…
Reference in New Issue
Block a user