Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>SSL can provide hints to the client about which certificate to present. This <em>might</em> allow you to use one key store with multiple identities in it, but, unfortunately, most servers don't use this hinting feature. So, it will be more robust if you specify the client certificate to use on for each connection.</p> <p>Here is sample code to set up one <code>SSLContext</code> with specified identity and trust stores. You can repeat these steps to create multiple contexts, one for each client certificate you want to use. Each <code>SSLContext</code> would probably use the same trust store, but a different identity store (containing the single client key entry to be used in that context). </p> <p>Initialize the contexts that you will need one time, and reuse the the correct one for each connection. If you are making multiple connections, this will allow you to take advantage of SSL sessions.</p> <pre><code>KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(identityStore, password); TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(trustStore); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); </code></pre> <p>Later, you can create a socket directly:</p> <pre><code>SSLSocketFactory factory = ctx.getSocketFactory(); Socket socket = factory.createSocket(host, port); </code></pre> <p>Or, if you are using the <code>URL</code> class, you can specify the <code>SSLSocketFactory</code> to use when making HTTPS requests:</p> <pre><code>HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); con.setSSLSocketFactory(ctx.getSocketFactory()); </code></pre> <p>Java 6 has some additional API that makes it easier to configure sockets according to your preferences for cipher suites, etc.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload