java.security.cert.CertificateException: No subject alternative names matching IP address xxx.xxx.xxx foundor
java.security.cert.CertificateException: No subject alternative DNS name matching hostname.com found.The reason is because the certificate did not set the correct subject alternative value correctly. Two possible solution for above scenario:
- Change certificate’s subject alternative value
- Create customize HostnameVerifier
If you’re connecting to your host by using IP address, then you must change the subject alternative value to your IP address value. Likewise if you’re connecting using DNS name, the subject alternative value must match with the DNS name.
Create Customize HostnameVerifier
Basically you just need to create your customized HostnameVerifier class like example below:
private static class CustomizedHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
and then apply this class to your single SSL connection
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://url").openConnection();
connection.setHostnameVerifier(new CustomizedHostNameVerifier());
connection.setHostnameVerifier(new CustomizedHostNameVerifier());
or apply to all SLL connection
HttpsURLConnection.setDefaultHostnameVerifier(new CustomizedHostnameVerifier());
However this method might pose a security risk because basically we don’t verify the hostname anymore. The server may use other website’s certificate and the program will still accept it.
Our company recently wanted to add several of it's domains under the one certificate, so we approached a company specialising in Subject Alt Name SSL certificates on the Exchange 2007. This has been with a trusted certificate and we've had fantastic response from our customers across the domains at the added security.
ReplyDeleteYour blog site is useful but you blog title is discriminatory. Why don't you just make it something like Jarsehole.
ReplyDeleteThe reason is simple, I hate Java as much as I love them. And this blog's content consists mostly of the technical challenge that I've encountered a long the way.
ReplyDeletePlease don't think too much of the reason behind my blog title, it's just something pops out on top of my head that makes me smile.
Great! But how to change certificate’s subject alternative value? Thanks in advance
ReplyDelete"private static class" , this should be public class... this wont compile.
ReplyDelete