Java, SSL, and the unrecognized_name Error

This post explains a common cause of Java SSL `unrecognized_name` handshake errors after certificate changes: a mismatched Apache `ServerName` in VirtualHost configuration. It shows why disabling SNI is only a workaround and how to fix the root server configuration issue instead.

Coveros Staff

December 12, 2016

We ran into a problem on my most recent project with a weird error popping up when installing a wildcard SSL cert into an Apache webserver. We had previously been using a self-signed cert and the Java clients attempting to connect to this site had the old self-signed cert installed into their keystores. Once the new cert was installed, however, we started seeing an issue for all the Java clients attempting to connect to the site:

javax.net.ssl.SSLProtocolException: handshake alert: unrecognized\_name

Crucially, no other clients were having trouble connecting to this site, including web browsers, curl, chef, etc. This and a bit of googling quickly sent us down the wrong path, believing the issue was that Java wouldn’t recognize the wildcard cert for whatever reason. So for a long while we just added the SSL ignore option to our Java clients and left it at that:

-Djsse.enableSNIExtension=false

The truth is, this is totally unnecessary. This problem arises from a really simple misconfiguration and it’s just as easily resolved. In our case, the Apache configuration had been updated to point at the new cert, but the ServerName attribute of the VirtualHost configuration hadn’t changed, it was still referring to the machine by its old hostname. Most clients don’t care about this, as long as the site is reachable via the correct domain (e.g. https://sub.domain.com), they will validate the certificate. Java, however, is stricter and requires that the ServerName reported by the webserver also match the certificate’s valid domain.

This problem is a bit tough to Google for, since if you search for wildcard certs and Java, you won’t find your way to this simple fix. You’ll be told to just turn off SSL validation, which effectively just ignores the problem. The real fix is even simpler and hopefully this post makes it easier to find for anyone else who runs into the same issue.

tl;dr: Check your Apache VirtualHost configuration: you likely have the ServerName misconfigured and only Java cares.

Coveros Staff

Coveros Staff

This post represents the collective insights of the Coveros team. Our staff consists of software experts who bring deep experience in secure agile development, DevOps, testing, and software quality. Over the past 20 years, Coveros has trained more than 30,000 professionals and worked with half of the Fortune 100 companies on mission-critical software development challenges. We draw on this extensive experience to share practical insights, proven strategies, and real-world solutions that help organizations build better software faster and more securely.