From 0a3dc15cd3d6dd518fd9657a1ec97806a65986e0 Mon Sep 17 00:00:00 2001 From: doronz Date: Sun, 26 Nov 2023 21:31:05 +0200 Subject: [PATCH 1/3] ca: fix `DeprecationWarning` on python3.12 --- pymobiledevice3/ca.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pymobiledevice3/ca.py b/pymobiledevice3/ca.py index f4f6b37cf..49b4ba8c9 100755 --- a/pymobiledevice3/ca.py +++ b/pymobiledevice3/ca.py @@ -15,8 +15,10 @@ def make_cert(key, public_key, common_name=None): cert = cert.issuer_name(issuer) cert = cert.public_key(public_key) cert = cert.serial_number(1) - cert = cert.not_valid_before(datetime.utcnow() - timedelta(minutes=1)) - cert = cert.not_valid_after(datetime.utcnow() + timedelta(days=365 * 10)) + now = datetime.now() + now = now.replace(tzinfo=None) + cert = cert.not_valid_before(now - timedelta(minutes=1)) + cert = cert.not_valid_after(now + timedelta(days=365 * 10)) cert = cert.sign(key, hashes.SHA256()) return cert From 13a62b4513ea08a51947cbc2774e78858306eb7c Mon Sep 17 00:00:00 2001 From: doronz Date: Mon, 27 Nov 2023 13:54:23 +0200 Subject: [PATCH 2/3] tunneld: fix fastapi `DeprecationWarning` --- pymobiledevice3/tunneld.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pymobiledevice3/tunneld.py b/pymobiledevice3/tunneld.py index d2a3b2d2f..5527af3a0 100644 --- a/pymobiledevice3/tunneld.py +++ b/pymobiledevice3/tunneld.py @@ -3,7 +3,7 @@ import logging import os import signal -from contextlib import suppress +from contextlib import asynccontextmanager, suppress from typing import Dict, Tuple import fastapi @@ -162,14 +162,23 @@ async def discover_new_devices(self) -> None: class TunneldRunner: """ TunneldRunner orchestrate between the webserver and TunneldCore """ + @classmethod def create(cls, host: str, port: int) -> None: cls(host, port)._run_app() def __init__(self, host: str, port: int): + @asynccontextmanager + async def lifespan(app: FastAPI): + logging.getLogger('zeroconf').disabled = True + self._tunneld_core.start() + yield + logger.info('Closing tunneld tasks...') + await self._tunneld_core.close() + self.host = host self.port = port - self._app = FastAPI() + self._app = FastAPI(lifespan=lifespan) self._tunneld_core = TunneldCore() @self._app.get('/') @@ -193,16 +202,5 @@ async def clear_tunnels() -> fastapi.Response: self._tunneld_core.clear() return fastapi.Response(status_code=200, content='Cleared tunnels...') - @self._app.on_event('startup') - async def on_startup() -> None: - """ start TunneldCore """ - logging.getLogger('zeroconf').disabled = True - self._tunneld_core.start() - - @self._app.on_event('shutdown') - async def on_close() -> None: - logger.info('Closing tunneld tasks...') - await self._tunneld_core.close() - def _run_app(self) -> None: uvicorn.run(self._app, host=self.host, port=self.port, loop='asyncio') From b46ce2072b2c168ec75625df10f6bf1e13c96175 Mon Sep 17 00:00:00 2001 From: doronz Date: Wed, 29 Nov 2023 10:53:57 +0200 Subject: [PATCH 3/3] cli: fix permissions check on remote commands for windows --- pymobiledevice3/cli/cli_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymobiledevice3/cli/cli_common.py b/pymobiledevice3/cli/cli_common.py index b67a9dd14..1ae5ba643 100644 --- a/pymobiledevice3/cli/cli_common.py +++ b/pymobiledevice3/cli/cli_common.py @@ -3,6 +3,7 @@ import logging import os import signal +import sys import uuid from typing import Callable, List, Mapping, Optional, Tuple @@ -101,7 +102,7 @@ def wait_return(): def sudo_required(func): def wrapper(*args, **kwargs): - if os.geteuid() != 0: + if sys.platform != 'win32' and os.geteuid() != 0: raise AccessDeniedError() else: func(*args, **kwargs)