Skip to content

Commit

Permalink
feat: add 'tls_params' to Client.__init__
Browse files Browse the repository at this point in the history
Fixes #14.
  • Loading branch information
Sohaib90 authored Aug 31, 2022
1 parent d7e4837 commit 0291b62
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions asyncio_mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ def __init__(
self.retain = retain
self.properties = properties

# TLS set parameter class
class TLSParameters:
def __init__(
self,
*,
ca_certs: Optional[str] = None,
certfile: Optional[str] = None,
keyfile: Optional[str] = None,
cert_reqs: Optional[ssl.VerifyMode] = None,
tls_version: Optional[ssl._SSLMethod]= None,
ciphers: Optional[str] = None,
keyfile_password: Optional[str] = None
):
self.ca_certs = ca_certs
self.certfile = certfile
self.keyfile = keyfile
self.cert_reqs = cert_reqs
self.tls_version = tls_version
self.ciphers = ciphers
self.keyfile_password = keyfile_password



# See the overloads of `socket.setsockopt` for details.
SocketOption = Union[
Expand Down Expand Up @@ -117,6 +139,7 @@ def __init__(
logger: Optional[logging.Logger] = None,
client_id: Optional[str] = None,
tls_context: Optional[ssl.SSLContext] = None,
tls_params: Optional[TLSParameters] = None,
protocol: Optional[ProtocolVersion] = None,
will: Optional[Will] = None,
clean_session: Optional[bool] = None,
Expand Down Expand Up @@ -188,6 +211,15 @@ def __init__(

if tls_context is not None:
self._client.tls_set_context(tls_context)

if tls_params is not None:
self._client.tls_set(ca_certs= tls_params.ca_certs,
certfile= tls_params.certfile,
keyfile= tls_params.keyfile,
cert_reqs= tls_params.cert_reqs,
tls_version= tls_params.tls_version,
ciphers= tls_params.ciphers,
keyfile_password= tls_params.keyfile_password)

if websocket_path is not None or websocket_headers is not None:
self._client.ws_set_options(
Expand Down

0 comments on commit 0291b62

Please sign in to comment.