From 79d1e2a86cd358549dcacc1dd04c9ede41cff089 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 23 Nov 2017 18:32:30 +0000 Subject: [PATCH] Capitalise configuration keys and force-authenticate when UsePassword is disabled --- example.json | 14 +++++++------- threshold | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/example.json b/example.json index 07d4b3e..78f64ce 100644 --- a/example.json +++ b/example.json @@ -1,9 +1,9 @@ { - "port": 13867, - "bind": "127.0.0.1", - "usessl": true, - "key": "key.pem", - "cert": "cert.pem", - "usepassword": true, - "password": "example" + "Port": 13867, + "BindAddress": "127.0.0.1", + "UseSSL": true, + "ListenerKey": "key.pem", + "ListenerCertificate": "cert.pem", + "UsePassword": true, + "Password": "s" } diff --git a/threshold b/threshold index 076c053..b8569af 100755 --- a/threshold +++ b/threshold @@ -37,6 +37,8 @@ class Base(Protocol): def __init__(self, addr): self.addr = addr self.authed = False + if config["UsePassword"] == False: + self.authed = True def send(self, data): data += "\r\n" @@ -83,12 +85,12 @@ class Helper(object): def getConfig(self): with open("config.json", "r") as f: config = load(f) - if set(["port", "bind", "usessl", "usepassword"]).issubset(set(config.keys())): - if config["usessl"] == True: - if not set(["cert", "key"]).issubset(set(config.keys())): + if set(["Port", "BindAddress", "UseSSL", "UsePassword"]).issubset(set(config.keys())): + if config["UseSSL"] == True: + if not set(["ListenerKey", "ListenerCertificate"]).issubset(set(config.keys())): error("SSL is on but certificate or key is not defined") - if config["usepassword"] == True: - if not "password" in config.keys(): + if config["UsePassword"] == True: + if not "Password" in config.keys(): error("Password authentication is on but password is not defined") return config else: @@ -194,7 +196,7 @@ class Helper(object): return else: if cmd == "pass" and length == 2: - if spl[1] == config["password"]: + if spl[1] == config["Password"]: success("Authenticated successfully") obj.authed = True return @@ -213,11 +215,11 @@ if __name__ == "__main__": help = helper.getHelp() listener = BaseFactory() - if config["usessl"] == True: - reactor.listenSSL(config["port"], listener, DefaultOpenSSLContextFactory(config["key"], config["cert"]), interface=config["bind"]) - log("Threshold running with SSL on %s:%s" % (config["bind"], config["port"])) + if config["UseSSL"] == True: + reactor.listenSSL(config["Port"], listener, DefaultOpenSSLContextFactory(config["ListenerKey"], config["ListenerCertificate"]), interface=config["BindAddress"]) + log("Threshold running with SSL on %s:%s" % (config["BindAddress"], config["Port"])) else: - reactor.listenTCP(config["port"], listener, interface=config["bind"]) - log("Threshold running on %s:%s" % (config["bind"], config["port"])) + reactor.listenTCP(config["Port"], listener, interface=config["BindAddress"]) + log("Threshold running on %s:%s" % (config["BindAddress"], config["Port"])) reactor.run()