Capitalise configuration keys and force-authenticate when UsePassword is disabled

pull/1/head
Mark Veidemanis 7 years ago
parent 2355412a2e
commit 79d1e2a86c

@ -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"
}

@ -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()

Loading…
Cancel
Save