mirror of
https://github.com/seriyps/mtproto_proxy.git
synced 2026-08-04 15:19:47 +00:00
Add padding for outgoing upstream traffic in secure mode
This commit is contained in:
parent
ad394a2aa8
commit
4eab3caa66
2 changed files with 9 additions and 2 deletions
|
|
@ -64,7 +64,13 @@ try_decode_packet_len(Len, Data, #int_st{padding = Pad} = St) ->
|
|||
end.
|
||||
|
||||
-spec encode_packet(iodata(), codec()) -> iodata().
|
||||
encode_packet(Data, St) ->
|
||||
encode_packet(Data, #int_st{padding = Pad} = St) ->
|
||||
Size = iolist_size(Data),
|
||||
Packet = [<<Size:32/little>> | Data],
|
||||
Packet = case Pad of
|
||||
false -> [<<Size:32/little>> | Data];
|
||||
true ->
|
||||
PadSize = rand:uniform(4) - 1,
|
||||
Padding = crypto:strong_rand_bytes(PadSize), % 0 is ok
|
||||
[<<(Size + PadSize):32/little>>, Data | Padding]
|
||||
end,
|
||||
{Packet, St}.
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
-define(FLAG_HAS_AD_TAG , 16#8).
|
||||
-define(FLAG_MAGIC , 16#1000).
|
||||
-define(FLAG_EXTMODE2 , 16#20000).
|
||||
-define(FLAG_PAD , 16#8000000). %TODO: use it
|
||||
-define(FLAG_INTERMEDIATE , 16#20000000).
|
||||
-define(FLAG_ABRIDGED , 16#40000000).
|
||||
-define(FLAG_QUICKACK , 16#80000000).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue