@@ -2,7 +2,7 @@ use super::channel::Channel;
22#[ cfg( feature = "tls" ) ]
33use super :: {
44 service:: TlsConnector ,
5- tls:: { Certificate , TlsProvider } ,
5+ tls:: { Certificate , Identity , TlsProvider } ,
66} ;
77use bytes:: Bytes ;
88use http:: uri:: { InvalidUriBytes , Uri } ;
@@ -212,6 +212,7 @@ pub struct ClientTlsConfig {
212212 provider : TlsProvider ,
213213 domain : Option < String > ,
214214 cert : Option < Certificate > ,
215+ identity : Option < Identity > ,
215216 #[ cfg( feature = "openssl" ) ]
216217 openssl_raw : Option < openssl1:: ssl:: SslConnector > ,
217218 #[ cfg( feature = "rustls" ) ]
@@ -223,6 +224,9 @@ impl fmt::Debug for ClientTlsConfig {
223224 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
224225 f. debug_struct ( "ClientTlsConfig" )
225226 . field ( "provider" , & self . provider )
227+ . field ( "domain" , & self . domain )
228+ . field ( "cert" , & self . cert )
229+ . field ( "identity" , & self . identity )
226230 . finish ( )
227231 }
228232}
@@ -246,6 +250,7 @@ impl ClientTlsConfig {
246250 provider,
247251 domain : None ,
248252 cert : None ,
253+ identity : None ,
249254 #[ cfg( feature = "openssl" ) ]
250255 openssl_raw : None ,
251256 #[ cfg( feature = "rustls" ) ]
@@ -265,6 +270,12 @@ impl ClientTlsConfig {
265270 self
266271 }
267272
273+ /// Sets the client identity to present to the server.
274+ pub fn identity ( & mut self , identity : Identity ) -> & mut Self {
275+ self . identity = Some ( identity) ;
276+ self
277+ }
278+
268279 /// Use options specified by the given `SslConnector` to configure TLS.
269280 ///
270281 /// This overrides all other TLS options set via other means.
@@ -294,12 +305,20 @@ impl ClientTlsConfig {
294305 match self . provider {
295306 #[ cfg( feature = "openssl" ) ]
296307 TlsProvider :: OpenSsl => match & self . openssl_raw {
297- None => TlsConnector :: new_with_openssl_cert ( self . cert . clone ( ) , domain) ,
308+ None => TlsConnector :: new_with_openssl_cert (
309+ self . cert . clone ( ) ,
310+ self . identity . clone ( ) ,
311+ domain,
312+ ) ,
298313 Some ( r) => TlsConnector :: new_with_openssl_raw ( r. clone ( ) , domain) ,
299314 } ,
300315 #[ cfg( feature = "rustls" ) ]
301316 TlsProvider :: Rustls => match & self . rustls_raw {
302- None => TlsConnector :: new_with_rustls_cert ( self . cert . clone ( ) , domain) ,
317+ None => TlsConnector :: new_with_rustls_cert (
318+ self . cert . clone ( ) ,
319+ self . identity . clone ( ) ,
320+ domain,
321+ ) ,
303322 Some ( c) => TlsConnector :: new_with_rustls_raw ( c. clone ( ) , domain) ,
304323 } ,
305324 }
0 commit comments