Skip to content

Commit 3bba705

Browse files
committed
removed impl_trait_type_alias, implemented ChannelBinding
1 parent 55449c7 commit 3bba705

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ readme = "README.md"
1010
[dependencies]
1111
bytes = "0.5.3"
1212
futures = "0.3.1"
13+
ring = "0.16.9"
1314
rustls = "0.16.0"
1415
tokio = "0.2.6"
1516
tokio-postgres = "0.5.1"

src/lib.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(type_alias_impl_trait)]
2-
31
use std::{
42
io,
53
future::Future,
@@ -10,8 +8,9 @@ use std::{
108
};
119

1210
use 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};
1514
use tokio::io::{AsyncRead, AsyncWrite};
1615
use tokio_postgres::tls::{ChannelBinding, MakeTlsConnect, TlsConnect};
1716
use tokio_rustls::{client::TlsStream, TlsConnector};
@@ -30,13 +29,13 @@ impl MakeRustlsConnect {
3029

3130
impl<S> MakeTlsConnect<S> for MakeRustlsConnect
3231
where
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

5453
impl<S> TlsConnect<S> for RustlsConnect
5554
where
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

@@ -72,7 +72,14 @@ where
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

Comments
 (0)