From f5c30c611530943441e3ee6fb22bcb5a9b6d7ccc Mon Sep 17 00:00:00 2001 From: Alexander Bersenev Date: Wed, 29 Aug 2018 00:04:58 +0500 Subject: [PATCH] secure only mode --- mtprotoproxy.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mtprotoproxy.py b/mtprotoproxy.py index 1d83cb5..fcc8ecb 100755 --- a/mtprotoproxy.py +++ b/mtprotoproxy.py @@ -147,6 +147,8 @@ AD_TAG = bytes.fromhex(config.get("AD_TAG", "")) PREFER_IPV6 = config.get("PREFER_IPV6", socket.has_ipv6) # disables tg->client trafic reencryption, faster but less secure FAST_MODE = config.get("FAST_MODE", True) +# doesn't allow to connect in not-secure mode +SECURE_ONLY = config.get("SECURE_ONLY", False) STATS_PRINT_PERIOD = config.get("STATS_PRINT_PERIOD", 600) PROXY_INFO_UPDATE_PERIOD = config.get("PROXY_INFO_UPDATE_PERIOD", 24*60*60) TO_CLT_BUFSIZE = config.get("TO_CLT_BUFSIZE", 16384) @@ -588,6 +590,9 @@ async def handle_handshake(reader, writer): if proto_tag not in (PROTO_TAG_ABRIDGED, PROTO_TAG_INTERMEDIATE, PROTO_TAG_SECURE): continue + if SECURE_ONLY and proto_tag != PROTO_TAG_SECURE: + continue + dc_idx = int.from_bytes(decrypted[DC_IDX_POS:DC_IDX_POS+2], "little", signed=True) reader = CryptoWrappedStreamReader(reader, decryptor) @@ -1097,13 +1102,14 @@ def print_tg_info(): for user, secret in sorted(USERS.items(), key=lambda x: x[0]): for ip in ip_addrs: - params = {"server": ip, "port": PORT, "secret": secret} - params_encodeded = urllib.parse.urlencode(params, safe=':') - print("{}: tg://proxy?{}".format(user, params_encodeded), flush=True) + if not SECURE_ONLY: + params = {"server": ip, "port": PORT, "secret": secret} + params_encodeded = urllib.parse.urlencode(params, safe=':') + print("{}: tg://proxy?{}".format(user, params_encodeded), flush=True) params = {"server": ip, "port": PORT, "secret": "dd" + secret} params_encodeded = urllib.parse.urlencode(params, safe=':') - print("{}: tg://proxy?{} (beta)".format(user, params_encodeded), flush=True) + print("{}: tg://proxy?{}".format(user, params_encodeded), flush=True) def loop_exception_handler(loop, context):