@@ -507,13 +507,31 @@ impl TlsConnector {
507
507
}
508
508
}
509
509
510
+ /// Client certificate verification modes
511
+ pub enum TlsClientCertificateVerification {
512
+ /// The server will not request certificates from the client.
513
+ ///
514
+ /// # Warning
515
+ /// The client will not be able to send any certificates with this setting.
516
+ DoNotRequestCertificate ,
517
+ /// The server will request a certificate from the client, then will validate
518
+ /// any certificate it receives. The client may choose not to send any.
519
+ RequestCertificate ,
520
+ /// The server will request a certificate from the client, then will validate
521
+ /// any certificate it receives or reject the connection none are provided.
522
+ RequireCertificate ,
523
+ }
524
+
510
525
/// A builder for `TlsAcceptor`s.
511
526
///
512
527
/// You can get one from [`TlsAcceptor::builder()`](TlsAcceptor::builder)
513
528
pub struct TlsAcceptorBuilder {
514
529
identity : Identity ,
515
530
min_protocol : Option < Protocol > ,
516
531
max_protocol : Option < Protocol > ,
532
+ client_cert_verification : TlsClientCertificateVerification ,
533
+ client_cert_verification_ca_cert : Option < Certificate > ,
534
+ client_cert_verification_trust : bool
517
535
}
518
536
519
537
impl TlsAcceptorBuilder {
@@ -537,6 +555,35 @@ impl TlsAcceptorBuilder {
537
555
self
538
556
}
539
557
558
+ /// Sets the verification mode for client certificates.
559
+ ///
560
+ /// Defaults to `TlsClientCertificateVerification::DoNotRequestCertificate`.
561
+ pub fn client_cert_verification ( & mut self , client_cert_verification : TlsClientCertificateVerification ) -> & mut TlsAcceptorBuilder {
562
+ self . client_cert_verification = client_cert_verification;
563
+ self
564
+ }
565
+
566
+ /// Sets which ca to tell the client is acceptable to send to the server.
567
+ ///
568
+ /// A value of `None` will not tell the client it is acceptable to send certificates signed by any ca.
569
+ ///
570
+ /// Defaults `None`.
571
+ pub fn client_cert_verification_ca_cert ( & mut self , client_cert_verification_ca_cert : Option < Certificate > ) -> & mut TlsAcceptorBuilder {
572
+ self . client_cert_verification_ca_cert = client_cert_verification_ca_cert;
573
+ self
574
+ }
575
+
576
+ /// Trust the ca certificate used for client verification
577
+ ///
578
+ /// Adds client ca to the list of trusted certificates. This is used in
579
+ /// case you are using self-signed CA certificate.
580
+ ///
581
+ /// Defaults `false`
582
+ pub fn trust_client_ca_cert ( & mut self , should_trust : bool ) -> & mut TlsAcceptorBuilder {
583
+ self . client_cert_verification_trust = should_trust;
584
+ self
585
+ }
586
+
540
587
/// Creates a new `TlsAcceptor`.
541
588
pub fn build ( & self ) -> Result < TlsAcceptor > {
542
589
let acceptor = imp:: TlsAcceptor :: new ( self ) ?;
@@ -601,6 +648,9 @@ impl TlsAcceptor {
601
648
identity,
602
649
min_protocol : Some ( Protocol :: Tlsv10 ) ,
603
650
max_protocol : None ,
651
+ client_cert_verification : TlsClientCertificateVerification :: DoNotRequestCertificate ,
652
+ client_cert_verification_ca_cert : None ,
653
+ client_cert_verification_trust : false
604
654
}
605
655
}
606
656
0 commit comments