Skip to content

Commit

Permalink
Optionally encrypt the password using sha256
Browse files Browse the repository at this point in the history
Add a configuration parameter whether the password should be sha256 encrypted.
Newer Connect Box models require an encrypted password, but leave it to the user
whether they want to do it themselves.
  • Loading branch information
kvalev committed Mar 7, 2023
1 parent 67d349f commit f977880
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions connect_box/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""A Python Client to get data from UPC Connect Boxes."""
import asyncio
from collections import OrderedDict
from hashlib import sha256
from http.cookies import BaseCookie
import logging
import re
Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(
host: str = "192.168.0.1",
username: str = "admin",
use_token: bool = True,
encrypt_password: bool = False,
):
"""Initialize the connection."""
self._session: aiohttp.ClientSession = session
Expand Down Expand Up @@ -92,6 +94,10 @@ def __init__(
self.cm_systeminfo: Optional[CmSystemInfo] = None
self.global_settings: Optional[GlobalSettings] = None

# Optionally encrypt_password the password if requested
if password and encrypt_password:
self.password = sha256(self.password.encode("utf-8")).hexdigest()

# Allow setting cookies for IP addresses
self._session.cookie_jar._unsafe = True

Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
async def main():
"""Sample code to retrieve the data from an UPC Connect Box."""
async with aiohttp.ClientSession() as session:
client = ConnectBox(session, PASSWORD, use_token=False)
client = ConnectBox(session, PASSWORD, use_token=False, encode_password=True)

# Print details about the downstream channel connectivity
await client.async_get_downstream()
Expand Down

0 comments on commit f977880

Please sign in to comment.