Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The twist here is that you are using client authentication, so you need a private key and a certificate to identify yourself. You provide this to JSSE by specifying KeyManagers when you initialize an SSLContext. </p> <h2>Customizable Setup</h2> <p>Following are the basic steps. The JSSE API was significantly improved in Java 6, but I'll stick with Java 5, in case you're stuck on that version.</p> <pre><code>KeyStore tks = KeyStore.getInstance(KeyStore.getDefaultType()); tks.load(...); /* Load the trust key store with root CAs. */ TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(tks); KeyStore iks = KeyStore.getInstance(KeyStore.getDefaultType()); iks.load(...); /* Load the identity key store with your key/cert. */ KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(iks, password); SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); SocketFactory factory = ctx.getSocketFactory(); Socket socket = factory.createSocket(host, port); </code></pre> <h2>System Configuration</h2> <p>An alternative "zero-config" scenario can be used when using the <code>SunJSSE</code> provider. I believe many other providers (like IBM) have followed the same pattern and will work as well. The mechanism uses <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#getProperties()" rel="nofollow noreferrer">system properties,</a> and is described in detail by the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#InstallationAndCustomization" rel="nofollow noreferrer">JSSE Reference Guide.</a></p> <p>For client authentication, the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#CustomizingStores" rel="nofollow noreferrer">important properties</a> are <code>javax.net.ssl.keyStore</code> and <code>javax.net.ssl.keyStorePassword</code>. The values should be the path to the user's key store and the password for that key store's "key entries", respectively.</p> <p>When using these properties, you can create a new SSLSocket that supports client authentication like this:</p> <pre><code>SocketFactory factory = SSLSocketFactory.getDefault(); Socket socket = factory.createSocket(host, port); </code></pre> <p>Since you are using the "default" <code>SSLSocketFactory</code>, which depends on the system-wide properties, all sockets created in the JVM will authenticate with the same certificate. If you need more control than that, you have to use the "Customizable Setup" above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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