Skip to content

Commit 96c6d7b

Browse files
authored
Add http.proxy-cainfo config for proxy certs (#15374)
This adds a `http.proxy-cainfo` option to Cargo which reads CA information from a bundle to pass through to the underlying `libcurl` call. This should allow configuration of Cargo in situations where SSL proxy is used. Similar to #2917. cc #15376
2 parents 1320642 + 5af7831 commit 96c6d7b

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/cargo/util/context/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,6 +2632,7 @@ pub struct CargoHttpConfig {
26322632
pub low_speed_limit: Option<u32>,
26332633
pub timeout: Option<u64>,
26342634
pub cainfo: Option<ConfigRelativePath>,
2635+
pub proxy_cainfo: Option<ConfigRelativePath>,
26352636
pub check_revoke: Option<bool>,
26362637
pub user_agent: Option<String>,
26372638
pub debug: Option<bool>,

src/cargo/util/network/http.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ pub fn configure_http_handle(gctx: &GlobalContext, handle: &mut Easy) -> CargoRe
6161
let cainfo = cainfo.resolve_path(gctx);
6262
handle.cainfo(&cainfo)?;
6363
}
64+
// Use `proxy_cainfo` if explicitly set; otherwise, fall back to `cainfo` as curl does #15376.
65+
if let Some(proxy_cainfo) = http.proxy_cainfo.as_ref().or(http.cainfo.as_ref()) {
66+
let proxy_cainfo = proxy_cainfo.resolve_path(gctx);
67+
handle.proxy_cainfo(&format!("{}", proxy_cainfo.display()))?;
68+
}
6469
if let Some(check) = http.check_revoke {
6570
handle.ssl_options(SslOpt::new().no_revoke(!check))?;
6671
}

src/doc/src/reference/config.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ ssl-version.min = "tlsv1.1" # minimum TLS version
110110
timeout = 30 # timeout for each HTTP request, in seconds
111111
low-speed-limit = 10 # network timeout threshold (bytes/sec)
112112
cainfo = "cert.pem" # path to Certificate Authority (CA) bundle
113+
proxy-cainfo = "cert.pem" # path to proxy Certificate Authority (CA) bundle
113114
check-revoke = true # check for SSL certificate revocation
114115
multiplexing = true # HTTP/2 multiplexing
115116
user-agent = "" # the user-agent header
@@ -746,6 +747,14 @@ Sets the timeout for each HTTP request, in seconds.
746747
Path to a Certificate Authority (CA) bundle file, used to verify TLS
747748
certificates. If not specified, Cargo attempts to use the system certificates.
748749

750+
#### `http.proxy-cainfo`
751+
* Type: string (path)
752+
* Default: falls back to `http.cainfo` if not set
753+
* Environment: `CARGO_HTTP_PROXY_CAINFO`
754+
755+
Path to a Certificate Authority (CA) bundle file, used to verify proxy TLS
756+
certificates.
757+
749758
#### `http.check-revoke`
750759
* Type: boolean
751760
* Default: true (Windows) false (all others)

src/doc/src/reference/environment-variables.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ In summary, the supported environment variables are:
106106
* `CARGO_HTTP_PROXY` --- Enables HTTP proxy, see [`http.proxy`].
107107
* `CARGO_HTTP_TIMEOUT` --- The HTTP timeout, see [`http.timeout`].
108108
* `CARGO_HTTP_CAINFO` --- The TLS certificate Certificate Authority file, see [`http.cainfo`].
109+
* `CARGO_HTTP_PROXY_CAINFO` --- The proxy TLS certificate Certificate Authority file, see [`http.proxy-cainfo`].
109110
* `CARGO_HTTP_CHECK_REVOKE` --- Disables TLS certificate revocation checks, see [`http.check-revoke`].
110111
* `CARGO_HTTP_SSL_VERSION` --- The TLS version to use, see [`http.ssl-version`].
111112
* `CARGO_HTTP_LOW_SPEED_LIMIT` --- The HTTP low-speed limit, see [`http.low-speed-limit`].
@@ -173,6 +174,7 @@ In summary, the supported environment variables are:
173174
[`http.proxy`]: config.md#httpproxy
174175
[`http.timeout`]: config.md#httptimeout
175176
[`http.cainfo`]: config.md#httpcainfo
177+
[`http.proxy-cainfo`]: config.md#httpproxy-cainfo
176178
[`http.check-revoke`]: config.md#httpcheck-revoke
177179
[`http.ssl-version`]: config.md#httpssl-version
178180
[`http.low-speed-limit`]: config.md#httplow-speed-limit

0 commit comments

Comments
 (0)