We are running Spring Boot APIs where we terminate TLS in the API itself. Several times we have observed excessive CPU usage after extensive searches were caused by someone creating many connections (legitimately or erroneously because of rejected client certs) or not using TLS resumption.
To prevent these long and costly searches in the future, we would like to log when handshake fails or succeed and why and whether session resumption is being used.
We are not specifically tied to our current stack, and upgrading to a different server like Undertow or WebFlux, and/or a new version of Java would be fine as well. Similarly, we are fine using APR, NIO, or native bindings to achieve these goals.
The following other questions suggest that currently, there is no out of the box solution. They suggest extending JSSEImplementation or create customized SSL Socket Factory, or turning the level of the NIO adapter to Debug. These solutions feel fragile, and I wonder whether there is a more extendable mechanism based on events or callbacks. Alternatively, we could enable the handshake logs from Java, but those are verbose, and we would incur a significant performance hit when doing so.
- Is it possible to do a TLS handshake event in Tomcat?
- Enable Logging SSL handshake failure(Audit purpose logs) only on Tomcat 8+ with Java
Update1:
I've tried to go the route of using a customized SSLServerSocketFactory. The sun.security.ssl.SSLServerSocketFactoryImpl
returns a sun.security.ssl.SSLServerSocketImpl
on bind which returns a nice SSLSocket
on accept. I could wrap that accept method always to add a completion handler. The only drawback is: SSLServerSocketFactoryImpl
is final, so I cannot just wrap it. This means I need to copy a lot of code, and it still would only give me metrics on successful handshakes. Copying the code would be a maintenance burden because this is JRE specific code.