mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 18:51:31 +00:00
Implement HMAC signatures of fsm_update broadcast messages
This commit is contained in:
parent
c658894c12
commit
d5feba7076
@ -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)
|
||||
|
@ -4,7 +4,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from tfw.networking.event_handlers import ServerConnector
|
||||
from tfw.crypto import message_checksum
|
||||
from tfw.crypto import message_checksum, KeyManager, verify_message
|
||||
from tfw.config.logs import logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -116,9 +116,11 @@ class FSMAwareEventHandler(EventHandlerBase, ABC):
|
||||
super().__init__(key)
|
||||
self.subscribe('fsm_update')
|
||||
self.fsm_state = None
|
||||
self._auth_key = KeyManager().auth_key
|
||||
|
||||
def dispatch_handling(self, message):
|
||||
if message['key'] == 'fsm_update':
|
||||
if verify_message(self._auth_key, message):
|
||||
self._handle_fsm_update(message)
|
||||
return None
|
||||
return super().dispatch_handling(message)
|
||||
|
Loading…
Reference in New Issue
Block a user