all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Shannon Sterz" <s.sterz@proxmox.com>
To: "Dominik Csapak" <d.csapak@proxmox.com>,
	<pve-devel@lists.proxmox.com>, <pbs-devel@lists.proxmox.com>
Subject: Re: [PATCH proxmox v3 1/6] http: factor out openssl verification callback
Date: Thu, 25 Jun 2026 13:19:38 +0200	[thread overview]
Message-ID: <DJI38M9ZF4GP.1BD2DGE4RSPLG@proxmox.com> (raw)
In-Reply-To: <20260617085949.1528300-2-d.csapak@proxmox.com>

On Wed Jun 17, 2026 at 10:59 AM CEST, Dominik Csapak wrote:
> with the 'tls' feature offers a callback method that can be used within
> openssl's `set_verify_callback` with a given expected fingerprint.
>
> The logic is inspired by our perl and proxmox-websocket-tunnel
> verification logic:
>
> Use openssl's verification if no fingerprint is pinned. If a fingerprint
> is given, ignore openssl's verification and check if the leafs
> certificate is a match.
>
> This introduces a custom error type for this, since we need to handle
> errors differently for different users, e.g. pbs-client wants to be able
> to use a fingerprint cache and let the user accept it in interactive cli
> sessions. For this we want the 'thiserror' crate, so move it to the
> workspace Cargo.toml and depend from there. (also change this for
> proxmox-openid)
>
> One thing to note here is that  the APPLICATION_VERIFICATION error of
> openssl is used to mark the case where an untrusted root or intermediate
> certificate is trusted from the callback. When that happens, openssl
> might return true for the following certificates (if nothing else is
> wrong aside from a missing trust anchor), so the error is checked for
> this special value to determine if the openssl validation can be
> trusted.
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---

-->8 snip 8<--

> +/// Intended as an openssl verification callback.
> +///
> +/// The following things are checked:
> +///
> +/// * If no fingerprint is given, return the openssl verification result
> +/// * If a fingerprint is given, do:
> +///     * Ignore all non-leaf certificates/
> +pub fn openssl_verify_callback(
> +    openssl_valid: bool,
> +    ctx: &mut X509StoreContextRef,
> +    expected_fp: Option<&str>,
> +) -> Result<(), SslVerifyError> {
> +    let trust_openssl = ctx.error() != X509VerifyResult::APPLICATION_VERIFICATION;
> +    if expected_fp.is_none() && openssl_valid && trust_openssl {

i think this check could be simplified to

    if expected_fp.is_none() {
        return openssl_valid;
    }

checking `trust_openssl` only makes sense in a scenario where a chain is
being validated and we told OpenSSL to trust an otherwise untrusted
certificate so we can check the fingerprint of a certificate further
down the chain. so unless a fingerprint is added while verifying a
certificate chain, the extra checks just make this code harder to
understand. to my knowledge, this scenario can't happen.

or am i missing something here?

> +        return Ok(());
> +    }
> +
> +    let cert = match ctx.current_cert() {
> +        Some(cert) => cert,
> +        None => {
> +            return Err(SslVerifyError::NoCertificate);
> +        }
> +    };
> +
> +    if ctx.error_depth() > 0 {
> +        // openssl was not valid, but we want to continue, so save that we don't trust openssl
> +        ctx.set_error(X509VerifyResult::APPLICATION_VERIFICATION);
> +        return Ok(());
> +    }
> +
> +    let digest = cert
> +        .digest(openssl::hash::MessageDigest::sha256())
> +        .map_err(SslVerifyError::InvalidFingerprint)?;
> +    let fingerprint = get_fingerprint_from_u8(&digest);

imo, we should think about adding the `Fingerprint` type i already moved
from pdm/cli/client to the common pdm api-types in another series [1] to
either this crate or another crate that handles tls
(proxmox-acme-api/proxmox-client) and then re-use it here. then we don't
have to do the `to_lowercase()` dance manually and it would be more
efficient to use the actual fingerprint bytes instead of a string
representation.

the callback should then also take `Option<Fingerprint>` instead of an
`Option<&str>`.

[1]: https://lore.proxmox.com/pdm-devel/20260611120327.257523-9-s.sterz@proxmox.com/

-->8 snip 8<--




  reply	other threads:[~2026-06-25 11:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17  8:59 [PATCH proxmox{,-backup,-websocket-tunnel} v3 0/6] unify openssl callback logic Dominik Csapak
2026-06-17  8:59 ` [PATCH proxmox v3 1/6] http: factor out openssl verification callback Dominik Csapak
2026-06-25 11:19   ` Shannon Sterz [this message]
2026-06-17  8:59 ` [PATCH proxmox v3 2/6] http: tls: use legacy behavior when PROXMOX_NEW_TLS_CHECK is not set Dominik Csapak
2026-06-25 11:19   ` Shannon Sterz
2026-06-17  8:59 ` [PATCH proxmox v3 3/6] client: use proxmox-http's openssl verification callback Dominik Csapak
2026-06-25 11:19   ` Shannon Sterz
2026-06-17  8:59 ` [PATCH proxmox-backup v3 4/6] pbs-client: use proxmox-https openssl callback Dominik Csapak
2026-06-25 11:19   ` Shannon Sterz
2026-06-17  8:59 ` [PATCH proxmox-backup v3 5/6] pbs-client: honor already verified fingerprint Dominik Csapak
2026-06-17  8:59 ` [PATCH proxmox-websocket-tunnel v3 6/6] use proxmox-http's openssl callback Dominik Csapak
2026-06-25 11:19   ` Shannon Sterz
2026-06-25 11:19 ` [PATCH proxmox{,-backup,-websocket-tunnel} v3 0/6] unify openssl callback logic Shannon Sterz
2026-06-25 11:22   ` [PATCH proxmox 1/3] http: tls: move PROXMOX_NEW_TLS_CHECK env var name into constant Shannon Sterz
2026-06-25 11:22     ` [PATCH proxmox 2/3] http: tls: implement `PartialEq` for `SslVerifyError` Shannon Sterz
2026-06-25 11:22     ` [PATCH proxmox 3/3] http: tls: add integration tests for openssl verify callbacks Shannon Sterz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DJI38M9ZF4GP.1BD2DGE4RSPLG@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal