Capitalise configuration keys and force-authenticate when UsePassword is disabled

This commit is contained in:
Mark Veidemanis 2017-11-23 18:32:30 +00:00
parent 2355412a2e
commit 79d1e2a86c
2 changed files with 20 additions and 18 deletions

View File

@ -1,9 +1,9 @@
{ {
"port": 13867, "Port": 13867,
"bind": "127.0.0.1", "BindAddress": "127.0.0.1",
"usessl": true, "UseSSL": true,
"key": "key.pem", "ListenerKey": "key.pem",
"cert": "cert.pem", "ListenerCertificate": "cert.pem",
"usepassword": true, "UsePassword": true,
"password": "example" "Password": "s"
} }

View File

@ -37,6 +37,8 @@ class Base(Protocol):
def __init__(self, addr): def __init__(self, addr):
self.addr = addr self.addr = addr
self.authed = False self.authed = False
if config["UsePassword"] == False:
self.authed = True
def send(self, data): def send(self, data):
data += "\r\n" data += "\r\n"
@ -83,12 +85,12 @@ class Helper(object):
def getConfig(self): def getConfig(self):
with open("config.json", "r") as f: with open("config.json", "r") as f:
config = load(f) config = load(f)
if set(["port", "bind", "usessl", "usepassword"]).issubset(set(config.keys())): if set(["Port", "BindAddress", "UseSSL", "UsePassword"]).issubset(set(config.keys())):
if config["usessl"] == True: if config["UseSSL"] == True:
if not set(["cert", "key"]).issubset(set(config.keys())): if not set(["ListenerKey", "ListenerCertificate"]).issubset(set(config.keys())):
error("SSL is on but certificate or key is not defined") error("SSL is on but certificate or key is not defined")
if config["usepassword"] == True: if config["UsePassword"] == True:
if not "password" in config.keys(): if not "Password" in config.keys():
error("Password authentication is on but password is not defined") error("Password authentication is on but password is not defined")
return config return config
else: else:
@ -194,7 +196,7 @@ class Helper(object):
return return
else: else:
if cmd == "pass" and length == 2: if cmd == "pass" and length == 2:
if spl[1] == config["password"]: if spl[1] == config["Password"]:
success("Authenticated successfully") success("Authenticated successfully")
obj.authed = True obj.authed = True
return return
@ -213,11 +215,11 @@ if __name__ == "__main__":
help = helper.getHelp() help = helper.getHelp()
listener = BaseFactory() listener = BaseFactory()
if config["usessl"] == True: if config["UseSSL"] == True:
reactor.listenSSL(config["port"], listener, DefaultOpenSSLContextFactory(config["key"], config["cert"]), interface=config["bind"]) reactor.listenSSL(config["Port"], listener, DefaultOpenSSLContextFactory(config["ListenerKey"], config["ListenerCertificate"]), interface=config["BindAddress"])
log("Threshold running with SSL on %s:%s" % (config["bind"], config["port"])) log("Threshold running with SSL on %s:%s" % (config["BindAddress"], config["Port"]))
else: else:
reactor.listenTCP(config["port"], listener, interface=config["bind"]) reactor.listenTCP(config["Port"], listener, interface=config["BindAddress"])
log("Threshold running on %s:%s" % (config["bind"], config["port"])) log("Threshold running on %s:%s" % (config["BindAddress"], config["Port"]))
reactor.run() reactor.run()