]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: acme: acme_will_expire() uses acme_schedule_date()
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 25 Sep 2025 13:14:31 +0000 (15:14 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 25 Sep 2025 13:14:31 +0000 (15:14 +0200)
Date computation between acme_will_expire() and acme_schedule_date() are
the same. Call acme_schedule_date() from acme_will_expire() and put the
functions as static. The patch also move the functions in the right
order.

src/acme.c

index d021638388c8b9a7660db73f86351b8dd21e1ad2..abf79b846d0466637d1c3cd5dcce4cebf307a3ef 100644 (file)
@@ -2346,16 +2346,20 @@ wait:
        MT_LIST_UNLOCK_FULL(&ctx->el, tmp);
        return task;
 }
+
 /*
- * Return 1 if the certificate must be regenerated
- * Check if the notAfter date will append in (validity period / 12) or 7 days per default
+ * Return when the next task is scheduled
+ * Check if the notAfter date will happen in (validity period / 12) or 7 days per default
  */
-int acme_will_expire(struct ckch_store *store)
+static time_t acme_schedule_date(struct ckch_store *store)
 {
        time_t diff = 0;
        time_t notAfter = 0;
        time_t notBefore = 0;
 
+       if (!global_ssl.acme_scheduler)
+               return 0;
+
        /* compute the validity period of the leaf certificate */
        if (!store->data || !store->data->cert)
                return 0;
@@ -2370,40 +2374,27 @@ int acme_will_expire(struct ckch_store *store)
                diff = 7 * 24 * 60 * 60; /* default to 7 days */
        }
 
-       if (notAfter - diff <= date.tv_sec)
-               return 1;
-
-       return 0;
+       return (notAfter - diff);
 }
 
 /*
- * Return when the next task is scheduled
- * Check if the notAfter date will happen in (validity period / 12) or 7 days per default
+ * Return 1 if the certificate must be regenerated
+ * Check if the notAfter date will append in (validity period / 12) or 7 days per default
  */
-time_t acme_schedule_date(struct ckch_store *store)
+static int acme_will_expire(struct ckch_store *store)
 {
-       time_t diff = 0;
        time_t notAfter = 0;
-       time_t notBefore = 0;
-
-       if (!global_ssl.acme_scheduler)
-               return 0;
 
        /* compute the validity period of the leaf certificate */
        if (!store->data || !store->data->cert)
                return 0;
 
-       notAfter = x509_get_notafter_time_t(store->data->cert);
-       notBefore = x509_get_notbefore_time_t(store->data->cert);
+       notAfter = acme_schedule_date(store);
 
-       if ((notAfter >= 0 && notBefore >= 0)
-          && (notAfter > notBefore)) {
-               diff = (notAfter - notBefore) / 12; /* validity period / 12 */
-       } else {
-               diff = 7 * 24 * 60 * 60; /* default to 7 days */
-       }
+       if (notAfter <= date.tv_sec)
+               return 1;
 
-       return (notAfter - diff);
+       return 0;
 }
 
 /* Does the scheduling of the ACME tasks