Skip to content

Commit 55f1266

Browse files
committed
fix(net): don't stop the server when an SSL handshake fails with EOF
HttpAcceptor::accept()'s HTTPS logic passes IO errors from the underlying SSL stream directly to the caller. Furthermore, the caller uses the EndOfFile error code to detect that the server should stop accepting connections. This means that if the TCP connection was succesfully accepted, but an EOF condition was detected during the handshake, the server will stop accepting connections and quit. This allows for a trivial denial of service attack and can happen accidentally as well. Change HttpAcceptor::accept such that if the TCP stream underlying the SSL stream returns an IoError error, a ConnectionAborted IoError is returned instead. This allows distinguishing between IoErrors from the acceptor and the stream. The original error reason is stored in the detail field.
1 parent 3e951c9 commit 55f1266

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/net.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,17 @@ impl NetworkAcceptor for HttpAcceptor {
237237
HttpAcceptor::Http(ref mut tcp, _) => HttpStream::Http(try!(tcp.accept())),
238238
HttpAcceptor::Https(ref mut tcp, _, ref ssl_context) => {
239239
let stream = try!(tcp.accept());
240-
let ssl_stream = try!(SslStream::<TcpStream>::new_server(&**ssl_context, stream).
241-
map_err(lift_ssl_error));
242-
HttpStream::Https(ssl_stream)
240+
match SslStream::<TcpStream>::new_server(&**ssl_context, stream) {
241+
Ok(ssl_stream) => HttpStream::Https(ssl_stream),
242+
Err(StreamError(ref e)) => {
243+
return Err(IoError {
244+
kind: ConnectionAborted,
245+
desc: "SSL Handshake Interrupted",
246+
detail: Some(e.desc.to_string())
247+
});
248+
},
249+
Err(e) => return Err(lift_ssl_error(e))
250+
}
243251
}
244252
})
245253
}

0 commit comments

Comments
 (0)