@@ -482,11 +482,30 @@ impl TlsConnector {
482
482
}
483
483
}
484
484
485
+ /// Client certificate verification modes
486
+ pub enum TlsClientCertificateVerification {
487
+ /// The server will not request certificates from the client.
488
+ ///
489
+ /// # Warning
490
+ /// The client will not be able to send any certificates with this setting.
491
+ DoNotRequestCertificate ,
492
+ /// The server will request a certificate from the client, then will validate
493
+ /// any certificate it receives. The client may choose not to send any.
494
+ RequestCertificate ,
495
+ /// The server will request a certificate from the client, then will validate
496
+ /// any certificate it receives or reject the connection none are provided.
497
+ RequireCertificate ,
498
+ }
499
+
485
500
/// A builder for `TlsAcceptor`s.
486
501
pub struct TlsAcceptorBuilder {
487
502
identity : Identity ,
488
503
min_protocol : Option < Protocol > ,
489
504
max_protocol : Option < Protocol > ,
505
+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , target_os = "ios" ) ) ) ]
506
+ client_cert_verification : TlsClientCertificateVerification ,
507
+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , target_os = "ios" ) ) ) ]
508
+ client_cert_verification_ca_cert : Option < Certificate >
490
509
}
491
510
492
511
impl TlsAcceptorBuilder {
@@ -510,6 +529,26 @@ impl TlsAcceptorBuilder {
510
529
self
511
530
}
512
531
532
+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , target_os = "ios" ) ) ) ]
533
+ /// Sets the verification mode for client certificates.
534
+ ///
535
+ /// Defaults to `TlsClientCertificateVerification::DoNotRequestCertificate`.
536
+ pub fn client_cert_verification ( & mut self , client_cert_verification : TlsClientCertificateVerification ) -> & mut TlsAcceptorBuilder {
537
+ self . client_cert_verification = client_cert_verification;
538
+ self
539
+ }
540
+
541
+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , target_os = "ios" ) ) ) ]
542
+ /// Sets which ca to tell the client is acceptable to send to the server.
543
+ ///
544
+ /// A value of `None` will not tell the client it is acceptable to send certificates signed by any ca.
545
+ ///
546
+ /// Defaults `None`.
547
+ pub fn client_cert_verification_ca_cert ( & mut self , client_cert_verification_ca_cert : Option < Certificate > ) -> & mut TlsAcceptorBuilder {
548
+ self . client_cert_verification_ca_cert = client_cert_verification_ca_cert;
549
+ self
550
+ }
551
+
513
552
/// Creates a new `TlsAcceptor`.
514
553
pub fn build ( & self ) -> Result < TlsAcceptor > {
515
554
let acceptor = imp:: TlsAcceptor :: new ( self ) ?;
@@ -574,6 +613,10 @@ impl TlsAcceptor {
574
613
identity,
575
614
min_protocol : Some ( Protocol :: Tlsv10 ) ,
576
615
max_protocol : None ,
616
+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , target_os = "ios" ) ) ) ]
617
+ client_cert_verification : TlsClientCertificateVerification :: DoNotRequestCertificate ,
618
+ #[ cfg( not( any( target_os = "macos" , target_os = "windows" , target_os = "ios" ) ) ) ]
619
+ client_cert_verification_ca_cert : None
577
620
}
578
621
}
579
622
0 commit comments