]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Add --http.proxy issue160
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 16 May 2025 16:52:20 +0000 (10:52 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 16 May 2025 17:04:57 +0000 (11:04 -0600)
Attempt to fix #160.

src/config.c
src/config.h
src/http/http.c

index e3e807c91783ee75bddb5985268fdebfe6dab3d1..86a6d63dda96e5729cf02bddccaf94087d5e44c7 100644 (file)
@@ -125,6 +125,8 @@ struct rpki_config {
                curl_off_t max_file_size;
                /* Directory where CA certs to verify peers are found */
                char *ca_path;
+               /* See CURLOPT_PROXY */
+               char *proxy;
        } http;
 
        struct {
@@ -591,6 +593,14 @@ static const struct option_field options[] = {
                .doc = "Directory where CA certificates are found, used to verify the peer",
                .arg_doc = "<directory>",
                .json_null_allowed = false,
+       }, {
+               .id = 9013,
+               .name = "http.proxy",
+               .type = &gt_string,
+               .offset = offsetof(struct rpki_config, http.proxy),
+               .doc = "Name of proxy to use",
+               .arg_doc = "<URI>",
+               .json_null_allowed = true,
        },
 
        /* Logging fields */
@@ -980,6 +990,7 @@ set_default_values(void)
        rpki_config.http.low_speed_time = 10;
        rpki_config.http.max_file_size = 2000000000;
        rpki_config.http.ca_path = NULL; /* Use system default */
+       rpki_config.http.proxy = NULL;
 
        rpki_config.log.enabled = true;
        rpki_config.log.tag = NULL;
@@ -1013,6 +1024,8 @@ set_default_values(void)
 static int
 validate_config(void)
 {
+       char const *proxy;
+
        if (rpki_config.mode == PRINT_FILE)
                return 0;
 
@@ -1040,6 +1053,14 @@ validate_config(void)
        if (rpki_config.slurm != NULL && !valid_file_or_dir(rpki_config.slurm, true))
                return pr_op_err("Invalid slurm location.");
 
+       if (rpki_config.http.proxy == NULL) {
+               proxy = curl_getenv("https_proxy");
+               if (proxy == NULL)
+                       proxy = curl_getenv("HTTPS_PROXY");
+               if (proxy != NULL && proxy[0] != '\0')
+                       rpki_config.http.proxy = pstrdup(proxy);
+       }
+
        return 0;
 }
 
@@ -1402,6 +1423,12 @@ config_get_http_retry_interval(void)
        return rpki_config.http.retry.interval;
 }
 
+char const *
+config_get_http_proxy(void)
+{
+       return rpki_config.http.proxy;
+}
+
 char const *
 config_get_http_user_agent(void)
 {
index a40f0f15bd2ff77f08e9912863bec6b13a2253db..30e5de1534045446dcc4be4f997ae5259c619640 100644 (file)
@@ -52,6 +52,7 @@ bool config_get_http_enabled(void);
 unsigned int config_get_http_priority(void);
 unsigned int config_get_http_retry_count(void);
 unsigned int config_get_http_retry_interval(void);
+char const *config_get_http_proxy(void);
 char const *config_get_output_roa(void);
 char const *config_get_output_bgpsec(void);
 enum output_format config_get_output_format(void);
index 5ab96d559711b5414c23ee2fb45bb6f3114eca07..2bd31519ea133045a8aab123e21c64317b4f402b 100644 (file)
@@ -213,6 +213,9 @@ http_easy_init(struct http_handler *handler, curl_off_t ims)
                    CURL_TIMECOND_IFMODSINCE);
        }
 
+       if (config_get_http_proxy())
+               setopt_str(result, CURLOPT_PROXY, config_get_http_proxy());
+
        handler->curl = result;
        return 0;
 }