fix: add certifi bundle and custom SSL context for reliable updates in bundled builds
Build and Release Barcode Reader Server (Multi-Platform) / build-linux (push) Successful in 48s
Build and Release Barcode Reader Server (Multi-Platform) / build-windows (push) Successful in 3m39s
Build and Release Barcode Reader Server (Multi-Platform) / build-macos (push) Failing after 10m57s
Build and Release Barcode Reader Server (Multi-Platform) / build-linux (push) Successful in 48s
Build and Release Barcode Reader Server (Multi-Platform) / build-windows (push) Successful in 3m39s
Build and Release Barcode Reader Server (Multi-Platform) / build-macos (push) Failing after 10m57s
This commit is contained in:
1 parent
2d94be87ae
commit
dbd53c17e7
4 files changed
+45
-3
No files matched your search
@@ -30,6 +30,7 @@ HIDDEN_IMPORTS = [
|
|||||||
"aiohttp",
|
"aiohttp",
|
||||||
"pynput",
|
"pynput",
|
||||||
"pyperclip",
|
"pyperclip",
|
||||||
|
"certifi",
|
||||||
]
|
]
|
||||||
|
|
||||||
EXCLUDED_MODULES = [
|
EXCLUDED_MODULES = [
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ pyperclip>=1.8.2
|
|||||||
qrcode>=7.4.2
|
qrcode>=7.4.2
|
||||||
PySide6-Essentials>=6.8.0
|
PySide6-Essentials>=6.8.0
|
||||||
pillow>=10.0.0
|
pillow>=10.0.0
|
||||||
|
certifi>=2024.2.2
|
||||||
+42
-2
@@ -7,6 +7,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
import ssl
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -19,6 +20,45 @@ from typing import Callable, Optional
|
|||||||
from version import APP_NAME, APP_VERSION, RELEASES_PAGE_URL, UPDATE_RELEASES_API
|
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
|
@dataclass
|
||||||
class ReleaseAsset:
|
class ReleaseAsset:
|
||||||
"""Singolo file eseguibile o installer allegato a una release."""
|
"""Singolo file eseguibile o installer allegato a una release."""
|
||||||
@@ -237,7 +277,7 @@ def check_for_updates(
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
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")
|
raw = resp.read().decode("utf-8", errors="replace")
|
||||||
payload = json.loads(raw)
|
payload = json.loads(raw)
|
||||||
except urllib.error.HTTPError as exc:
|
except urllib.error.HTTPError as exc:
|
||||||
@@ -299,7 +339,7 @@ def download_asset(
|
|||||||
asset.download_url,
|
asset.download_url,
|
||||||
headers={"User-Agent": f"BarcodeReaderServer/{APP_VERSION}"},
|
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)
|
total = int(resp.headers.get("Content-Length") or asset.size or 0)
|
||||||
downloaded = 0
|
downloaded = 0
|
||||||
with open(dest_path, "wb") as out:
|
with open(dest_path, "wb") as out:
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ APP_NAME = "Barcode Reader Server"
|
|||||||
APP_BINARY_NAME = "BarcodeServer"
|
APP_BINARY_NAME = "BarcodeServer"
|
||||||
APP_ID = "com.catellisrl.barcodereader"
|
APP_ID = "com.catellisrl.barcodereader"
|
||||||
APP_PUBLISHER = "Catelli Srl"
|
APP_PUBLISHER = "Catelli Srl"
|
||||||
APP_VERSION = "1.0.0"
|
APP_VERSION = "1.0.1"
|
||||||
|
|
||||||
GITEA_BASE_URL = "https://gitea.catelli.it"
|
GITEA_BASE_URL = "https://gitea.catelli.it"
|
||||||
GITEA_REPO = "brontomark/barcode_reader_pc"
|
GITEA_REPO = "brontomark/barcode_reader_pc"
|
||||||
|
|||||||
Reference in new issue
Block a user