From 17b24377ddb3b038944a7a0cc6c0b4d091be571c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 12 Jul 2018 15:17:39 +0200 Subject: [PATCH] Implement a ZMQ prefix-match countermeasure in EHBase --- lib/tfw/event_handler_base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/tfw/event_handler_base.py b/lib/tfw/event_handler_base.py index aee4b93..81b1ead 100644 --- a/lib/tfw/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -31,10 +31,25 @@ class EventHandlerBase(ABC): a response back in case the handler returned something. This is subscribed in __init__(). """ + if not self.check_key(message): + return + response = self.dispatch_handling(message) if response: self.server_connector.send(response) + def check_key(self, message): + """ + Checks whether the message is intended for this + EventHandler. + + This is necessary because ZMQ handles PUB - SUB + connetions with pattern matching (e.g. someone + subscribed to 'fsm' will receive 'fsm_update' + messages as well. + """ + return self.key == message['key'] + def dispatch_handling(self, message): """ Used to dispatch messages to their specific handlers.