Java – CertificateException: No name matching xxx found

At paysafecard we have a lot to deal with certificates. For our test systems we use one SSL certificate for different sub-domains, e.g. one certificate for “https://test.yunacard.com” used for “https://testa.yunacard.com” and “https://testb.yunacard.com”.

But when you do this, you get a javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching xxx found when trying to connect e.g. with new java.net.URL(url).openStream();

The work around for this problem is, to include the following in your Java class (found here):

public class ClassBla {
  static {
    javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
      public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
        return true;
      }
   });
  }
  ..
}

There is a way to import a certificate issued to a different domain for another certain (sub-)domain with the java keytool as well.

Advertisements
This entry was posted in howtos, work and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s