From 80e224e8edcc6dace9bb47163e10fbc3eb88025e Mon Sep 17 00:00:00 2001 From: Franoosh Date: Sat, 10 Jan 2026 13:03:05 +0100 Subject: Add support for zmq certificates --- client.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'client.py') diff --git a/client.py b/client.py index 2c1b372..4b1c6a9 100644 --- a/client.py +++ b/client.py @@ -34,6 +34,7 @@ from helpers import ( timestamp_to_bytes, bytes_to_timestamp, write_yappi_stats, + auth_service, ) ################################################### @@ -69,6 +70,7 @@ FPS = 30 # Maybe serial number from /proc/cpuinfo. # In bytes. CLIENT_ID = b"client_001" +CERTIFICATE_DIRECTORY = 'certs' ##################################################### # End defaults and constants # @@ -373,7 +375,7 @@ class ClientTask(Thread): Watch for new camera devices using inotify """ - def __init__(self, _id, context: zmq.Context=None) -> None: + def __init__(self, _id, context: zmq.Context) -> None: """ Parameters ---------- @@ -383,7 +385,7 @@ class ClientTask(Thread): ZMQ context, by default None """ super().__init__(daemon=True) - self.context = context or zmq.Context.instance() + self.context = context self.socket = self.context.socket(zmq.DEALER) self.identity = self.socket.identity = _id # <-- bytes self.poll = zmq.Poller() @@ -1049,7 +1051,14 @@ if __name__ == "__main__": logger.info("Starting up ...") - client = ClientTask(get_serial_number()) + context = zmq.Context() + try: + auth_service(context, cert_dir=CERTIFICATE_DIRECTORY) + except Exception as exc: + logger.error("Error configuring authentication: %r", exc) + exit(1) + + client = ClientTask(get_serial_number(), context) client.start() client.join() -- cgit v1.2.3