11//! OpenSSL support.
22extern crate openssl;
3- extern crate openssl_verify;
43
54use std:: error:: Error ;
5+ use std:: fmt;
66
77use self :: openssl:: error:: ErrorStack ;
8- use self :: openssl:: ssl:: { IntoSsl , SslContext , SslStream , SslMethod , SSL_VERIFY_PEER ,
9- SSL_OP_NO_SSLV2 , SSL_OP_NO_SSLV3 , SSL_OP_NO_COMPRESSION } ;
10- use self :: openssl_verify:: verify_callback;
8+ use self :: openssl:: ssl:: { SslMethod , SslConnector , SslConnectorBuilder , SslStream } ;
119use tls:: { TlsStream , Stream , TlsHandshake } ;
1210
1311impl TlsStream for SslStream < Stream > {
@@ -23,35 +21,35 @@ impl TlsStream for SslStream<Stream> {
2321/// A `TlsHandshake` implementation that uses OpenSSL.
2422///
2523/// Requires the `with-openssl` feature.
26- #[ derive( Debug ) ]
27- pub struct OpenSsl ( SslContext ) ;
24+ pub struct OpenSsl ( SslConnector ) ;
25+
26+ impl fmt:: Debug for OpenSsl {
27+ fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
28+ fmt. debug_struct ( "OpenSsl" ) . finish ( )
29+ }
30+ }
2831
2932impl OpenSsl {
30- /// Creates a `OpenSsl` with a reasonable default configuration.
31- ///
32- /// The configuration is modeled after libcurl's and is subject to change.
33+ /// Creates a `OpenSsl` with `SslConnector`'s default configuration.
3334 pub fn new ( ) -> Result < OpenSsl , ErrorStack > {
34- let mut ctx = try!( SslContext :: new ( SslMethod :: Sslv23 ) ) ;
35- try!( ctx. set_default_verify_paths ( ) ) ;
36- ctx. set_options ( SSL_OP_NO_SSLV2 | SSL_OP_NO_SSLV3 | SSL_OP_NO_COMPRESSION ) ;
37- try!( ctx. set_cipher_list ( "ALL!EXPORT!EXPORT40!EXPORT56!aNULL!LOW!RC4@STRENGTH" ) ) ;
38- Ok ( ctx. into ( ) )
35+ let connector = try!( SslConnectorBuilder :: new ( SslMethod :: tls ( ) ) ) . build ( ) ;
36+ Ok ( OpenSsl ( connector) )
3937 }
4038
41- /// Returns a reference to the associated `SslContext `.
42- pub fn context ( & self ) -> & SslContext {
39+ /// Returns a reference to the inner `SslConnector `.
40+ pub fn connector ( & self ) -> & SslConnector {
4341 & self . 0
4442 }
4543
46- /// Returns a mutable reference to the associated `SslContext `.
47- pub fn context_mut ( & mut self ) -> & mut SslContext {
44+ /// Returns a mutable reference to the inner `SslConnector `.
45+ pub fn connector_mut ( & mut self ) -> & mut SslConnector {
4846 & mut self . 0
4947 }
5048}
5149
52- impl From < SslContext > for OpenSsl {
53- fn from ( ctx : SslContext ) -> OpenSsl {
54- OpenSsl ( ctx )
50+ impl From < SslConnector > for OpenSsl {
51+ fn from ( connector : SslConnector ) -> OpenSsl {
52+ OpenSsl ( connector )
5553 }
5654}
5755
@@ -60,10 +58,7 @@ impl TlsHandshake for OpenSsl {
6058 domain : & str ,
6159 stream : Stream )
6260 -> Result < Box < TlsStream > , Box < Error + Send + Sync > > {
63- let domain = domain. to_owned ( ) ;
64- let mut ssl = try!( self . 0 . into_ssl ( ) ) ;
65- ssl. set_verify_callback ( SSL_VERIFY_PEER , move |p, x| verify_callback ( & domain, p, x) ) ;
66- let stream = try!( SslStream :: connect ( ssl, stream) ) ;
61+ let stream = try!( self . 0 . connect ( domain, stream) ) ;
6762 Ok ( Box :: new ( stream) )
6863 }
6964}
0 commit comments