Monday, June 24, 2024

Java SSL exceptions are not really the end of the world

Have you ever felt like an end of the world when you tried to make a HTTP call and end up with an SSL exception in java? then you are probably not alone. 

For most of us the java SSL errors are vague and leave us with no option on how to fix that. Its because in the stacktrace, usually there will not be any specific message, except mostly the PKIX path building failed message, which points to the exact problem, where the fix might be needed.  

But there is nothing to worry about it. If you don't know your way around this exception, all you need to know about is the system property javax.net.debug.

Setting the system property as javax.net.debug=all would print all the certificate exchanges and SSL handshake messages that happens between client and server to the log.

Using that log it should be relatively easy to understand what causes the SSL connection failure.

Since it's a system property it can be set as a jvm argument when starting up the java program in a similar way like java -Djavax.net.debug=all

This property certainly make the debugging and understanding of the SSL errors better.

In case if you wanted to know more about this property then check out the guide Debugging SSL/TLS Connections in javase docs.