Make TFWServer sign commands issued due to signed triggers

This commit is contained in:
Kristóf Tóth 2018-07-23 17:14:44 +02:00
parent 8ba99d8e36
commit e846a2b111

View File

@ -9,6 +9,7 @@ from tornado.web import Application
from tfw.networking.event_handlers import ServerUplinkConnector
from tfw.networking.server import EventHandlerConnector
from tfw.networking import MessageSender
from tfw.crypto import KeyManager, verify_message, sign_message
from tfw.config.logs import logging
from .zmq_websocket_proxy import ZMQWebSocketProxy
@ -24,6 +25,7 @@ class TFWServer:
def __init__(self):
self._event_handler_connector = EventHandlerConnector()
self._uplink_connector = ServerUplinkConnector()
self._auth_key = KeyManager().auth_key
self.application = Application([(
r'/ws', ZMQWebSocketProxy, {
@ -37,13 +39,16 @@ class TFWServer:
def handle_trigger(self, message):
if 'trigger' in message:
LOG.debug('Executing handler for trigger "%s"', message.get('trigger', ''))
self._uplink_connector.send_to_eventhandler({
fsm_eh_command = {
'key': 'fsm',
'data': {
'command': 'trigger',
'value': message.get('trigger', '')
'value': message['trigger']
}
})
}
if verify_message(self._auth_key, message):
sign_message(self._auth_key, fsm_eh_command)
self._uplink_connector.send_to_eventhandler(fsm_eh_command)
def handle_recover(self, message):
if message['key'] == 'recover':