Skip to content

Commit ecc9d80

Browse files
authored
add support for ssl proxy (#339)
- update docker image to ubuntu 16.04 - add support for ssl proxy
1 parent e30fe22 commit ecc9d80

File tree

7 files changed

+82
-2
lines changed

7 files changed

+82
-2
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ winapi = { version = '0.3', features = ['libloaderapi', 'wincrypt'] }
3131
[dev-dependencies]
3232
mio = "0.6"
3333
mio-extras = "2.0.3"
34+
anyhow = "1.0.31"
3435

3536
[workspace]
3637
members = ["systest"]
@@ -49,3 +50,8 @@ protocol-ftp = ["curl-sys/protocol-ftp"]
4950
[[test]]
5051
name = "atexit"
5152
harness = false
53+
54+
[[example]]
55+
name = "ssl_proxy"
56+
path = "examples/ssl_proxy.rs"
57+
required-features = ["ssl"]

ci/Dockerfile-linux64-curl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:14.04
1+
FROM ubuntu:16.04
22

33
RUN apt-get update
44
RUN apt-get install -y --no-install-recommends \

curl-sys/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
576576
// pub const CURLOPT_LOGIN_OPTIONS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 224;
577577
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
578578
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;
579+
pub const CURLOPT_PROXY_CAINFO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 246;
580+
pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254;
581+
pub const CURLOPT_PROXY_SSLKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 256;
579582

580583
pub const CURL_IPRESOLVE_WHATEVER: c_int = 0;
581584
pub const CURL_IPRESOLVE_V4: c_int = 1;

examples/ssl_proxy.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extern crate anyhow;
2+
3+
use anyhow::Result;
4+
5+
fn main() -> Result<()> {
6+
let mut handle = curl::easy::Easy::new();
7+
8+
let proxy_url = "https://fwdproxy";
9+
let proxy_port = 8082;
10+
let cainfo = "/var/credentials/root/ca.pem";
11+
let sslcert = "/var/credentials/user/x509.pem";
12+
let sslkey = "/var/credentials/user/x509.pem";
13+
14+
handle.connect_timeout(std::time::Duration::from_secs(5))?;
15+
handle.connect_only(true)?;
16+
handle.verbose(true)?;
17+
handle.url("https://www.google.com")?;
18+
19+
handle.proxy(proxy_url)?;
20+
handle.proxy_port(proxy_port)?;
21+
handle.proxy_cainfo(&cainfo)?;
22+
handle.proxy_sslcert(&sslcert)?;
23+
handle.proxy_sslkey(&sslkey)?;
24+
println!("ssl proxy setup done");
25+
26+
handle.perform()?;
27+
println!("connected done");
28+
Ok(())
29+
}

src/easy/handle.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,21 @@ impl Easy {
563563
self.inner.proxy_port(port)
564564
}
565565

566+
/// Same as [`Easy2::proxy_cainfo`](struct.Easy2.html#method.proxy_cainfo)
567+
pub fn proxy_cainfo(&mut self, cainfo: &str) -> Result<(), Error> {
568+
self.inner.proxy_cainfo(cainfo)
569+
}
570+
571+
/// Same as [`Easy2::proxy_sslcert`](struct.Easy2.html#method.proxy_sslcert)
572+
pub fn proxy_sslcert(&mut self, sslcert: &str) -> Result<(), Error> {
573+
self.inner.proxy_sslcert(sslcert)
574+
}
575+
576+
/// Same as [`Easy2::proxy_sslkey`](struct.Easy2.html#method.proxy_sslkey)
577+
pub fn proxy_sslkey(&mut self, sslkey: &str) -> Result<(), Error> {
578+
self.inner.proxy_sslkey(sslkey)
579+
}
580+
566581
/// Same as [`Easy2::proxy_type`](struct.Easy2.html#method.proxy_type)
567582
pub fn proxy_type(&mut self, kind: ProxyType) -> Result<(), Error> {
568583
self.inner.proxy_type(kind)

src/easy/handler.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,30 @@ impl<H> Easy2<H> {
881881
self.setopt_long(curl_sys::CURLOPT_PROXYPORT, port as c_long)
882882
}
883883

884+
/// Set CA certificate to verify peer against for proxy
885+
///
886+
/// By default this value is not set and corresponds to `CURLOPT_PROXY_CAINFO`.
887+
pub fn proxy_cainfo(&mut self, cainfo: &str) -> Result<(), Error> {
888+
let cainfo = CString::new(cainfo)?;
889+
self.setopt_str(curl_sys::CURLOPT_PROXY_CAINFO, &cainfo)
890+
}
891+
892+
/// Set client certificate for proxy
893+
///
894+
/// By default this value is not set and corresponds to `CURLOPT_PROXY_SSLCERT`.
895+
pub fn proxy_sslcert(&mut self, sslcert: &str) -> Result<(), Error> {
896+
let sslcert = CString::new(sslcert)?;
897+
self.setopt_str(curl_sys::CURLOPT_PROXY_SSLCERT, &sslcert)
898+
}
899+
900+
/// Set private key for HTTPS proxy
901+
///
902+
/// By default this value is not set and corresponds to `CURLOPT_PROXY_SSLKEY`.
903+
pub fn proxy_sslkey(&mut self, sslkey: &str) -> Result<(), Error> {
904+
let sslkey = CString::new(sslkey)?;
905+
self.setopt_str(curl_sys::CURLOPT_PROXY_SSLKEY, &sslkey)
906+
}
907+
884908
/// Indicates the type of proxy being used.
885909
///
886910
/// By default this option is `ProxyType::Http` and corresponds to

systest/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ fn main() {
109109
}
110110
if version < 54 {
111111
match s {
112-
"CURL_SSLVERSION_TLSv1_3" => return true,
112+
"CURL_SSLVERSION_TLSv1_3"
113+
| "CURLOPT_PROXY_CAINFO"
114+
| "CURLOPT_PROXY_SSLCERT"
115+
| "CURLOPT_PROXY_SSLKEY" => return true,
113116
_ => {}
114117
}
115118
}

0 commit comments

Comments
 (0)