From 8f84c33a1e1045eac4d9083446cb2a65f8295e53 Mon Sep 17 00:00:00 2001 From: Zhengji Li Date: Mon, 14 Oct 2019 11:11:37 +0800 Subject: [PATCH] compatability with OTP 22 (issue #5) `stream_state()` in crypto is no longer self contained. --- src/mimicsocks_wormhole_local.erl | 11 ++++++----- src/mimicsocks_wormhole_remote.erl | 7 +++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mimicsocks_wormhole_local.erl b/src/mimicsocks_wormhole_local.erl index 9234bb0..9e9245a 100644 --- a/src/mimicsocks_wormhole_local.erl +++ b/src/mimicsocks_wormhole_local.erl @@ -61,7 +61,9 @@ callback_mode() -> cmd_ref, ho_timer, - ho_buf = <<>> + ho_buf = <<>>, + + ping_timer } ). @@ -69,16 +71,15 @@ callback_mode() -> 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), @@ -319,4 +320,4 @@ gen_ivec() -> _ -> Q = 256 div rand:uniform(10), list_to_binary([(rand:uniform(Q) + T) rem 256 || _ <- L]) - end. \ No newline at end of file + end. diff --git a/src/mimicsocks_wormhole_remote.erl b/src/mimicsocks_wormhole_remote.erl index beb95fb..f9d9944 100644 --- a/src/mimicsocks_wormhole_remote.erl +++ b/src/mimicsocks_wormhole_remote.erl @@ -79,13 +79,12 @@ wait_ivec(cast, {local, Bin}, #state{buff = Buff, key = Key} = State) -> <> -> 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}, @@ -219,4 +218,4 @@ parse_cmds(<> = _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. \ No newline at end of file +-endif.