From: David Riley <d.riley@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-common 1/2] certificate: add helpers for lifetime-based ACME renewal
Date: Tue, 6 Oct 2026 14:31:19 +0200 [thread overview]
Message-ID: <20261006123120.68750-2-d.riley@proxmox.com> (raw)
In-Reply-To: <20261006123120.68750-1-d.riley@proxmox.com>
Add helpers to calculate a renewal lead time based on the actual
lifetime of an X.509 certificate (the difference between its notBefore
and notAfter dates [0]).
This commit is in preparation for fixing #8006. The scaling mirrors
the logic already used in Proxmox Backup Server [1]: certificates
living for less than 10 days are renewed at half their lifetime,
while longer-lived certificates use a third of their lifetime.
Link: https://bugzilla.proxmox.com/show_bug.cgi?id=8006
[0] https://www.cs.auckland.ac.nz/~pgut001/pubs/x509guide.txt
[1] https://lore.proxmox.com/pbs-devel/20260423134607.105229-2-m.federanko@proxmox.com/
Signed-off-by: David Riley <d.riley@proxmox.com>
---
src/PVE/Certificate.pm | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/src/PVE/Certificate.pm b/src/PVE/Certificate.pm
index b8415e2..45c9bc7 100644
--- a/src/PVE/Certificate.pm
+++ b/src/PVE/Certificate.pm
@@ -328,6 +328,21 @@ sub get_certificate_info {
return $info;
}
+# Obtain the notBefore timestamp of a X.509 certificate as a UNIX epoch.
+sub get_not_before_as_epoch {
+ my ($cert_path) = @_;
+
+ my $cert = $read_certificate->($cert_path);
+ my $not_before = eval { convert_asn1_to_epoch(Net::SSLeay::X509_get_notBefore($cert)) };
+ my $err = $@;
+
+ Net::SSLeay::X509_free($cert);
+
+ die $err if $err;
+
+ return $not_before;
+}
+
# Obtain the expiration timestamp of a X.509 certificate as a UNIX epoch.
sub get_expiration_as_epoch {
my ($cert_path) = @_;
@@ -354,6 +369,22 @@ sub check_expiry {
return ($not_after < $timestamp) ? 1 : 0;
}
+sub get_cert_renew_lead_time {
+ my ($cert_path) = @_;
+
+ my $default_lead = 30 * 24 * 60 * 60;
+
+ my $not_before = get_not_before_as_epoch($cert_path);
+ my $not_after = get_expiration_as_epoch($cert_path);
+
+ my $lifetime = $not_after - $not_before;
+ return $default_lead if $lifetime <= 0;
+
+ my $scale = $lifetime < (10 * 24 * 60 * 60) ? 2 : 3;
+
+ return int($lifetime / $scale);
+}
+
# Create a CSR and certificate key for a given order
# returns path to CSR file or path to CSR and key files
sub generate_csr {
--
2.47.3
next prev parent reply other threads:[~2026-10-06 12:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 12:31 [PATCH common/manager 0/2] fix #8006: acme: lifetime-based certificate renewal threshold David Riley
2026-10-06 12:31 ` David Riley [this message]
2026-10-06 12:31 ` [PATCH pve-manager 2/2] fix #8006: api: " 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=20261006123120.68750-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 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.