@@ -619,7 +619,7 @@ mod openssl {
619
619
use std:: sync:: Arc ;
620
620
use std:: time:: Duration ;
621
621
622
- use openssl:: ssl:: { Ssl , SslContext , SslStream , SslMethod , SSL_VERIFY_NONE } ;
622
+ use openssl:: ssl:: { Ssl , SslContext , SslStream , SslMethod , SSL_VERIFY_NONE , SSL_VERIFY_PEER , SSL_OP_NO_SSLV2 , SSL_OP_NO_SSLV3 } ;
623
623
use openssl:: ssl:: error:: StreamError as SslIoError ;
624
624
use openssl:: ssl:: error:: SslError ;
625
625
use openssl:: x509:: X509FileType ;
@@ -651,11 +651,10 @@ mod openssl {
651
651
652
652
impl Default for OpensslClient {
653
653
fn default ( ) -> OpensslClient {
654
- OpensslClient ( SslContext :: new ( SslMethod :: Sslv23 ) . unwrap_or_else ( |e| {
655
- // if we cannot create a SslContext, that's because of a
656
- // serious problem. just crash.
657
- panic ! ( "{}" , e)
658
- } ) )
654
+ let mut ctx = SslContext :: new ( SslMethod :: Sslv23 ) . unwrap ( ) ;
655
+ ctx. set_default_verify_paths ( ) . unwrap ( ) ;
656
+ ctx. set_options ( SSL_OP_NO_SSLV2 | SSL_OP_NO_SSLV3 ) ;
657
+ OpensslClient ( ctx)
659
658
}
660
659
}
661
660
@@ -664,8 +663,10 @@ mod openssl {
664
663
type Stream = SslStream < T > ;
665
664
666
665
fn wrap_client ( & self , stream : T , host : & str ) -> :: Result < Self :: Stream > {
667
- let ssl = try!( Ssl :: new ( & self . 0 ) ) ;
666
+ let mut ssl = try!( Ssl :: new ( & self . 0 ) ) ;
668
667
try!( ssl. set_hostname ( host) ) ;
668
+ let host = host. to_owned ( ) ;
669
+ ssl. set_verify_callback ( SSL_VERIFY_PEER , move |p, x| :: openssl_verify:: verify_callback ( & host, p, x) ) ;
669
670
SslStream :: connect ( ssl, stream) . map_err ( From :: from)
670
671
}
671
672
}
0 commit comments