title: Java: Accepting self-signed certificates
body: <p>I use the following TrustManager to accept self-signed certificates from my local test server in my Java application:</p>
  
  <pre><code>public class CertificateAcceptor {
  
      private TrustManager[] createTrustManager() {
          TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
  
              public X509Certificate[] getAcceptedIssuers() {
                  return null;
              }
  
              public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                  // leave blank to trust every client
              }
  
              public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                  // leave blank to trust every client
              }
          }};
          return trustAllCerts;
      }
  </code></pre>
  
  <p>I have some security concerns with that, since as far as I know, this accepts just all certificates. So I'm asking myself if there is a way to only accept certificates that are coming from localhost on Port 9443?</p>