From 07bd9b795a813a24e124ec9ad101c4c30f672049 Mon Sep 17 00:00:00 2001 From: Alexander Bersenev Date: Tue, 25 Feb 2020 02:41:49 +0500 Subject: [PATCH] handle bad secrets in configs --- mtprotoproxy.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mtprotoproxy.py b/mtprotoproxy.py index 2d44bc9..7a73004 100755 --- a/mtprotoproxy.py +++ b/mtprotoproxy.py @@ -126,6 +126,15 @@ def init_config(): conf_dict.setdefault("USERS", {"tg": "00000000000000000000000000000000"}) conf_dict["AD_TAG"] = bytes.fromhex(conf_dict.get("AD_TAG", "")) + for user, secret in conf_dict["USERS"].items(): + if not re.fullmatch("[0-9a-fA-F]{32}", secret): + fixed_secret = re.sub(r"[^0-9a-fA-F]", "", secret).zfill(32)[:32] + + print_err("Bad secret for user %s, should be 32 hex chars, got %s. " % (user, secret)) + print_err("Changing it to %s" % fixed_secret) + + conf_dict["USERS"][user] = fixed_secret + # load advanced settings # use middle proxy, necessary to show ad