Skip to content

Commit 1931312

Browse files
authored
Add support for CURLOPT_PINNEDPUBLICKEY (#391)
* Implement CURLOPT_PINNEDPUBLICKEY setter * Implement in Easy wrapper * rustfmt
1 parent f41ace0 commit 1931312

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

curl-sys/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ pub const CURLOPT_SSL_OPTIONS: CURLoption = CURLOPTTYPE_LONG + 216;
584584
// pub const CURLOPT_DNS_LOCAL_IP6: CURLoption = CURLOPTTYPE_OBJECTPOINT + 223;
585585
// pub const CURLOPT_LOGIN_OPTIONS: CURLoption = CURLOPTTYPE_OBJECTPOINT + 224;
586586
pub const CURLOPT_EXPECT_100_TIMEOUT_MS: CURLoption = CURLOPTTYPE_LONG + 227;
587+
pub const CURLOPT_PINNEDPUBLICKEY: CURLoption = CURLOPTTYPE_OBJECTPOINT + 230;
587588
pub const CURLOPT_UNIX_SOCKET_PATH: CURLoption = CURLOPTTYPE_OBJECTPOINT + 231;
588589
pub const CURLOPT_PATH_AS_IS: CURLoption = CURLOPTTYPE_LONG + 234;
589590
pub const CURLOPT_PIPEWAIT: CURLoption = CURLOPTTYPE_LONG + 237;

src/easy/handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,11 @@ impl Easy {
10871087
self.inner.ssl_options(bits)
10881088
}
10891089

1090+
/// Same as [`Easy2::pinned_public_key`](struct.Easy2.html#method.pinned_public_key)
1091+
pub fn pinned_public_key(&mut self, pubkey: &str) -> Result<(), Error> {
1092+
self.inner.pinned_public_key(pubkey)
1093+
}
1094+
10901095
// =========================================================================
10911096
// getters
10921097

src/easy/handler.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,23 +2229,24 @@ impl<H> Easy2<H> {
22292229
self.setopt_long(curl_sys::CURLOPT_CERTINFO, enable as c_long)
22302230
}
22312231

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

22502251
/// Specify a source for random data
22512252
///

0 commit comments

Comments
 (0)