public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH pve-common v2 02/16] certificate: add helper to verify that a certificate was signed by a ca
Date: Wed,  5 Aug 2026 15:18:25 +0200	[thread overview]
Message-ID: <20260805131838.254723-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20260805131838.254723-2-s.sterz@proxmox.com>

Signed-off-by: Shannon Sterz <s.sterz@proxmox.com>
---
 src/PVE/Certificate.pm | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/PVE/Certificate.pm b/src/PVE/Certificate.pm
index b8415e2..91b3c4d 100644
--- a/src/PVE/Certificate.pm
+++ b/src/PVE/Certificate.pm
@@ -260,6 +260,52 @@ sub assert_certificate_matches_key {
     return 1;
 }
 
+=head3 check_certificate_signed_by_ca()
+
+Checks whether the certificate at C<$cert_path> is signed by the CA certificate
+located at C<$ca_path>.
+
+=cut
+
+sub check_certificate_signed_by_ca {
+    my ($cert_path, $ca_path) = @_;
+    my @cleanup;
+
+    my $result = eval {
+        my $ca_cert = $read_certificate->($ca_path);
+        push @cleanup, sub { Net::SSLeay::X509_free($ca_cert) };
+
+        my $cert = $read_certificate->($cert_path);
+        push @cleanup, sub { Net::SSLeay::X509_free($cert) };
+
+        my $store = Net::SSLeay::X509_STORE_new()
+            or ssl_die("Could not create an SSL store to check if ca signed certificate");
+        push @cleanup, sub { Net::SSLeay::X509_STORE_free($store) };
+
+        Net::SSLeay::X509_STORE_add_cert($store, $ca_cert)
+            or ssl_die("Could not load ca certificate into context.");
+
+        my $ctx = Net::SSLeay::X509_STORE_CTX_new()
+            or ssl_die("Could not create an SSL context to check if ca signed certificate");
+        push @cleanup, sub { Net::SSLeay::X509_STORE_CTX_free($ctx) };
+
+        Net::SSLeay::X509_STORE_CTX_init($ctx, $store, $cert, 0)
+            or ssl_die("Could not initialize an SSL context to check if ca signed certificate");
+
+        Net::SSLeay::X509_verify_cert($ctx);
+    };
+
+    my $err = $@;
+
+    while (my $cleanup_fn = pop @cleanup) {
+        $cleanup_fn->();
+    }
+
+    die $err if $err;
+
+    return $result == 1;
+}
+
 sub get_certificate_info {
     my ($cert_path) = @_;
 
-- 
2.47.3





  parent reply	other threads:[~2026-08-05 13:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 13:18 [PATCH cluster/common/datacenter-manager/manager/proxmox v2 00/16] TLS Certificate Staging Shannon Sterz
2026-08-05 13:18 ` [PATCH cluster v2 01/16] setup: allow caller to provide the certificate filename Shannon Sterz
2026-08-05 13:18 ` Shannon Sterz [this message]
2026-08-05 13:18 ` [PATCH manager v2 03/16] bin/api: add a new staged certificate when renewing self-signed cert Shannon Sterz
2026-08-05 13:18 ` [PATCH manager v2 04/16] api: certificates: if node parameter is 'localhost' return local certs Shannon Sterz
2026-08-05 13:18 ` [PATCH proxmox v2 05/16] pve-api-types: expose certificates info endpoint Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 06/16] client: allow users to update a changed fingerprint interactively Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 07/16] cli/api-types: move Fingerprint to common api type crate Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 08/16] server: connection: report mismatching fingerprint as untrusted on probe Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 09/16] ui: wizard: add context if a provided fingerprint did not match remote Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 10/16] ui: wizard: nodes page: always update fingerprints on user confirmation Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 11/16] pdm-api-types: implement ApiType for Fingerprint Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 12/16] pdm-api-types: add staged_fingerprints field to NodeUrl Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 13/16] server: remotes: lock remotes config when updating it Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 14/16] server: connection: rotate in staged fingerprints when encountering them Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 15/16] server: api: tasks: move `spawn_aborted_on_shutdown()` to super module Shannon Sterz
2026-08-05 13:18 ` [PATCH datacenter-manager v2 16/16] server: bin: api: tasks: add task to discover new staged certificates 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=20260805131838.254723-4-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pdm-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal