public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: David Riley <d.riley@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: David Riley <d.riley@proxmox.com>
Subject: [PATCH pve-common v3 1/4] certificate: add helper to extract validity period
Date: Wed, 21 Oct 2026 11:52:26 +0200	[thread overview]
Message-ID: <20261021095229.50842-2-d.riley@proxmox.com> (raw)
In-Reply-To: <20261021095229.50842-1-d.riley@proxmox.com>

Previously, only the expiration timestamp was needed, so only notAfter
was parsed from the certificate.

To prepare for lifetime calculations, introduce a helper that extracts
both the notBefore and notAfter timestamps [0] in a single certificate
read. Adapt the existing expiration helper to consume it without any
change in behavior for existing callers.

[0] https://www.rfc-editor.org/info/rfc5280/#section-4.1

Signed-off-by: David Riley <d.riley@proxmox.com>
Reviewed-by: Michael Köppl <m.koeppl@proxmox.com>
Tested-by: Michael Köppl <m.koeppl@proxmox.com>
---
 src/PVE/Certificate.pm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Certificate.pm b/src/PVE/Certificate.pm
index b8415e2..8406949 100644
--- a/src/PVE/Certificate.pm
+++ b/src/PVE/Certificate.pm
@@ -331,16 +331,28 @@ sub get_certificate_info {
 # Obtain the expiration timestamp of a X.509 certificate as a UNIX epoch.
 sub get_expiration_as_epoch {
     my ($cert_path) = @_;
+    my (undef, $not_after) = get_validity_as_epoch($cert_path);
+    return $not_after;
+}
+
+# Obtain the notBefore and notAfter timestamps of a X.509 certificate as UNIX epochs.
+sub get_validity_as_epoch {
+    my ($cert_path) = @_;
 
     my $cert = $read_certificate->($cert_path);
-    my $not_after = eval { convert_asn1_to_epoch(Net::SSLeay::X509_get_notAfter($cert)) };
+    my ($not_before, $not_after) = eval {
+        (
+            convert_asn1_to_epoch(Net::SSLeay::X509_get_notBefore($cert)),
+            convert_asn1_to_epoch(Net::SSLeay::X509_get_notAfter($cert)),
+        );
+    };
     my $err = $@;
 
     Net::SSLeay::X509_free($cert);
 
     die $err if $err;
 
-    return $not_after;
+    return ($not_before, $not_after);
 }
 
 # Checks whether certificate expires before $timestamp (UNIX epoch)
-- 
2.47.3





  reply	other threads:[~2026-10-21  9:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  9:52 [PATCH common/manager v3 0/4] fix #8006: acme: lifetime-based certificate renewal threshold David Riley
2026-10-21  9:52 ` David Riley [this message]
2026-10-21  9:52 ` [PATCH pve-common v3 2/4] certificate: add helper for lifetime-based ACME renewal lead time David Riley
2026-10-21  9:52 ` [PATCH pve-manager v3 3/4] fix #8006: api: acme: use lifetime-based certificate " David Riley
2026-10-21  9:52 ` [PATCH pve-manager v3 4/4] fix #8006: pveupdate: use lifetime-based " David Riley

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=20261021095229.50842-2-d.riley@proxmox.com \
    --to=d.riley@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 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