18
18
import logging
19
19
20
20
from sipyco import keepalive , pyon
21
+ from sipyco .ssl_tools import create_ssl_context
21
22
from sipyco .asyncio_tools import AsyncioServer
22
23
23
24
@@ -102,6 +103,9 @@ class Subscriber:
102
103
A list of functions may also be used, and they will be called in turn.
103
104
:param disconnect_cb: An optional function called when disconnection
104
105
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.
105
109
"""
106
110
def __init__ (self , notifier_name , target_builder , notify_cb = None ,
107
111
disconnect_cb = None ):
@@ -114,9 +118,15 @@ def __init__(self, notifier_name, target_builder, notify_cb=None,
114
118
self .notify_cbs = notify_cb
115
119
self .disconnect_cb = disconnect_cb
116
120
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 )
118
127
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 )
120
130
try :
121
131
if before_receive_cb is not None :
122
132
before_receive_cb ()
0 commit comments