From 7b78e4a88e08b90e6d9219f3dd15016133cdfe76 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Tue, 22 Sep 2026 18:30:35 +0900 Subject: [PATCH] fix: surface the real OpenSSL error instead of a generic TLS message _request()'s ssl.SSLCertVerificationError handler hardcoded "certificate verification failed" regardless of cause, discarding e.verify_message/ e.reason (standard OpenSSL diagnostic text - never a secret) - exactly what's needed to tell a wrong CA, expired cert, clock skew, and a hostname mismatch apart. Found while diagnosing a live addKey TLS failure on minisforum that doesn't reproduce from this machine (same CA file, same pinned IP, same SNI hostname - openssl s_client and a direct repro of get_pinned() both succeed here), so the next attempt needs the real reason, not a collapsed generic string. Also stopped discarding detail on the generic SSLError/OSError branches. Verified: forcing a real verification failure (wrong CA) now reports "unable to get local issuer certificate" instead of the old generic text. Full test suite still passes (86/86). Co-Authored-By: Claude Sonnet 5 --- ansible/roles/pia-gateway/files/pia_gateway.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ansible/roles/pia-gateway/files/pia_gateway.py b/ansible/roles/pia-gateway/files/pia_gateway.py index 2b81a4e..1c26fa5 100644 --- a/ansible/roles/pia-gateway/files/pia_gateway.py +++ b/ansible/roles/pia-gateway/files/pia_gateway.py @@ -785,13 +785,22 @@ class HttpClient: data = resp.read(4_000_000) return resp.status, data except ssl.SSLCertVerificationError as e: - raise ApiError("tls", "certificate verification failed") from e + # verify_message/reason are standard OpenSSL diagnostic text + # (e.g. "unable to get local issuer certificate", "certificate + # has expired", a hostname mismatch) — never a secret, and + # exactly what's needed to tell "wrong CA", "expired cert", + # "clock skew", and "hostname mismatch" apart instead of + # collapsing all of them into one opaque string. + detail = e.verify_message or e.reason or str(e) or "certificate verification failed" + raise ApiError("tls", detail) from e except ssl.SSLError as e: - raise ApiError("tls", e.__class__.__name__) from e + detail = getattr(e, "reason", None) or str(e) or e.__class__.__name__ + raise ApiError("tls", f"{e.__class__.__name__}: {detail}") from e except socket.timeout as e: raise ApiError("timeout", "request timed out") from e except (OSError, http.client.HTTPException) as e: - raise ApiError("network", e.__class__.__name__) from e + detail = str(e) or e.__class__.__name__ + raise ApiError("network", f"{e.__class__.__name__}: {detail}") from e finally: with contextlib.suppress(Exception): conn.close()