title: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative names matching IP address
body: <p>I have a java application calling external api which is hosted on address like <a href="https://10.20.30.40:1234/test/myurl" rel="nofollow noreferrer">https://10.20.30.40:1234/test/myurl</a></p>
  <p>this have a domain base certifcate with CN like *.myappdomain.au</p>
  <p>We have done registration on our linux server of the certificate.
  I have even tried loading the certificate with following code but it is of no use and we are getting same error</p>
  <pre><code>private static SSLSocketFactory createSSLSocketFactory(String certificatePath) throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
          File crtFile = new File(certificatePath);
          
          Certificate certificate = CertificateFactory.getInstance(&quot;X.509&quot;).generateCertificate(new FileInputStream(crtFile));
  
          KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
          keyStore.load(null, null);
          keyStore.setCertificateEntry(&quot;server&quot;, certificate);
  
          TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
          trustManagerFactory.init(keyStore);
  
          SSLContext sslContext = SSLContext.getInstance(&quot;TLS&quot;);
          sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
  
          return sslContext.getSocketFactory();
      }
  </code></pre>
  <p>One thing i tried which work is adding entry in host like
  10.20.30.40 myappdomain.au
  and then using url like
  <a href="https://myappdomain.au:1234/test/myurl" rel="nofollow noreferrer">https://myappdomain.au:1234/test/myurl</a></p>
  <p>then application works</p>
  <p>Any idea what more i need to do</p>