diff --git a/at_client/connections/atconnection.py b/at_client/connections/atconnection.py index 15b41d1..7c06da6 100644 --- a/at_client/connections/atconnection.py +++ b/at_client/connections/atconnection.py @@ -15,19 +15,29 @@ class AtConnection(ABC): Abstract base class for connecting to and communicating with an atprotocol server. """ - def __init__(self, host:str, port:int, context:ssl.SSLContext, verbose:bool=False): + def __init__(self, host:str, port:int, context:ssl.SSLContext=None, verbose:bool=False): """ Initialize the AtConnection object. Parameters: - host (str): The host name or IP address of the server. - port (int): The port number of the server. - - context (ssl.SSLContext): The SSL context for secure connections. + - context (ssl.SSLContext, optional): The SSL context for secure connections. - verbose (bool, optional): Indicates if verbose output is enabled (default is False). """ + if isinstance(context, ssl.SSLContext): + context.minimum_version = ssl.TLSVersion.TLSv1_2 + self._context = context + elif isinstance(context, bool): + verbose = context + self._context = ssl.create_default_context() + self._context.minimum_version = ssl.TLSVersion.TLSv1_2 + else: + self._context = ssl.create_default_context() + self._context.minimum_version = ssl.TLSVersion.TLSv1_2 + self._host = host self._port = port - self._context = context self._addr_info = socket.getaddrinfo(host, port)[0][-1] self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._secure_root_socket = None diff --git a/at_client/connections/atmonitorconnection.py b/at_client/connections/atmonitorconnection.py index cb909cb..0fd18b0 100644 --- a/at_client/connections/atmonitorconnection.py +++ b/at_client/connections/atmonitorconnection.py @@ -18,7 +18,7 @@ class AtMonitorConnection(AtSecondaryConnection): should_be_running: bool = False def __init__(self, queue: queue.Queue, atsign: AtSign, address: Address, - context: ssl.SSLContext = ssl.create_default_context(), + context: ssl.SSLContext = None, verbose: bool = True, regex=".*", last_received_time: int = 0): self.atsign = atsign self.queue = queue diff --git a/at_client/connections/atrootconnection.py b/at_client/connections/atrootconnection.py index 71540e1..2e78930 100644 --- a/at_client/connections/atrootconnection.py +++ b/at_client/connections/atrootconnection.py @@ -14,7 +14,7 @@ class AtRootConnection(AtConnection): __instance = None @staticmethod - def get_instance(host:str='root.atsign.org', port:int=64, context:ssl.SSLContext=ssl.create_default_context(), verbose:bool=False): + def get_instance(host:str='root.atsign.org', port:int=64, context:ssl.SSLContext=None, verbose:bool=False): """ Get an instance of AtRootConnection using the singleton pattern. @@ -25,7 +25,7 @@ def get_instance(host:str='root.atsign.org', port:int=64, context:ssl.SSLContext port : int, optional The port number of the root server (default is 64). context : ssl.SSLContext, optional - The SSL context for secure connections (default is ssl.create_default_context()). + The SSL context for secure connections (default is None). verbose : bool, optional Indicates if verbose output is enabled (default is False). diff --git a/at_client/connections/atsecondaryconnection.py b/at_client/connections/atsecondaryconnection.py index f7a8e42..9a56296 100644 --- a/at_client/connections/atsecondaryconnection.py +++ b/at_client/connections/atsecondaryconnection.py @@ -9,7 +9,7 @@ class AtSecondaryConnection(AtConnection): Subclass of AtConnection representing a connection to the secondary server in the atprotocol. """ - def __init__(self, address: Address, context:ssl.SSLContext=ssl.create_default_context(), verbose:bool=False): + def __init__(self, address: Address, context:ssl.SSLContext=None, verbose:bool=False): """ Initialize the AtSecondaryConnection object. @@ -20,7 +20,7 @@ def __init__(self, address: Address, context:ssl.SSLContext=ssl.create_default_c port : int The port number of the secondary server. context : ssl.SSLContext, optional - The SSL context for secure connections (default is ssl.create_default_context()). + The SSL context for secure connections (default is None). verbose : bool, optional Indicates if verbose output is enabled (default is False). """ diff --git a/pyproject.toml b/pyproject.toml index 3c8b23e..d624f3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "atsdk" -version = "0.2.73" +version = "0.2.74" description = "Python SDK for atPlatform" authors = ["Umang Shah ","Chris Swan "] maintainers = ["Chris Swan "]