1- #![ feature( type_alias_impl_trait) ]
2-
31use std:: {
42 io,
53 future:: Future ,
@@ -10,8 +8,9 @@ use std::{
108} ;
119
1210use bytes:: { Buf , BufMut } ;
13- use futures:: future:: TryFutureExt ;
14- use rustls:: ClientConfig ;
11+ use futures:: future:: { FutureExt , TryFutureExt } ;
12+ use ring:: digest;
13+ use rustls:: { ClientConfig , Session } ;
1514use tokio:: io:: { AsyncRead , AsyncWrite } ;
1615use tokio_postgres:: tls:: { ChannelBinding , MakeTlsConnect , TlsConnect } ;
1716use tokio_rustls:: { client:: TlsStream , TlsConnector } ;
@@ -30,13 +29,13 @@ impl MakeRustlsConnect {
3029
3130impl < S > MakeTlsConnect < S > for MakeRustlsConnect
3231where
33- S : AsyncRead + AsyncWrite + Unpin ,
32+ S : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
3433{
3534 type Stream = RustlsStream < S > ;
3635 type TlsConnect = RustlsConnect ;
37- type Error = std :: io:: Error ;
36+ type Error = io:: Error ;
3837
39- fn make_tls_connect ( & mut self , hostname : & str ) -> std :: io:: Result < RustlsConnect > {
38+ fn make_tls_connect ( & mut self , hostname : & str ) -> io:: Result < RustlsConnect > {
4039 DNSNameRef :: try_from_ascii_str ( hostname)
4140 . map ( |dns_name| RustlsConnect {
4241 hostname : dns_name. to_owned ( ) ,
@@ -53,15 +52,16 @@ pub struct RustlsConnect {
5352
5453impl < S > TlsConnect < S > for RustlsConnect
5554where
56- S : AsyncRead + AsyncWrite + Unpin ,
55+ S : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
5756{
5857 type Stream = RustlsStream < S > ;
59- type Error = std :: io:: Error ;
60- type Future = impl Future < Output = std :: io:: Result < RustlsStream < S > > > ;
58+ type Error = io:: Error ;
59+ type Future = Pin < Box < dyn Future < Output = io:: Result < RustlsStream < S > > > > > ;
6160
6261 fn connect ( self , stream : S ) -> Self :: Future {
6362 self . connector . connect ( self . hostname . as_ref ( ) , stream)
6463 . map_ok ( |s| RustlsStream ( Box :: pin ( s) ) )
64+ . boxed ( )
6565 }
6666}
6767
7272 S : AsyncRead + AsyncWrite + Unpin ,
7373{
7474 fn channel_binding ( & self ) -> ChannelBinding {
75- ChannelBinding :: none ( ) // TODO
75+ let ( _, session) = self . 0 . get_ref ( ) ;
76+ match session. get_peer_certificates ( ) {
77+ Some ( certs) if certs. len ( ) > 0 => {
78+ let sha256 = digest:: digest ( & digest:: SHA256 , certs[ 0 ] . as_ref ( ) ) ;
79+ ChannelBinding :: tls_server_end_point ( sha256. as_ref ( ) . into ( ) )
80+ } ,
81+ _ => ChannelBinding :: none ( ) ,
82+ }
7683 }
7784}
7885
0 commit comments