Skip to content

Commit 5b61776

Browse files
added a parameter S2Connection to allow self signed certificates
1 parent 1a590c0 commit 5b61776

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/s2python/s2_connection.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class S2Connection: # pylint: disable=too-many-instance-attributes
198198
_eventloop: asyncio.AbstractEventLoop
199199
_stop_event: asyncio.Event
200200
_restart_connection_event: asyncio.Event
201+
_verify_certificate: bool
201202

202203
def __init__( # pylint: disable=too-many-arguments
203204
self,
@@ -206,6 +207,7 @@ def __init__( # pylint: disable=too-many-arguments
206207
control_types: List[S2ControlType],
207208
asset_details: AssetDetails,
208209
reconnect: bool = False,
210+
verify_certificate: bool = True,
209211
) -> None:
210212
self.url = url
211213
self.reconnect = reconnect
@@ -221,6 +223,7 @@ def __init__( # pylint: disable=too-many-arguments
221223
self.control_types = control_types
222224
self.role = role
223225
self.asset_details = asset_details
226+
self._verify_certificate = verify_certificate
224227

225228
self._handlers.register_handler(SelectControlType, self.handle_select_control_type_as_rm)
226229
self._handlers.register_handler(Handshake, self.handle_handshake)
@@ -318,8 +321,13 @@ async def wait_till_connection_restart() -> None:
318321
await self.ws.wait_closed()
319322

320323
async def _connect_ws(self) -> None:
324+
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
325+
if not self._verify_certificate:
326+
ssl_context.check_hostname = False
327+
ssl_context.verify_mode = ssl.CERT_NONE
328+
321329
try:
322-
self.ws = await ws_connect(uri=self.url)
330+
self.ws = await ws_connect(uri=self.url, ssl=ssl_context)
323331
except (EOFError, OSError) as e:
324332
logger.info("Could not connect due to: %s", str(e))
325333

0 commit comments

Comments
 (0)