Skip to content

Commit

Permalink
compatability with OTP 22 (issue #5)
Browse files Browse the repository at this point in the history
`stream_state()` in crypto is no longer self contained.
  • Loading branch information
foldl committed Oct 14, 2019
1 parent 3f4858b commit 8f84c33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/mimicsocks_wormhole_local.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,25 @@ callback_mode() ->

cmd_ref,
ho_timer,
ho_buf = <<>>
ho_buf = <<>>,

ping_timer
}
).

%% callback funcitons
init([UpStream, ServerAddr, ServerPort, OtherPorts, Key | T]) ->
process_flag(trap_exit, true),
IVec = gen_ivec(),
Cipher = crypto:stream_init(aes_ctr, Key, IVec),
ID0 = next_id(Key, IVec),
HOID = next_id(Key, ID0),

RecvSink = mimicsocks_inband_recv:start_link([self(), self()]),
mimicsocks_inband_recv:set_key(RecvSink, Key),
Recv = mimicsocks_crypt:start_link(decrypt, [RecvSink, Cipher]),
Recv = mimicsocks_crypt:start_link(decrypt, [RecvSink, crypto:stream_init(aes_ctr, Key, IVec)]),

{ok, SendSink} = mimicsocks_mimic:start_link([self(), identity, identity, iir]),
SendEncrypt = mimicsocks_crypt:start_link(encrypt, [SendSink, Cipher]),
SendEncrypt = mimicsocks_crypt:start_link(encrypt, [SendSink, crypto:stream_init(aes_ctr, Key, IVec)]),
Send = mimicsocks_inband_send:start_link([SendEncrypt, self()]),
mimicsocks_inband_send:set_key(Send, Key),

Expand Down Expand Up @@ -319,4 +320,4 @@ gen_ivec() ->
_ ->
Q = 256 div rand:uniform(10),
list_to_binary([(rand:uniform(Q) + T) rem 256 || _ <- L])
end.
end.
7 changes: 3 additions & 4 deletions src/mimicsocks_wormhole_remote.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ wait_ivec(cast, {local, Bin}, #state{buff = Buff, key = Key} = State) ->
<<IVec:?MIMICSOCKS_HELLO_SIZE/binary, ID0:?MIMICSOCKS_HELLO_SIZE/binary, Rem/binary>> ->
case next_id(Key, IVec) of
ID0 ->
Cipher = crypto:stream_init(aes_ctr, Key, IVec),
RecvSink = mimicsocks_inband_recv:start_link([self(), self()]),
mimicsocks_inband_recv:set_key(RecvSink, Key),
Recv = mimicsocks_crypt:start_link(decrypt, [RecvSink, Cipher]),
Recv = mimicsocks_crypt:start_link(decrypt, [RecvSink, crypto:stream_init(aes_ctr, Key, IVec)]),

{ok, SendSink} = mimicsocks_mimic:start_link([self()]),
SendCrypt = mimicsocks_crypt:start_link(encrypt, [SendSink, Cipher]),
SendCrypt = mimicsocks_crypt:start_link(encrypt, [SendSink, crypto:stream_init(aes_ctr, Key, IVec)]),
Send = mimicsocks_inband_send:start_link([SendCrypt, self()]),
mimicsocks_inband_send:set_key(Send, Key),
Recv ! {recv, self(), Rem},
Expand Down Expand Up @@ -219,4 +218,4 @@ parse_cmds(<<?MIMICSOCKS_INBAND_HO_COMPLETE_L2R, Rem/binary>> = _Cmds, Pid) ->
create_close_timer() -> timer:send_after(100, close).
-else.
create_close_timer() -> timer:send_after((rand:uniform(50) + 1) * 60 * 1000, close).
-endif.
-endif.

0 comments on commit 8f84c33

Please sign in to comment.