botan icon indicating copy to clipboard operation
botan copied to clipboard

How to identify a bad TLS connection?

Open tzimmer63 opened this issue 3 years ago • 4 comments

Hi, I've build a small https server with botan. If a client connects with http instead of https (or I get other garbage), how do I find out that a valid TLS session was not established? I did not find anything in the TLS Callback that informs me about incoming garbage and let me close the TCP connection.

tzimmer63 avatar Jul 01 '21 14:07 tzimmer63

Currently Botan (master or 3.0.0-alpha0) is performing some 'pre-check' of the TLS record version and if it does not match the expected one, then the content of the record header is compared with common HTTP request methods: GET, PUT, POST, HEAD, CONNE. If any of the HTTP request methods is matching, then the handshake is immediately interrupted with PROTOCOL_VERSION alert. There are probably no other checks of garbage input, but there is a PR with improved check of record content: https://github.com/randombit/botan/pull/2755

pstanisz avatar Jul 01 '21 19:07 pstanisz

The checking @pstanisz mentioned is also available in 2.18.0 and higher so you don't need to use pre-release software to get this.

randombit avatar Jul 01 '21 23:07 randombit

I've upgraded to 2.18.1 and I do not get the described behaviour. When calling the server with unencrypted http, I'm not getting a tls_alert() call in the TLS_Callback. Instead, I'm getting an exception "Got unexpected TLS record version". I have no problem with that, it helps a lot, I just wanted to let you know that. Thanks a lot, guys.

tzimmer63 avatar Jul 02 '21 10:07 tzimmer63

tls_alert is only called when you receive an alert from the peer, here we are sending an alert and there is no callback/inspection for this process (though that might indeed be useful for debugging and the like, something to think about there...)

randombit avatar Jul 04 '21 13:07 randombit