Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send fatal alert on server_config_provider failure #27

Merged
merged 2 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,31 @@ impl TlsStream {
tcp_handshake.readable().await?;
read_acceptor(&tcp_handshake, &mut acceptor)?;
if let Some(accepted) = acceptor.accept().map_err(rustls_to_io_error)? {
let f = server_config_provider(accepted.client_hello());
let config = f.await?;
let config = match server_config_provider(accepted.client_hello()).await
{
Ok(config) => config,
Err(err) => {
// This is a bad case. The provider was supposed to give us a config, but instead it failed.
//
// There's no easy way to reject an acceptor, and we only have an Arc for the stream so we can't close
// it. Instead we send a fatal alert manually which is effectively going to close the stream.
//
// Wireshark packet decode:
// TLSv1.2 Record Layer: Alert (Level: Fatal, Description: Close Notify)
// Content Type: Alert (21)
// Version: TLS 1.2 (0x0303)
// Length: 2
// Alert Message
// Level: Fatal (2)
// Description: Close Notify (0)
const FATAL_ALERT: &[u8] = b"\x15\x03\x03\x00\x02\x02\x00";
for c in FATAL_ALERT {
tcp_handshake.writable().await?;
tcp_handshake.try_write(&[*c])?;
}
return Err(err);
}
};
let tls = accepted
.into_connection(config)
.map_err(rustls_to_io_error)?;
Expand Down
Loading