2019-08-05 11:47:05 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from tfw.internals.crypto import KeyManager, verify_message
|
|
|
|
|
2019-08-23 13:27:03 +00:00
|
|
|
from .control_event_handler import ControlEventHandler
|
2019-08-05 11:47:05 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=abstract-method
|
2019-08-23 13:27:03 +00:00
|
|
|
class SignedEventHandler(ControlEventHandler):
|
2019-08-05 11:47:05 +00:00
|
|
|
def __init__(self, connector):
|
|
|
|
self._auth_key = KeyManager().auth_key
|
|
|
|
super().__init__(connector)
|
|
|
|
|
|
|
|
def _event_callback(self, message):
|
|
|
|
if verify_message(self._auth_key, message):
|
|
|
|
self.handle_event(message, self.connector)
|
|
|
|
else:
|
|
|
|
LOG.error('Message does not have valid signature: %s', message)
|