Skip to content

Commit

Permalink
sync_struct: add optional SSL support
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Agbuya <[email protected]>
  • Loading branch information
fsagbuya committed Jan 24, 2025
1 parent 077b0bf commit d7a3c5e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sipyco/sync_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging

from sipyco import keepalive, pyon
from sipyco.ssl_tools import create_ssl_context
from sipyco.asyncio_tools import AsyncioServer


Expand Down Expand Up @@ -102,6 +103,9 @@ class Subscriber:
A list of functions may also be used, and they will be called in turn.
:param disconnect_cb: An optional function called when disconnection
happens from external causes (i.e. not when ``close`` is called).
:param local_cert: Client's certificate file. Providing this enables SSL.
:param local_key: Client's private key file. Required when local_cert is provided.
:param peer_cert: Server's SSL certificate file to trust. Required when local_cert is provided.
"""
def __init__(self, notifier_name, target_builder, notify_cb=None,
disconnect_cb=None):
Expand All @@ -114,9 +118,12 @@ def __init__(self, notifier_name, target_builder, notify_cb=None,
self.notify_cbs = notify_cb
self.disconnect_cb = disconnect_cb

async def connect(self, host, port, before_receive_cb=None):
async def connect(self, host, port, local_cert=None, local_key=None, peer_cert=None,
before_receive_cb=None):
ssl_context = create_ssl_context(local_cert, local_key, peer_cert)
self.reader, self.writer = \
await keepalive.async_open_connection(host, port, limit=100 * 1024 * 1024)
await keepalive.async_open_connection(host, port, ssl=ssl_context,
limit=100 * 1024 * 1024)
try:
if before_receive_cb is not None:
before_receive_cb()
Expand Down

0 comments on commit d7a3c5e

Please sign in to comment.