Skip to content

Commit 8e28676

Browse files
committed
Fix bug in previous commit (early tls error detection)
1 parent 2eb3fed commit 8e28676

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/mtp_handler.erl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,20 @@ parse_upstream_data(<<Header:64/binary, Rest/binary>>,
327327
#state{stage = init, secret = Secret, listener = Listener, codec = Codec0,
328328
ad_tag = Tag, addr = {Ip, _} = Addr, policy_state = PState0,
329329
sock = Sock, transport = Transport} = S) ->
330+
{TlsHandshakeDone, _} = mtp_codec:info(tls, Codec0),
330331
AllowedProtocols = allowed_protocols(),
331-
(not is_tls_only(AllowedProtocols)) orelse
332+
%% If the only enabled protocol is fake-tls and tls handshake haven't been performed yet - raise
333+
%% protocol error.
334+
(is_tls_only(AllowedProtocols) andalso not TlsHandshakeDone) andalso
332335
error({protocol_error, tls_client_hello_expected, Header}),
333336
case mtp_obfuscated:from_header(Header, Secret) of
334337
{ok, DcId, PacketLayerMod, CryptoCodecSt} ->
335338
maybe_check_replay(Header),
336339
{ProtoToReport, PState} =
337-
case mtp_codec:info(tls, Codec0) of
338-
{true, _} when PacketLayerMod == mtp_secure ->
340+
case TlsHandshakeDone of
341+
true when PacketLayerMod == mtp_secure ->
339342
{mtp_secure_fake_tls, PState0};
340-
{false, _} ->
343+
false ->
341344
assert_protocol(PacketLayerMod, AllowedProtocols),
342345
check_policy(Listener, Ip, undefined),
343346
%FIXME: if any codebelow fail, we will get counter policy leak

0 commit comments

Comments
 (0)