From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 0D0C61FF187 for ; Tue, 2 Dec 2025 12:25:47 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C5C39CF0A; Tue, 2 Dec 2025 12:26:11 +0100 (CET) From: Shannon Sterz To: pdm-devel@lists.proxmox.com Date: Tue, 2 Dec 2025 12:22:36 +0100 Message-ID: <20251202112235.215074-2-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1764674694804 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.092 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox] client: handle tls verification errors more gracefully X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" this makes it so that errors that previously would simply yield a "client error (Connect)" now show a more useful error message, such as: Could not establish a TLS connection. Check whether the fingerprint matches or the certificate is valid. OpenSSL Error: error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:../ssl/statem/statem_clnt.c:2123: this should help users figure out what's really happened more easily. Signed-off-by: Shannon Sterz --- there might also be one or two bugs hiding in how the client handles certificate validation. imo setting a fingerprint should override certificate validity and not the other way round. as it is somewhat akin to pinning a certificate. also as fabian pointed out in an off list discussion, the use of `current_cert` in `verify_fingerprint` may be wrong as it could yield a parent certificate if it is already unverifiable by openssl. this one would need some more investigation, though. left both of these as-is, as that seems like some bigger changes for right now. proxmox-client/src/client.rs | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/proxmox-client/src/client.rs b/proxmox-client/src/client.rs index da2c5c59..81af5681 100644 --- a/proxmox-client/src/client.rs +++ b/proxmox-client/src/client.rs @@ -242,10 +242,22 @@ impl Client { } .map_err(|err| Error::internal("failed to build request", err))?; - let response = client - .request(request) - .await - .map_err(|err| Error::Client(err.into()))?; + let response = client.request(request).await.map_err(|err| { + for err in err.chain() { + if let Some(err) = err.downcast_ref::() { + return Error::Client( + format!( + "Could not establish a TLS connection. Check \ + whether the fingerprint matches or the certificate is valid. \ + OpenSSL Error: {err}" + ) + .into(), + ); + } + } + + Error::Client(err.into()) + })?; if response.status() == StatusCode::UNAUTHORIZED { return Err(Error::Unauthorized); @@ -352,11 +364,23 @@ impl Client { .body(request.body.into()) .map_err(|err| Error::internal("error building login http request", err))?; - let api_response = self - .client - .request(request) - .await - .map_err(|err| Error::Client(err.into()))?; + let api_response = self.client.request(request).await.map_err(|err| { + for err in err.chain() { + if let Some(err) = err.downcast_ref::() { + return Error::Client( + format!( + "Could not establish a TLS connection. Check \ + whether the fingerprint matches or the certificate is valid. \ + OpenSSL Error: {err}" + ) + .into(), + ); + } + } + + Error::Client(err.into()) + })?; + if !api_response.status().is_success() { return Err(Error::api(api_response.status(), "authentication failed")); } -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel