]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: acme: use a customized proxy
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 23 Apr 2025 13:37:57 +0000 (15:37 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Wed, 23 Apr 2025 13:37:57 +0000 (15:37 +0200)
Use a customized proxy for the ACME client.

The proxy is initialized at the first acme section parsed.

The proxy uses the httpsclient log format as ACME CA use HTTPS.

src/acme.c

index ce0f495cf7fa369cddad7934381c94c741b50437..7bb3fc1cd0b9b4723b98a49bbc84a65082c6a147 100644 (file)
@@ -37,6 +37,8 @@
 static struct acme_cfg *acme_cfgs = NULL;
 static struct acme_cfg *cur_acme = NULL;
 
+static struct proxy *httpclient_acme_px = NULL;
+
 /* Return an existing acme_cfg section */
 struct acme_cfg *get_acme_cfg(const char *name)
 {
@@ -115,6 +117,17 @@ error:
        return err_code;
 }
 
+/* Initialize the proxy for the ACME HTTP client */
+static int httpclient_acme_init()
+{
+       httpclient_acme_px = httpclient_create_proxy("<ACME>");
+       if (!httpclient_acme_px)
+               return ERR_FATAL;
+       httpclient_acme_px->logformat.str = httpsclient_log_format; /* ACME server are always SSL */
+
+       return ERR_NONE;
+}
+
 
 /* acme section parser
  * Fill the acme_cfgs linked list
@@ -146,6 +159,14 @@ static int cfg_parse_acme(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
+               if (httpclient_acme_px == NULL) {
+                       if (httpclient_acme_init() & ERR_FATAL) {
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum);
+                               goto out;
+                       }
+               }
+
                cur_acme = new_acme_cfg(args[1]);
                if (!cur_acme) {
                        err_code |= ERR_ALERT | ERR_FATAL;
@@ -550,7 +571,7 @@ int acme_http_req(struct task *task, struct acme_ctx *ctx, struct ist url, enum
 {
        struct httpclient *hc;
 
-       hc = httpclient_new(task, meth, url);
+       hc = httpclient_new_from_proxy(httpclient_acme_px, task, meth, url);
        if (!hc)
                goto error;