Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/s2python/s2_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import threading
import uuid
import ssl
from dataclasses import dataclass
from typing import Optional, List, Type, Dict, Callable, Awaitable, Union

Expand Down Expand Up @@ -198,6 +199,7 @@ class S2Connection: # pylint: disable=too-many-instance-attributes
_eventloop: asyncio.AbstractEventLoop
_stop_event: asyncio.Event
_restart_connection_event: asyncio.Event
_verify_certificate: bool

def __init__( # pylint: disable=too-many-arguments
self,
Expand All @@ -206,6 +208,7 @@ def __init__( # pylint: disable=too-many-arguments
control_types: List[S2ControlType],
asset_details: AssetDetails,
reconnect: bool = False,
verify_certificate: bool = True,
) -> None:
self.url = url
self.reconnect = reconnect
Expand All @@ -221,6 +224,7 @@ def __init__( # pylint: disable=too-many-arguments
self.control_types = control_types
self.role = role
self.asset_details = asset_details
self._verify_certificate = verify_certificate

self._handlers.register_handler(SelectControlType, self.handle_select_control_type_as_rm)
self._handlers.register_handler(Handshake, self.handle_handshake)
Expand Down Expand Up @@ -318,8 +322,13 @@ async def wait_till_connection_restart() -> None:
await self.ws.wait_closed()

async def _connect_ws(self) -> None:
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
if not self._verify_certificate:
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

try:
self.ws = await ws_connect(uri=self.url)
self.ws = await ws_connect(uri=self.url, ssl=ssl_context)
except (EOFError, OSError) as e:
logger.info("Could not connect due to: %s", str(e))

Expand Down