Java 7 introduced SNI support which is enabled by default. I have found out that certain misconfigured servers send an “Unrecognized Name” warning in the SSL handshake which is ignored by most clients… except for Java. As @Bob Kerns mentioned, the Oracle engineers refuse to “fix” this bug/feature.
As workaround, they suggest to set the jsse.enableSNIExtension
property. To allow your programs to work without re-compiling, run your app as:
java -Djsse.enableSNIExtension=false yourClass
The property can also be set in the Java code, but it must be set before any SSL actions. Once the SSL library has loaded, you can change the property, but it won’t have any effect on the SNI status. To disable SNI on runtime (with the aforementioned limitations), use:
System.setProperty("jsse.enableSNIExtension", "false");
The disadvantage of setting this flag is that SNI is disabled everywhere in the application. In order to make use of SNI and still support misconfigured servers:
- Create a
SSLSocket
with the host name you want to connect to. Let’s name thissslsock
. - Try to run
sslsock.startHandshake()
. This will block until it is done or throw an exception on error. Whenever an error occurred instartHandshake()
, get the exception message. If it equals tohandshake alert: unrecognized_name
, then you have found a misconfigured server. - When you have received the
unrecognized_name
warning (fatal in Java), retry opening aSSLSocket
, but this time without a host name. This effectively disables SNI (after all, the SNI extension is about adding a host name to the ClientHello message).
For the Webscarab SSL proxy, this commit implements the fall-back setup.