Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 48b9f8e

Browse files
committedFeb 19, 2025
sync_struct: add optional SSL support
Signed-off-by: Florian Agbuya <[email protected]>
1 parent 7b6a8bc commit 48b9f8e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

‎sipyco/sync_struct.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import logging
1919

2020
from sipyco import keepalive, pyon
21+
from sipyco.ssl_tools import create_ssl_context
2122
from sipyco.asyncio_tools import AsyncioServer
2223

2324

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

117-
async def connect(self, host, port, before_receive_cb=None):
121+
async def connect(self, host, port, local_cert=None, local_key=None, peer_cert=None,
122+
before_receive_cb=None):
123+
if local_cert is None:
124+
ssl_context = None
125+
else:
126+
ssl_context = create_ssl_context(local_cert, local_key, peer_cert)
118127
self.reader, self.writer = \
119-
await keepalive.async_open_connection(host, port, limit=100 * 1024 * 1024)
128+
await keepalive.async_open_connection(host, port, ssl=ssl_context,
129+
limit=100 * 1024 * 1024)
120130
try:
121131
if before_receive_cb is not None:
122132
before_receive_cb()

0 commit comments

Comments
 (0)
Please sign in to comment.