Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy_cacert support #344

Merged
merged 3 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;
pub const CURLOPT_PROXY_CAINFO: CURLoption = CURLOPTTYPE_OBJECTPOINT + 246;
pub const CURLOPT_PROXY_CAPATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 247;
pub const CURLOPT_PROXY_SSLCERT: CURLoption = CURLOPTTYPE_OBJECTPOINT + 254;
pub const CURLOPT_PROXY_SSLKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 256;

Expand Down
5 changes: 5 additions & 0 deletions src/easy/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,11 @@ impl Easy {
self.inner.proxy_cainfo(cainfo)
}

/// Same as [`Easy2::proxy_capath`](struct.Easy2.html#method.proxy_capath)
pub fn proxy_capath<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error> {
self.inner.proxy_capath(path)
}

/// Same as [`Easy2::proxy_sslcert`](struct.Easy2.html#method.proxy_sslcert)
pub fn proxy_sslcert(&mut self, sslcert: &str) -> Result<(), Error> {
self.inner.proxy_sslcert(sslcert)
Expand Down
28 changes: 22 additions & 6 deletions src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,25 +881,41 @@ impl<H> Easy2<H> {
self.setopt_long(curl_sys::CURLOPT_PROXYPORT, port as c_long)
}

/// Set CA certificate to verify peer against for proxy
/// Set CA certificate to verify peer against for proxy.
///
/// By default this value is not set and corresponds to `CURLOPT_PROXY_CAINFO`.
/// By default this value is not set and corresponds to
/// `CURLOPT_PROXY_CAINFO`.
pub fn proxy_cainfo(&mut self, cainfo: &str) -> Result<(), Error> {
let cainfo = CString::new(cainfo)?;
self.setopt_str(curl_sys::CURLOPT_PROXY_CAINFO, &cainfo)
}

/// Set client certificate for proxy
/// Specify a directory holding CA certificates for proxy.
///
/// The specified directory should hold multiple CA certificates to verify
/// the HTTPS proxy with. If libcurl is built against OpenSSL, the
/// certificate directory must be prepared using the OpenSSL `c_rehash`
/// utility.
///
/// By default this value is not set and corresponds to
/// `CURLOPT_PROXY_CAPATH`.
pub fn proxy_capath<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error> {
self.setopt_path(curl_sys::CURLOPT_PROXY_CAPATH, path.as_ref())
}

/// Set client certificate for proxy.
///
/// By default this value is not set and corresponds to `CURLOPT_PROXY_SSLCERT`.
/// By default this value is not set and corresponds to
/// `CURLOPT_PROXY_SSLCERT`.
pub fn proxy_sslcert(&mut self, sslcert: &str) -> Result<(), Error> {
let sslcert = CString::new(sslcert)?;
self.setopt_str(curl_sys::CURLOPT_PROXY_SSLCERT, &sslcert)
}

/// Set private key for HTTPS proxy
/// Set private key for HTTPS proxy.
///
/// By default this value is not set and corresponds to `CURLOPT_PROXY_SSLKEY`.
/// By default this value is not set and corresponds to
/// `CURLOPT_PROXY_SSLKEY`.
pub fn proxy_sslkey(&mut self, sslkey: &str) -> Result<(), Error> {
let sslkey = CString::new(sslkey)?;
self.setopt_str(curl_sys::CURLOPT_PROXY_SSLKEY, &sslkey)
Expand Down
6 changes: 6 additions & 0 deletions systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ fn main() {
_ => {}
}
}
if version < 52 {
match s {
"CURLOPT_PROXY_CAPATH" => return true,
_ => {}
}
}

if version < 49 {
if s.starts_with("CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE") {
Expand Down