1
1
//! OpenSSL support.
2
2
extern crate openssl;
3
- extern crate openssl_verify;
4
3
5
4
use std:: error:: Error ;
5
+ use std:: fmt;
6
6
7
7
use 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 } ;
11
9
use tls:: { TlsStream , Stream , TlsHandshake } ;
12
10
13
11
impl TlsStream for SslStream < Stream > {
@@ -23,35 +21,35 @@ impl TlsStream for SslStream<Stream> {
23
21
/// A `TlsHandshake` implementation that uses OpenSSL.
24
22
///
25
23
/// 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
+ }
28
31
29
32
impl 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.
33
34
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) )
39
37
}
40
38
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 {
43
41
& self . 0
44
42
}
45
43
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 {
48
46
& mut self . 0
49
47
}
50
48
}
51
49
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 )
55
53
}
56
54
}
57
55
@@ -60,10 +58,7 @@ impl TlsHandshake for OpenSsl {
60
58
domain : & str ,
61
59
stream : Stream )
62
60
-> 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) ) ;
67
62
Ok ( Box :: new ( stream) )
68
63
}
69
64
}
0 commit comments