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()