Made STS policies one-shot when upgrading from plaintext to tls
This commit is contained in:
parent
19864a7e13
commit
5981bfa04c
1 changed files with 11 additions and 4 deletions
|
@ -2,18 +2,19 @@ import time
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _set_policy(self, server, port, duration):
|
def _set_policy(self, server, port, duration, one_shot):
|
||||||
expiration = None
|
expiration = None
|
||||||
if duration:
|
if duration:
|
||||||
expiration = time.time()+int(duration)
|
expiration = time.time()+int(duration)
|
||||||
server.set_setting("sts-policy", {
|
server.set_setting("sts-policy", {
|
||||||
"port": port,
|
"port": port,
|
||||||
"expiration": expiration})
|
"expiration": expiration,
|
||||||
|
"one-shot": one_shot})
|
||||||
def _change_duration(self, server, info):
|
def _change_duration(self, server, info):
|
||||||
port = event["server"].port
|
port = event["server"].port
|
||||||
if "port" in info:
|
if "port" in info:
|
||||||
port = int(info["port"])
|
port = int(info["port"])
|
||||||
self._set_policy(server, port, info["duration"])
|
self._set_policy(server, port, info["duration"], False)
|
||||||
|
|
||||||
@utils.hook("received.cap.ls")
|
@utils.hook("received.cap.ls")
|
||||||
def on_cap_ls(self, event):
|
def on_cap_ls(self, event):
|
||||||
|
@ -23,7 +24,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
delimiter=",")
|
delimiter=",")
|
||||||
if not event["server"].tls:
|
if not event["server"].tls:
|
||||||
self._set_policy(event["server"], int(info["port"]),
|
self._set_policy(event["server"], int(info["port"]),
|
||||||
None)
|
None, True)
|
||||||
event["server"].disconnect()
|
event["server"].disconnect()
|
||||||
else:
|
else:
|
||||||
self._change_duration(event["server"], info)
|
self._change_duration(event["server"], info)
|
||||||
|
@ -44,3 +45,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
[str(event["server"])])
|
[str(event["server"])])
|
||||||
event["server"].tls = True
|
event["server"].tls = True
|
||||||
event["server"].port = sts_policy["port"]
|
event["server"].port = sts_policy["port"]
|
||||||
|
|
||||||
|
@utils.hook("received.numeric.001"):
|
||||||
|
def on_connect(self, event):
|
||||||
|
sts_policy = event["server"].get_setting("sts-policy")
|
||||||
|
if sts_policy and sts_policy["one-shot"]:
|
||||||
|
event["server"].del_setting("sts-policy")
|
||||||
|
|
Loading…
Reference in a new issue