Implement HMAC signatures of fsm_update broadcast messages

This commit is contained in:
Kristóf Tóth
2018-07-16 14:31:52 +02:00
parent c658894c12
commit d5feba7076
2 changed files with 10 additions and 3 deletions

View File

@ -2,6 +2,7 @@
# All Rights Reserved. See LICENSE file for details.
from tfw import EventHandlerBase
from tfw.crypto import KeyManager, sign_message
from tfw.config.logs import logging
LOG = logging.getLogger(__name__)
@ -12,6 +13,7 @@ class FSMManagingEventHandler(EventHandlerBase):
super().__init__(key)
self.fsm = fsm_type()
self._fsm_updater = FSMUpdater(self.fsm)
self.auth_key = KeyManager().auth_key
self.command_handlers = {
'trigger': self.handle_trigger,
@ -22,7 +24,10 @@ class FSMManagingEventHandler(EventHandlerBase):
try:
data = message['data']
message['data'] = self.command_handlers[data['command']](data)
self.server_connector.broadcast(self._fsm_updater.generate_fsm_update())
fsm_update_message = self._fsm_updater.generate_fsm_update()
sign_message(self.auth_key, message)
sign_message(self.auth_key, fsm_update_message)
self.server_connector.broadcast(fsm_update_message)
return message
except KeyError:
LOG.error('IGNORING MESSAGE: Invalid message received: %s', message)