Skip to content

Commit

Permalink
Add support for CURLOPT_PINNEDPUBLICKEY (#391)
Browse files Browse the repository at this point in the history
* Implement CURLOPT_PINNEDPUBLICKEY setter

* Implement in Easy wrapper

* rustfmt
  • Loading branch information
yoavk authored May 4, 2021
1 parent f41ace0 commit 1931312
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions curl-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
// pub const CURLOPT_DNS_LOCAL_IP6: CURLoption = CURLOPTTYPE_OBJECTPOINT + 223;
// pub const CURLOPT_LOGIN_OPTIONS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 224;
pub const CURLOPT_EXPECT_100_TIMEOUT_MS: CURLoption = CURLOPTTYPE_LONG + 227;
pub const CURLOPT_PINNEDPUBLICKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 230;
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
pub const CURLOPT_PATH_AS_IS: CURLoption = CURLOPTTYPE_LONG + 234;
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;
Expand Down
5 changes: 5 additions & 0 deletions src/easy/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,11 @@ impl Easy {
self.inner.ssl_options(bits)
}

/// Same as [`Easy2::pinned_public_key`](struct.Easy2.html#method.pinned_public_key)
pub fn pinned_public_key(&mut self, pubkey: &str) -> Result<(), Error> {
self.inner.pinned_public_key(pubkey)
}

// =========================================================================
// getters

Expand Down
35 changes: 18 additions & 17 deletions src/easy/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,23 +2229,24 @@ impl<H> Easy2<H> {
self.setopt_long(curl_sys::CURLOPT_CERTINFO, enable as c_long)
}

// /// Set pinned public key.
// ///
// /// Pass a pointer to a zero terminated string as parameter. The string can
// /// be the file name of your pinned public key. The file format expected is
// /// "PEM" or "DER". The string can also be any number of base64 encoded
// /// sha256 hashes preceded by "sha256//" and separated by ";"
// ///
// /// When negotiating a TLS or SSL connection, the server sends a certificate
// /// indicating its identity. A public key is extracted from this certificate
// /// and if it does not exactly match the public key provided to this option,
// /// curl will abort the connection before sending or receiving any data.
// ///
// /// By default this option is not set and corresponds to
// /// `CURLOPT_PINNEDPUBLICKEY`.
// pub fn pinned_public_key(&mut self, enable: bool) -> Result<(), Error> {
// self.setopt_long(curl_sys::CURLOPT_CERTINFO, enable as c_long)
// }
/// Set pinned public key.
///
/// Pass a pointer to a zero terminated string as parameter. The string can
/// be the file name of your pinned public key. The file format expected is
/// "PEM" or "DER". The string can also be any number of base64 encoded
/// sha256 hashes preceded by "sha256//" and separated by ";"
///
/// When negotiating a TLS or SSL connection, the server sends a certificate
/// indicating its identity. A public key is extracted from this certificate
/// and if it does not exactly match the public key provided to this option,
/// curl will abort the connection before sending or receiving any data.
///
/// By default this option is not set and corresponds to
/// `CURLOPT_PINNEDPUBLICKEY`.
pub fn pinned_public_key(&mut self, pubkey: &str) -> Result<(), Error> {
let key = CString::new(pubkey)?;
self.setopt_str(curl_sys::CURLOPT_PINNEDPUBLICKEY, &key)
}

/// Specify a source for random data
///
Expand Down

0 comments on commit 1931312

Please sign in to comment.