Skip to content

Commit

Permalink
Replace deprecated ssl.wrap_context method (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Orhideous authored Feb 14, 2024
1 parent 078741d commit d7d0677
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions roombapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Import to public all required modules."""

from .discovery import RoombaDiscovery
from .getpassword import RoombaPassword
from .roomba import Roomba, RoombaConnectionError
Expand Down
13 changes: 5 additions & 8 deletions roombapy/getpassword.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""The class helps you to get password for your Roomba."""

import logging
import socket
import ssl
import struct

from roombapy.remote_client import generate_tls_context


class RoombaPassword:
"""Main class to get a password."""
Expand Down Expand Up @@ -78,10 +80,5 @@ def _decode_password(data):
def _get_socket():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.settimeout(10)
ssl_socket = ssl.wrap_socket(
server_socket,
ssl_version=ssl.PROTOCOL_TLS,
ciphers="DEFAULT@SECLEVEL=1",
)
ssl_socket.context.options |= 0x4 # set OP_LEGACY_SERVER_CONNECT
return ssl_socket
context = generate_tls_context()
return context.wrap_socket(server_socket)
5 changes: 2 additions & 3 deletions roombapy/remote_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@cache
def _generate_tls_context() -> ssl.SSLContext:
def generate_tls_context() -> ssl.SSLContext:
"""Generate TLS context.
We only want to do this once ever because it's expensive.
Expand Down Expand Up @@ -108,10 +108,9 @@ def _get_mqtt_client(self):

self.log.debug("Setting TLS certificate")
mqtt_client._ssl_context = None
ssl_context = _generate_tls_context()
ssl_context = generate_tls_context()
mqtt_client.tls_set_context(ssl_context)
mqtt_client.tls_insecure_set(True)
mqtt_client._ssl_context.options |= 0x4 # set OP_LEGACY_SERVER_CONNECT

return mqtt_client

Expand Down

0 comments on commit d7d0677

Please sign in to comment.