Support PKCS12 identity on the ClientBuilder
This commit is contained in:
committed by
Sean McArthur
parent
768a72fb92
commit
646c8b8efc
@@ -8,7 +8,7 @@ use futures::sync::{mpsc, oneshot};
|
||||
|
||||
use request::{self, Request, RequestBuilder};
|
||||
use response::{self, Response};
|
||||
use {async_impl, Certificate, Method, IntoUrl, Proxy, RedirectPolicy, wait};
|
||||
use {async_impl, Certificate, Identity, Method, IntoUrl, Proxy, RedirectPolicy, wait};
|
||||
|
||||
/// A `Client` to make Requests with.
|
||||
///
|
||||
@@ -119,6 +119,41 @@ impl ClientBuilder {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Sets the identity to be used for client certificate authentication.
|
||||
///
|
||||
/// This can be used in mutual authentication scenarios to identify to a server
|
||||
/// with a PKCS#12 archive containing a certificate and private key for example.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// # use std::fs::File;
|
||||
/// # use std::io::Read;
|
||||
/// # fn build_client() -> Result<(), Box<std::error::Error>> {
|
||||
/// // read a local PKCS12 bundle
|
||||
/// let mut buf = Vec::new();
|
||||
/// File::open("my-ident.pfx")?.read_to_end(&mut buf)?;
|
||||
///
|
||||
/// // create an Identity from the PKCS#12 archive
|
||||
/// let pkcs12 = reqwest::Identity::from_pkcs12_der(&buf, "my-privkey-password")?;
|
||||
///
|
||||
/// // get a client builder
|
||||
/// let client = reqwest::ClientBuilder::new()?
|
||||
/// .identity(pkcs12)?
|
||||
/// .build()?;
|
||||
/// # drop(client);
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This method fails if adding client identity was unsuccessful.
|
||||
pub fn identity(&mut self, identity: Identity) -> ::Result<&mut ClientBuilder> {
|
||||
self.inner.identity(identity)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
|
||||
/// Disable hostname verification.
|
||||
///
|
||||
/// # Warning
|
||||
|
||||
Reference in New Issue
Block a user