From 3d1f422cd326f6cf711792151fac1e69bca92c0d Mon Sep 17 00:00:00 2001 From: Color Dumper <156731588+ColorDumper@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:31:25 -0500 Subject: [PATCH 1/4] Have Windows check GitHub's certificates for updates --- CHANGELOG.md | 8 +++ maphide/updates.py | 52 ++++++++++++++---- requirements-dev.txt | 4 ++ requirements.in | 3 ++ requirements.txt | 4 ++ tests/test_updates.py | 123 ++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 181 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee0d44f..3073464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to MapHide are documented here. +## Unreleased + +### Fixed + +- Fixed Update saying the download didn't finish on some PCs, often ones with a fairly new Windows install. +- Fixed update checks telling you to check your internet connection when the real problem was your PC's date and time, or GitHub's certificate. +- Fixed the debug log leaving out why an update check or download failed. + ## [v0.3.0](https://github.com/ColorDumper/MapHide/compare/v0.2.6...v0.3.0) - 2026-11-13 ### Added diff --git a/maphide/updates.py b/maphide/updates.py index 1eaa792..6f88f30 100644 --- a/maphide/updates.py +++ b/maphide/updates.py @@ -12,6 +12,7 @@ import json import os import re +import ssl import subprocess import sys import tempfile @@ -21,6 +22,9 @@ from dataclasses import dataclass from pathlib import Path +import truststore + +from .logs import describe_exception, logger from .version import CHANNEL, CHANNEL_GITHUB, CHANNEL_SOURCE, VERSION REPO = "ColorDumper/MapHide" @@ -46,6 +50,12 @@ DOWNLOAD_DAMAGED = "The download was damaged. Try again." INSTALLER_DIDNT_START = "The installer couldn't start." CHECK_FAILED = "Couldn't check for updates." +CLOCK_WRONG = "Your PC's date and time look wrong. Fix them in Windows settings and try again." +CERTIFICATE_REFUSED = "Windows couldn't confirm the connection to GitHub is safe. Try again later." + +# Certificate errors that usually mean the PC's clock is wrong: Windows' +# "outside its validity period", and OpenSSL's "not yet valid" and "expired". +CLOCK_ERROR_CODES = frozenset({0x800B0101, 9, 10}) # Updater states. IDLE = "idle" @@ -115,8 +125,26 @@ def redirect_request(self, req, fp, code, msg, headers, newurl): return super().redirect_request(req, fp, code, msg, headers, newurl) +def _https_context(): + """Windows checks GitHub's certificates, as it does for a browser. It + then fetches a trusted root it doesn't have yet, which a fairly new + Windows may be missing, instead of the connection being refused.""" + return truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT) + + # How MapHide goes online: https only, redirects included. -OPENER = urllib.request.build_opener(HttpsOnlyRedirects()) +OPENER = urllib.request.build_opener( + urllib.request.HTTPSHandler(context=_https_context()), HttpsOnlyRedirects() +) + + +def _certificate_message(exc): + """What to tell the user when `exc` is a certificate being refused, or + None when it's something else.""" + reason = getattr(exc, "reason", exc) + if not isinstance(reason, ssl.SSLCertVerificationError): + return None + return CLOCK_WRONG if reason.verify_code in CLOCK_ERROR_CODES else CERTIFICATE_REFUSED def _request(url): @@ -140,9 +168,9 @@ def fetch_latest(opener=OPENER.open): # too many checks from this network in the last hour. raise UpdateError(GITHUB_UNAVAILABLE) from exc except (urllib.error.URLError, TimeoutError, ConnectionError) as exc: - raise UpdateError(NO_CONNECTION) from exc + raise UpdateError(_certificate_message(exc) or NO_CONNECTION) from exc except (ValueError, OSError) as exc: - raise UpdateError(UNEXPECTED_REPLY) from exc + raise UpdateError(_certificate_message(exc) or UNEXPECTED_REPLY) from exc return release_from_json(data) @@ -178,7 +206,7 @@ def download_setup(release, folder, progress=None, opener=OPENER.open): raise except (urllib.error.URLError, TimeoutError, OSError) as exc: partial.unlink(missing_ok=True) - raise UpdateError(DOWNLOAD_FAILED) from exc + raise UpdateError(_certificate_message(exc) or DOWNLOAD_FAILED) from exc return target @@ -333,18 +361,24 @@ def _set(self, state, message=""): self.message = message self._on_change() - def _run(self, work, on_done): + def _run(self, step, work, on_done): """Run `work()` off the window's thread, then `on_done(result, - error)` back on it.""" + error)` back on it. `step` names it in the debug log.""" outcome = [] def run(): try: outcome.append((work(), None)) except UpdateError as exc: + # The window shows the plain message; the debug log gets + # what actually went wrong. + logger.warning( + "Update %s failed: %s", step, describe_exception(exc.__cause__ or exc) + ) outcome.append((None, str(exc))) - except Exception: + except Exception as exc: # A bug here must still end the wait in the window. + logger.error("Update %s failed: %s", step, describe_exception(exc)) outcome.append((None, CHECK_FAILED)) def wait(): @@ -385,7 +419,7 @@ def work(): self._clean(self._folder) return self._fetch() - self._run(work, done) + self._run("check", work, done) return True def clear_latest(self): @@ -418,5 +452,5 @@ def done(_result, error): self.progress = 0.0 self._set(DOWNLOADING) - self._run(work, done) + self._run("download", work, done) return True diff --git a/requirements-dev.txt b/requirements-dev.txt index 8500f5f..7afd574 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -210,6 +210,10 @@ shiboken6==6.12.0 \ --hash=sha256:da382e68f0815b31b6dc2bce11a465b148c4f42c37b91546a361de1576567d10 \ --hash=sha256:ff72a72b3277b418902d562b987b33a6f6818bed9fe40a49d634d09bc67f620e # via pyside6-essentials +truststore==0.10.5 \ + --hash=sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd \ + --hash=sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c + # via -r requirements.in websocket-client==1.9.2 \ --hash=sha256:0fcb57545848be86992e128218fd96dd87a6769ffdb1a968dff79632b85604d0 \ --hash=sha256:e1a673830a9c7bfa47b1cd3d5e4178f4c9651d80a4eab02c9c23a1c3ec6250ce diff --git a/requirements.in b/requirements.in index 3c567af..4cf6725 100644 --- a/requirements.in +++ b/requirements.in @@ -11,3 +11,6 @@ websocket-client==1.9.2 # The window and tray icon. Essentials is the core of Qt without the # extra modules MapHide doesn't use. PySide6-Essentials==6.12.0 +# Lets Windows check GitHub's certificates for update checks and downloads, +# so a trusted root Windows hasn't downloaded yet is fetched, not refused. +truststore==0.10.5 diff --git a/requirements.txt b/requirements.txt index a05b7ed..00f8982 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,10 @@ shiboken6==6.12.0 \ --hash=sha256:da382e68f0815b31b6dc2bce11a465b148c4f42c37b91546a361de1576567d10 \ --hash=sha256:ff72a72b3277b418902d562b987b33a6f6818bed9fe40a49d634d09bc67f620e # via pyside6-essentials +truststore==0.10.5 \ + --hash=sha256:30d36967ccaded5cbb38d602c433f53600036c79d502f4533a49b60a03bbefcd \ + --hash=sha256:9aaaedaefaf06d8b206278cf8b5012bc897f485a874503501e12d776df78951c + # via -r requirements.in websocket-client==1.9.2 \ --hash=sha256:0fcb57545848be86992e128218fd96dd87a6769ffdb1a968dff79632b85604d0 \ --hash=sha256:e1a673830a9c7bfa47b1cd3d5e4178f4c9651d80a4eab02c9c23a1c3ec6250ce diff --git a/tests/test_updates.py b/tests/test_updates.py index 25499b1..30ac3ab 100644 --- a/tests/test_updates.py +++ b/tests/test_updates.py @@ -3,15 +3,18 @@ import hashlib import io import json +import logging +import ssl import threading import time import urllib.error import urllib.request import pytest +import truststore from test_controller import ManualScheduler -from maphide import updates +from maphide import logs, updates from maphide.updates import ( AVAILABLE, CHECKING, @@ -83,6 +86,19 @@ def opener(request, timeout): return opener +# Windows' code for a certificate outside its dates, and OpenSSL's for "not +# yet valid" and "expired". Each usually means the PC's clock is wrong. +CLOCK_CODES = [0x800B0101, 9, 10] +# Windows' "untrusted root", and OpenSSL's "unable to get local issuer". +OTHER_CERTIFICATE_CODES = [0x800B0109, 20] + + +def certificate_refused(code, wrapped=True): + error = ssl.SSLCertVerificationError("certificate refused") + error.verify_code = code + return urllib.error.URLError(error) if wrapped else error + + # Versions. @@ -165,6 +181,24 @@ def test_a_garbled_reply_is_explained(): fetch_latest(opener_returning(b"")) +@pytest.mark.parametrize("code", CLOCK_CODES) +@pytest.mark.parametrize("wrapped", [True, False]) +def test_a_check_refused_over_the_clock_says_to_fix_the_clock(code, wrapped): + with pytest.raises(UpdateError) as caught: + fetch_latest(opener_raising(certificate_refused(code, wrapped))) + + assert str(caught.value) == updates.CLOCK_WRONG + + +@pytest.mark.parametrize("code", OTHER_CERTIFICATE_CODES) +@pytest.mark.parametrize("wrapped", [True, False]) +def test_a_check_refused_over_a_certificate_says_so(code, wrapped): + with pytest.raises(UpdateError) as caught: + fetch_latest(opener_raising(certificate_refused(code, wrapped))) + + assert str(caught.value) == updates.CERTIFICATE_REFUSED + + # Downloading. @@ -197,6 +231,21 @@ def test_a_broken_download_is_thrown_away(tmp_path): assert list(tmp_path.iterdir()) == [] +@pytest.mark.parametrize( + ("code", "message"), + [(code, updates.CLOCK_WRONG) for code in CLOCK_CODES] + + [(code, updates.CERTIFICATE_REFUSED) for code in OTHER_CERTIFICATE_CODES], +) +def test_a_download_refused_over_a_certificate_says_why(tmp_path, code, message): + release = release_from_json(release_json()) + + with pytest.raises(UpdateError) as caught: + download_setup(release, tmp_path, opener=opener_raising(certificate_refused(code))) + + assert str(caught.value) == message + assert list(tmp_path.iterdir()) == [] + + def test_only_this_projects_releases_are_downloaded(tmp_path): release = Release("0.3.0", "https://example.com/setup.exe", 1, SETUP_SHA) @@ -238,6 +287,16 @@ def test_maphide_goes_online_only_through_the_https_only_redirects(): assert any(isinstance(handler, updates.HttpsOnlyRedirects) for handler in handlers) +def test_windows_checks_githubs_certificates(): + # So Windows fetches a trusted root it doesn't have yet, which GitHub's + # download server may need, instead of MapHide refusing the download. + [https] = [h for h in updates.OPENER.handlers if isinstance(h, urllib.request.HTTPSHandler)] + + assert isinstance(https._context, truststore.SSLContext) + assert https._context.check_hostname + assert https._context.verify_mode == ssl.CERT_REQUIRED + + def test_the_setup_file_is_checked_again_just_before_it_runs(tmp_path): path = tmp_path / "MapHide-v0.3.0-setup.exe" path.write_bytes(SETUP_BYTES) @@ -383,12 +442,14 @@ def test_only_an_installed_github_copy_installs_updates(tmp_path): class Steps: - def __init__(self, release=None, error=None, can_install=True): + def __init__(self, release=None, error=None, can_install=True, cause=None): self.schedule = ManualScheduler() self.changes = 0 self.downloads = [] self.launched = [] self.download_error = None + # What went wrong underneath, as fetch and download pass it on. + self.cause = cause self.verify_error = None self.verified = [] self.cleaned = [] @@ -417,12 +478,12 @@ def _changed(self): def _fetch(self): if self.error: - raise UpdateError(self.error) + raise UpdateError(self.error) from self.cause return self.release def _download(self, release, folder, progress): if self.download_error: - raise UpdateError(self.download_error) + raise UpdateError(self.download_error) from self.cause self.downloads.append((release.version, folder)) progress(1.0) return "setup.exe" @@ -493,6 +554,60 @@ def test_a_failed_check_says_why(): assert (s.updater.state, s.updater.message) == (FAILED, updates.NO_CONNECTION) +@pytest.fixture +def debug_log(): + """What MapHide writes to its debug log, as if it were turned on.""" + lines = [] + handler = logging.Handler() + handler.emit = lambda record: lines.append(record.getMessage()) + level = logs.logger.level + logs.logger.addHandler(handler) + logs.logger.setLevel(logging.INFO) + yield lines + logs.logger.removeHandler(handler) + logs.logger.setLevel(level) + + +def test_a_failed_check_writes_the_real_error_to_the_debug_log(debug_log): + s = Steps(error=updates.CERTIFICATE_REFUSED, cause=certificate_refused(0x800B0109)) + + s.updater.check(quiet=True) + s.finish() + + [line] = debug_log + assert line.startswith("Update check failed: URLError") + assert "certificate refused" in line + + +def test_a_failed_download_writes_the_real_error_to_the_debug_log(debug_log): + s = Steps(cause=ConnectionResetError(10054, "connection reset")) + s.updater.check() + s.finish() + s.download_error = updates.DOWNLOAD_FAILED + + s.updater.install(on_started=lambda: None) + s.finish() + + [line] = debug_log + assert line.startswith("Update download failed: ConnectionResetError") + assert "connection reset" in line + + +def test_a_bug_in_the_updater_is_written_to_the_debug_log(debug_log): + s = Steps() + + def broken(): + raise RuntimeError("a bug") + + s.updater._fetch = broken + s.updater.check() + s.finish() + + assert s.updater.message == updates.CHECK_FAILED + [line] = debug_log + assert line.startswith("Update check failed: RuntimeError: a bug") + + def test_a_quiet_check_that_fails_says_nothing(): s = Steps(error=updates.NO_CONNECTION) From 2f814943f7fc5de2a29412248d0073461a6de91f Mon Sep 17 00:00:00 2001 From: Color Dumper <156731588+ColorDumper@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:31:28 -0500 Subject: [PATCH 2/4] Name the OBS Source Name field in its required message --- CHANGELOG.md | 1 + maphide/config.py | 2 +- tests/test_config.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3073464..2d7b76b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to MapHide are documented here. - Fixed Update saying the download didn't finish on some PCs, often ones with a fairly new Windows install. - Fixed update checks telling you to check your internet connection when the real problem was your PC's date and time, or GitHub's certificate. - Fixed the debug log leaving out why an update check or download failed. +- Fixed the message for an empty OBS Source Name in Settings naming a field that doesn't exist. ## [v0.3.0](https://github.com/ColorDumper/MapHide/compare/v0.2.6...v0.3.0) - 2026-11-13 diff --git a/maphide/config.py b/maphide/config.py index c990e2f..c28b050 100644 --- a/maphide/config.py +++ b/maphide/config.py @@ -221,7 +221,7 @@ def config_from_form( hide_hotkey = str(hide_hotkey).strip().upper() if not scene_item_name: - raise ValueError("Overlay Source is required.") + raise ValueError("OBS Source Name is required.") if not is_valid_show_hotkey(hotkey): raise ValueError(SHOW_KEY_HELP) if toggle_mode and not is_valid_hide_hotkey(hide_hotkey): diff --git a/tests/test_config.py b/tests/test_config.py index 68c6534..06b8651 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -274,7 +274,7 @@ def test_a_filled_in_form_becomes_settings(): [ ("host", " ", "OBS Host is required."), ("port", "", "OBS Port is required."), - ("scene_item_name", "", "Overlay Source is required."), + ("scene_item_name", "", "OBS Source Name is required."), ("hotkey", "ESC", "Show key supports A-Z."), ("port", "44a5", "OBS Port must be a number."), ("port", "0", "OBS Port must be between 1 and 65535."), From 3c54deba75e8cdf574034c2876dbad9bf8d123a2 Mon Sep 17 00:00:00 2001 From: Color Dumper <156731588+ColorDumper@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:31:33 -0500 Subject: [PATCH 3/4] Keep settings in AppData Roaming when APPDATA is not set --- CHANGELOG.md | 1 + maphide/paths.py | 13 ++++++++++++- tests/test_paths.py | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/test_paths.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d7b76b..736894e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to MapHide are documented here. - Fixed update checks telling you to check your internet connection when the real problem was your PC's date and time, or GitHub's certificate. - Fixed the debug log leaving out why an update check or download failed. - Fixed the message for an empty OBS Source Name in Settings naming a field that doesn't exist. +- Fixed settings being saved in MapHide's own folder, instead of your AppData folder, on a PC where Windows doesn't say where AppData is. ## [v0.3.0](https://github.com/ColorDumper/MapHide/compare/v0.2.6...v0.3.0) - 2026-11-13 diff --git a/maphide/paths.py b/maphide/paths.py index da0475e..e0bece1 100644 --- a/maphide/paths.py +++ b/maphide/paths.py @@ -13,7 +13,18 @@ # entry point are in the parent directory. APP_DIR = Path(__file__).resolve().parent.parent APP_NAME = "MapHide" -CONFIG_DIR = Path(os.getenv("APPDATA", APP_DIR)) / APP_NAME + + +def config_dir(environ=os.environ, home=Path.home): + """MapHide's settings folder, in the user's AppData\\Roaming. Found from + the home folder when the APPDATA variable is missing, so settings never + land in the program's own folder.""" + appdata = environ.get("APPDATA") + root = Path(appdata) if appdata else home() / "AppData" / "Roaming" + return root / APP_NAME + + +CONFIG_DIR = config_dir() CONFIG_PATH = CONFIG_DIR / "config.json" LEGACY_CONFIG_PATH = APP_DIR / "config.json" ICON_ICO_PATH = APP_DIR / "MapHide.ico" diff --git a/tests/test_paths.py b/tests/test_paths.py new file mode 100644 index 0000000..4e864e6 --- /dev/null +++ b/tests/test_paths.py @@ -0,0 +1,20 @@ +"""Tests for where MapHide keeps its settings.""" + +from pathlib import Path + +import pytest + +from maphide.paths import config_dir + + +def test_settings_live_in_the_appdata_folder(): + folder = config_dir({"APPDATA": r"C:\Users\Someone\AppData\Roaming"}) + + assert folder == Path(r"C:\Users\Someone\AppData\Roaming\MapHide") + + +@pytest.mark.parametrize("environ", [{}, {"APPDATA": ""}]) +def test_without_appdata_settings_still_go_to_appdata_roaming(environ): + folder = config_dir(environ, home=lambda: Path(r"C:\Users\Someone")) + + assert folder == Path(r"C:\Users\Someone\AppData\Roaming\MapHide") From 711f473402a11b8b505316be8173d628cf40ed5d Mon Sep 17 00:00:00 2001 From: Color Dumper <156731588+ColorDumper@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:58:45 -0500 Subject: [PATCH 4/4] Release v0.3.1 --- CHANGELOG.md | 12 ++++++------ maphide/version.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 736894e..37178b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,15 @@ All notable changes to MapHide are documented here. -## Unreleased +## [v0.3.1](https://github.com/ColorDumper/MapHide/compare/v0.3.0...v0.3.1) - 2026-11-19 ### Fixed -- Fixed Update saying the download didn't finish on some PCs, often ones with a fairly new Windows install. -- Fixed update checks telling you to check your internet connection when the real problem was your PC's date and time, or GitHub's certificate. -- Fixed the debug log leaving out why an update check or download failed. -- Fixed the message for an empty OBS Source Name in Settings naming a field that doesn't exist. -- Fixed settings being saved in MapHide's own folder, instead of your AppData folder, on a PC where Windows doesn't say where AppData is. +- Fixed Update saying the download didn't finish on some PCs, often ones with a fairly new Windows install. ([3d1f422](https://github.com/ColorDumper/MapHide/commit/3d1f422cd326f6cf711792151fac1e69bca92c0d)) +- Fixed update checks telling you to check your internet connection when the real problem was your PC's date and time, or GitHub's certificate. ([3d1f422](https://github.com/ColorDumper/MapHide/commit/3d1f422cd326f6cf711792151fac1e69bca92c0d)) +- Fixed the debug log leaving out why an update check or download failed. ([3d1f422](https://github.com/ColorDumper/MapHide/commit/3d1f422cd326f6cf711792151fac1e69bca92c0d)) +- Fixed the message for an empty OBS Source Name in Settings naming a field that doesn't exist. ([2f81494](https://github.com/ColorDumper/MapHide/commit/2f814943f7fc5de2a29412248d0073461a6de91f)) +- Fixed settings being saved in MapHide's own folder, instead of your AppData folder, on a PC where Windows doesn't say where AppData is. ([3c54deb](https://github.com/ColorDumper/MapHide/commit/3c54deba75e8cdf574034c2876dbad9bf8d123a2)) ## [v0.3.0](https://github.com/ColorDumper/MapHide/compare/v0.2.6...v0.3.0) - 2026-11-13 diff --git a/maphide/version.py b/maphide/version.py index 26d9a4f..8932d68 100644 --- a/maphide/version.py +++ b/maphide/version.py @@ -9,7 +9,7 @@ from .paths import APP_DIR -VERSION = "0.3.0" +VERSION = "0.3.1" APP_VERSION = f"v{VERSION}" # Where a packaged copy came from. The build writes one of these into