quininer / tokio-rustls

Asynchronous TLS/SSL streams for Tokio using Rustls.
142 stars 38 forks source link

No way to continue using an underlying socket after TLS handshake fails? #42

Closed umanwizard closed 5 years ago

umanwizard commented 5 years ago

I have a tokio::net::TcpStream which I am passing to tokio_rustls::TlsAcceptor::accept. If the TLS handshake fails, I would like to continue sending and receiving other (cleartext) data on the underlying TcpStream. However, since accept takes the socket by value (i.e., moving out of it), I can see no way to re-use it again in the future.

The reason this is required is because I am building an SMTP server, and the relevant RFCs allow a server to continue attempting to send mail in cleartext if the STARTTLS negotiation fails. This is particularly relevant when using rustls, as there are mail servers out there using pre-TLSv1.2 versions (which rustls doesn't support), and I still want to be able to get mail from them.

quininer commented 5 years ago

I can provide a take_inner for Connect/Accept, which should suffice.

impl<IO> Accept<IO> {
    fn take_inner(&mut self) -> Option<IO>;
}
umanwizard commented 5 years ago

That would be great, thanks!

quininer commented 5 years ago

I just published 0.10.0-alpha.4, and if you need, I can give 0.9 a backport.

umanwizard commented 5 years ago

Thanks for the quick turnaround. take_inner is seeming to work for my use case in 0.10.0-alpha.4