title: How can my library with built in ssl certificate also allow use with default certs
body: <p>I am distributing a library jar for internal clients, and the library includes a certificate which it uses to call a service that is also internal to our network.</p>
  
  <p>The trust manager is set up as follows</p>
  
  <pre><code>    TrustManagerFactory trustManagerFactory = 
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      KeyStore keystore = KeyStore.getInstance("JKS");
      InputStream keystoreStream = 
        clazz.getClassLoader().getResourceAsStream("certs.keystore"); // (on classpath)
      keystore.load(keystoreStream, "pa55w0rd".toCharArray());
      trustManagerFactory.init(keystore);
      TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
      SSLContext context = SSLContext.getInstance("SSL");
      context.init(null, trustManagers, null);
  
      SSLSocketFactory socketFact = context.getSocketFactory();
      connection.setSSLSocketFactory(socketFact);
  </code></pre>
  
  <p>All of this works fine except in cases where users need other certificates or the default certificate.</p>
  
  <p>I tried this
  <a href="https://stackoverflow.com/questions/1793979/registering-multiple-keystores-in-jvm">Registering multiple keystores in JVM</a> with no luck (I am having trouble generalizing it for my case)</p>
  
  <p>How can I use my cert and still allow user libraries to use their own certs as well?</p>