Add padding for outgoing upstream traffic in secure mode

parent ad394a2a
......@@ -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).
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment