Wednesday, March 11, 2015

Caused by: java.security.cert.CertificateException: No subject alternative names present

When you try to make an HTTPS connection with an unmatched CN (Common Name),

you will get the following exception:

Caused by: java.security.cert.CertificateException: No subject alternative names present

It is not a usual case

but in some case like monitoring, it could be necessary.

You can work around it as follows:

HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
};

HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

Reference:
http://stackoverflow.com/questions/10258101/sslhandshakeexception-no-subject-alternative-names-present

No comments:

Post a Comment