2019-08-05 11:47:05 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from tfw.internals.crypto import KeyManager, verify_message
|
|
|
|
|
2019-08-26 09:10:39 +00:00
|
|
|
from .event_handler import EventHandler
|
2019-08-05 11:47:05 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=abstract-method
|
2019-08-26 09:10:39 +00:00
|
|
|
class SignedEventHandler(EventHandler):
|
2019-08-05 11:47:05 +00:00
|
|
|
def __init__(self, connector):
|
|
|
|
self._auth_key = KeyManager().auth_key
|
|
|
|
super().__init__(connector)
|
|
|
|
|
2019-08-26 09:10:39 +00:00
|
|
|
def _validate_message(self, message):
|
|
|
|
is_valid = verify_message(self._auth_key, message)
|
|
|
|
if not is_valid:
|
2019-08-05 11:47:05 +00:00
|
|
|
LOG.error('Message does not have valid signature: %s', message)
|
2019-08-26 09:10:39 +00:00
|
|
|
return is_valid
|