diff --git a/mtprotoproxy.py b/mtprotoproxy.py index 6077746..87523fc 100755 --- a/mtprotoproxy.py +++ b/mtprotoproxy.py @@ -963,7 +963,6 @@ async def handle_handshake(reader, writer): global used_handshakes TLS_START_BYTES = b"\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03" - TLS_START_LEN = len(TLS_START_BYTES) EMPTY_READ_BUF_SIZE = 4096 peer = writer.get_extra_info('peername')[:2] @@ -976,13 +975,14 @@ async def handle_handshake(reader, writer): is_tls_handshake = True handshake = b"" - for byte_num in range(TLS_START_LEN): + for expected_byte in TLS_START_BYTES: handshake += await reader.readexactly(1) - if handshake[-1] != TLS_START_BYTES[byte_num]: + if handshake[-1] != expected_byte: is_tls_handshake = False + break if is_tls_handshake: - handshake += await reader.readexactly(TLS_HANDSHAKE_LEN - TLS_START_LEN) + handshake += await reader.readexactly(TLS_HANDSHAKE_LEN - len(handshake)) tls_handshake_result = await handle_pseudo_tls_handshake(handshake, reader, writer, peer) if not tls_handshake_result: @@ -994,7 +994,7 @@ async def handle_handshake(reader, writer): if config.TLS_ONLY: await handle_bad_client(reader, writer, handshake) return False - handshake += await reader.readexactly(HANDSHAKE_LEN - TLS_START_LEN) + handshake += await reader.readexactly(HANDSHAKE_LEN - len(handshake)) dec_prekey_and_iv = handshake[SKIP_LEN:SKIP_LEN+PREKEY_LEN+IV_LEN] dec_prekey, dec_iv = dec_prekey_and_iv[:PREKEY_LEN], dec_prekey_and_iv[PREKEY_LEN:]