diff --git a/server/build_binary.py b/server/build_binary.py index a897005..c7b9662 100755 --- a/server/build_binary.py +++ b/server/build_binary.py @@ -30,6 +30,7 @@ HIDDEN_IMPORTS = [ "aiohttp", "pynput", "pyperclip", + "certifi", ] EXCLUDED_MODULES = [ diff --git a/server/requirements.txt b/server/requirements.txt index 0651e3f..086b097 100644 --- a/server/requirements.txt +++ b/server/requirements.txt @@ -4,3 +4,4 @@ pyperclip>=1.8.2 qrcode>=7.4.2 PySide6-Essentials>=6.8.0 pillow>=10.0.0 +certifi>=2024.2.2 diff --git a/server/updater.py b/server/updater.py index fb630a0..af78725 100644 --- a/server/updater.py +++ b/server/updater.py @@ -7,6 +7,7 @@ import os import re import shlex import shutil +import ssl import subprocess import sys import tempfile @@ -19,6 +20,45 @@ from typing import Callable, Optional from version import APP_NAME, APP_VERSION, RELEASES_PAGE_URL, UPDATE_RELEASES_API +def get_ssl_context() -> ssl.SSLContext: + """Restituisce un SSLContext con certificati CA validi anche in bundle PyInstaller/macOS.""" + # 1. Prova prima certifi se presente (standard de-facto con bundle CA Mozilla aggiornato) + try: + import certifi + return ssl.create_default_context(cafile=certifi.where()) + except Exception: + pass + + # 2. Crea il contesto SSL standard + try: + ctx = ssl.create_default_context() + if ctx.get_ca_certs(): + return ctx + except Exception: + ctx = ssl.create_default_context() + + # 3. Su macOS e Linux, se l'ambiente PyInstaller non ha trovato i certificati, + # carica i certificati di root di sistema noti + known_ca_bundles = ( + "/etc/ssl/cert.pem", # macOS default e BSD + "/etc/ssl/certs/ca-certificates.crt", # Debian / Ubuntu + "/etc/pki/tls/certs/ca-bundle.crt", # Fedora / RHEL / CentOS + "/etc/ssl/ca-bundle.pem", # OpenSUSE + "/opt/homebrew/etc/openssl@3/cert.pem", # Homebrew macOS Apple Silicon + "/usr/local/etc/openssl@3/cert.pem", # Homebrew macOS Intel + ) + for ca_path in known_ca_bundles: + if os.path.isfile(ca_path): + try: + ctx.load_verify_locations(cafile=ca_path) + if ctx.get_ca_certs(): + return ctx + except Exception: + continue + + return ctx + + @dataclass class ReleaseAsset: """Singolo file eseguibile o installer allegato a una release.""" @@ -237,7 +277,7 @@ def check_for_updates( ) try: - with urllib.request.urlopen(req, timeout=timeout) as resp: + with urllib.request.urlopen(req, timeout=timeout, context=get_ssl_context()) as resp: raw = resp.read().decode("utf-8", errors="replace") payload = json.loads(raw) except urllib.error.HTTPError as exc: @@ -299,7 +339,7 @@ def download_asset( asset.download_url, headers={"User-Agent": f"BarcodeReaderServer/{APP_VERSION}"}, ) - with urllib.request.urlopen(req, timeout=timeout) as resp: + with urllib.request.urlopen(req, timeout=timeout, context=get_ssl_context()) as resp: total = int(resp.headers.get("Content-Length") or asset.size or 0) downloaded = 0 with open(dest_path, "wb") as out: diff --git a/server/version.py b/server/version.py index b4b5a4c..d6951f1 100644 --- a/server/version.py +++ b/server/version.py @@ -7,7 +7,7 @@ APP_NAME = "Barcode Reader Server" APP_BINARY_NAME = "BarcodeServer" APP_ID = "com.catellisrl.barcodereader" APP_PUBLISHER = "Catelli Srl" -APP_VERSION = "1.0.0" +APP_VERSION = "1.0.1" GITEA_BASE_URL = "https://gitea.catelli.it" GITEA_REPO = "brontomark/barcode_reader_pc"