cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
676 stars 160 forks source link

Server going down on SSL errors: Wider exception catching in ListenAsync #146

Closed nopap closed 8 months ago

nopap commented 3 years ago

Hi, With IsSecure enabled, if a client sends crap to the server it simply goes down with Exception 'The handshake failed due to an unexpected packet format.' In ListenAsync only the OperationCanceledException is currently catched, i propose to catch a wider range to prevent the server from going completely down on errors. I'm running right now with all exceptions catched, but maybe a subset only would be necessary.

What do you think ?

cosullivan commented 3 years ago

Hi,

When you say that the client sends crap, are you saying that the client doesn't complete the SSL handshake but starts sending commands instead?

nopap commented 3 years ago

Hi, yes whe the client send something/anything which is not the expected TLS handshake. For example a simple curl to the server will put it down due to invalid handshake.

cosullivan commented 3 years ago

Hi @nopap ,

I've just pushed a fix for this so it now also catches the IOException that can be thrown here and then also ensures that the original Pipe is disposed.

Thanks, Cain.