Skip to content

Interpret end of incoming TLS stream as EOF - #779

Closed
djc wants to merge 1 commit into
rustls:mainfrom
djc:no-alert-eof
Closed

djc wants to merge 1 commit into
rustls:mainfrom
djc:no-alert-eof

Conversation

@djc

@djc djc commented Jul 8, 2021

Copy link
Copy Markdown
Member

The peer is not required to send us CloseNotify, but if the socket has
shutdown we should act accordingly.

Fixes #777.

Probably needs further comment updates and some tests.

The peer is not required to send us `CloseNotify`, but if the socket has
shutdown we should act accordingly.
@djc
djc marked this pull request as draft July 8, 2021 21:20
@briansmith

Copy link
Copy Markdown
Contributor

I think @hawkw is going to review this. Just want to add that we should add a test for this before merging.

@hawkw hawkw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one major comment here --- what do you think?

Comment thread rustls/src/conn.rs
/// Are we done? i.e., have we processed all received messages,
/// and received a close_notify to indicate that no new messages
/// will arrive?
/// will arrive or ran out of bytes on the incoming TLS stream?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comments #563 (comment), #563 (comment), #563 (comment) suggest that a TLS connection closing without a CloseNotify ought to be considered an error (although the user should be able to ignore that error if they choose to). it looks like this code will now always return a clean error (Ok(0)) regardless of whether a CloseNotify was received or the TCP connection just closed without one?

I think we should probably be distinguishing between CloseNotify and closing a connection without a CloseNotify, and return an io::Error in that case.

IMO, ErrorKind::UnexpectedEof is probably the most correct error kind to use to indicate that a connection was closed without a CloseNotify, but I'm open to being convinced otherwise...i do think it's important to use an ErrorKind that rustls won't return in other cases, so user code can programmatically distinguish between the underlying connection EOF and other errors.

I wonder if it's also worth adding an option to consider TCP connection EOFs without CloseNotify a clean EOF, since some use cases may require talking to peers that don't support CloseNotify? Or is it sufficient to just allow the user to ignore that error kind themself?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be reported as an error rather than a 'clean' EOF. UnexpectedEof sounds like an excellent option, as does ConnectionAborted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, I have a slight preference for UnexpectedEof over ConnectionAborted, as I think it's possible that the I/O reader passed to read_tls may return ConnectionAborted, but it probably won't return UnexpectedEof, so it's clearer where the error came from. But, either is probably fine here.

@djc

djc commented Jul 9, 2021

Copy link
Copy Markdown
Member Author

@ctz I probably won't have much time to work on this over the weekend. If you want to take it over, please feel free. Otherwise I'll pick it back up on Monday.

@ctz

ctz commented Jul 11, 2021

Copy link
Copy Markdown
Member

I think I've addressed the above comments in 0b2b9bf

@djc

djc commented Jul 12, 2021

Copy link
Copy Markdown
Member Author

FWIW, your changes look good to me.

Comment thread rustls/src/conn.rs
/// sized chunks (like a socket or pipe might).
pub(crate) fn read_tls(&mut self, rd: &mut dyn io::Read) -> io::Result<usize> {
self.message_deframer.read(rd)
let res = self.message_deframer.read(rd);

@fantix fantix Jul 19, 2021 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the read() should not happen here if self.peer_eof is already true? The peer may not immediately terminate the TCP connection after sending a CloseNotify, and read() here will return WantRead error, leading to the caller waiting in Pending instead of getting a ConnectionAborted error with CloseNotify alert received as the message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

potentially questionable overloading of ErrorKind::WouldBlock

5 participants