From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 7337E1FF0ED for ; Fri, 31 Jul 2026 16:45:05 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 42051215B1; Fri, 31 Jul 2026 16:45:05 +0200 (CEST) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 31 Jul 2026 16:44:57 +0200 Message-Id: Subject: Re: [PATCH datacenter-manager 07/15] server: connection: report mismatching fingerprint as untrusted on probe To: "Shannon Sterz" , X-Mailer: aerc 0.20.0 References: <20260731091655.93282-1-s.sterz@proxmox.com> <20260731091655.93282-8-s.sterz@proxmox.com> In-Reply-To: <20260731091655.93282-8-s.sterz@proxmox.com> From: "Shannon Sterz" X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1785509087173 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.144 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ZAWW4RF6Y3RXBL45VE7TSQQJTLSZ22CL X-Message-ID-Hash: ZAWW4RF6Y3RXBL45VE7TSQQJTLSZ22CL X-MailFrom: s.sterz@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri Jul 31, 2026 at 11:16 AM CEST, Shannon Sterz wrote: > instead of erroring out. previously this function returned a > connection error if the provided fingerprint did not match the > remote's fingerprint. instead, report the certificate as untrusted, > giving client's more appropriate information in such cases. > > note that while the documentation for this function was technically > correct, the probe_tls endpoints for pve and pbs remotes stated: > >> If the certificate is not trusted with the given parameters, returns >> the certificate information. > > however, that was incorrect, since the endpoints returned an error if > the fingerprint did not match. since those two endpoints are currently > the only users that could actually provide a fingerprint (all other > callers explicitly provide `None`), this is more of a bug fix than a > public api break. > > Signed-off-by: Shannon Sterz > --- > server/src/connection.rs | 62 ++++++++++++++++++++++++++++------------ > 1 file changed, 43 insertions(+), 19 deletions(-) > > diff --git a/server/src/connection.rs b/server/src/connection.rs > index f635b74e..51bbb611 100644 > --- a/server/src/connection.rs > +++ b/server/src/connection.rs > @@ -15,6 +15,7 @@ use std::time::{Duration, SystemTime}; > use anyhow::{Error, bail, format_err}; > use http::Method; > use http::uri::Authority; > +use openssl::hash::MessageDigest; > use openssl::x509::X509StoreContextRef; > use serde::Serialize; > > @@ -22,6 +23,7 @@ use proxmox_acme_api::CertificateInfo; > use proxmox_client::{Client, HttpApiClient, HttpApiResponse, HttpApiResp= onseStream, TlsOptions}; > use proxmox_time::epoch_i64; > > +use pdm_api_types::Fingerprint; > use pdm_api_types::remotes::{NodeUrl, Remote, RemoteType, TlsProbeOutcom= e}; > use pve_api_types::client::PveClientImpl; > > @@ -929,7 +931,7 @@ impl HttpApiClient for MultiClient { > /// Checks TLS connection to the given remote > /// > /// Returns `Ok(TlsProbeOutcome::TrustedCertificate)` if connecting with= the given parameters works > -/// Returns `Ok(TlsProbeOutcome::UntrustedCertificate)` if no fingerprin= t was given and some certificate could not be validated > +/// Returns `Ok(TlsProbeOutcome::UntrustedCertificate)` if the provided = fingerprint does not match or a certificate could not be validated > /// Returns `Err(err)` if some other error occurred > /// > /// # Example > @@ -964,25 +966,47 @@ pub async fn probe_tls_connection( > // to save the invalid cert we find > let invalid_cert =3D Arc::new(StdMutex::new(None)); > > - let options =3D if let Some(fp) =3D &fingerprint { > - TlsOptions::parse_fingerprint(fp)? > - } else { > - TlsOptions::Callback(Box::new({ > - let invalid_cert =3D invalid_cert.clone(); > - move |valid: bool, chain: &mut X509StoreContextRef| { > - if let Some(cert) =3D chain.current_cert() { > - if !valid { > - let cert =3D cert > - .to_pem() > - .map_err(Error::from) > - .and_then(|pem| CertificateInfo::from_pem(""= , &pem)); > - *invalid_cert.lock().unwrap() =3D Some(cert); > - } > - } > - true > + let fingerprint =3D fingerprint > + .map(|fp| fp.parse::()) > + .transpose()?; > + > + let options =3D TlsOptions::Callback(Box::new({ > + let invalid_cert =3D invalid_cert.clone(); > + move |valid: bool, chain: &mut X509StoreContextRef| { > + // If no fingerprint was provided and the trust store trusts= the certificate, the > + // connection is valid. > + if fingerprint.is_none() && valid { > + return true; > } > - })) > - }; > + > + let Some(cert) =3D chain.current_cert() else { something i just noticed is that this here should also always get the leaf certificate. sorry for missing that, i'll clean that up in a v2 for the record, all that needs to change is that the above line should read: let Some(cert) =3D chain.chain().and_then(|c| c.get(0)) else { to renaming the (pre-existing) chain parameter to "context" or similar would probably also help with clarity here. > + return true; > + }; > + > + // If a fingerprint was provided and the certificate matches= it, the connection is > + // valid. > + if let Some(provided_fp) =3D &fingerprint { > + if cert > + .digest(MessageDigest::sha256()) > + .map(|fp| *fp =3D=3D **provided_fp) > + .unwrap_or(false) > + { > + return true; > + } > + } > + > + // Otherwise, the certificate is not trusted. > + let cert =3D cert > + .to_pem() > + .map_err(Error::from) > + .and_then(|pem| CertificateInfo::from_pem("", &pem)); > + > + *invalid_cert.lock().unwrap() =3D Some(cert); > + > + true > + } > + })); > + > let client =3D proxmox_client::Client::with_options(uri, options, De= fault::default())?; > > // set fake auth info. we don't need any, but the proxmox client wil= l return unauthenticated if