title: Add trustStore for client authentication
body: <p>A <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/samples/sockets/server/ClassFileServer.java" rel="nofollow noreferrer">server</a> and respective <a href="http://docs.oracle.com/javase/7/docs/technotes/guides/security/jsse/samples/sockets/client/SSLSocketClientWithClientAuth.java" rel="nofollow noreferrer">client</a> support client authentication but as noted here: <a href="https://stackoverflow.com/questions/9548807/sslhandshakeexception-no-cipher-suites-in-common">SSLHandshakeException: no cipher suites in common</a>, do not have trustStore reference, i.e. they use the default trustStore. How can the trustStore be specified?</p>
  
  <p><strong>ClassFileServer:</strong></p>
  
  <pre><code>private static ServerSocketFactory getServerSocketFactory(String type) {
      if (type.equals("TLS")) {
          SSLServerSocketFactory ssf = null;
  
          Properties systemProps = System.getProperties();
          systemProps.put( "javax.net.ssl.trustStore", "cacerts.jks");
          systemProps.put( "javax.net.ssl.trustStorePassword", "p@ssw0rd");
          System.setProperties(systemProps);
  
          try {
              // set up key manager to do server authentication
              SSLContext ctx;
              KeyManagerFactory kmf;
              KeyStore ks;
              char[] passphrase = "p@ssw0rd".toCharArray();
  
              ctx = SSLContext.getInstance("TLS");
              kmf = KeyManagerFactory.getInstance("SunX509");
              ks = KeyStore.getInstance("JKS");
              ks.load(new FileInputStream("keystore.jks"), passphrase);
              kmf.init(ks, passphrase);
              ctx.init(kmf.getKeyManagers(), null, null);
  
              ssf = ctx.getServerSocketFactory();
              return ssf;
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p><strong>SSLSocketClientWithClientAuth:</strong></p>
  
  <pre><code>    try {
  
          /*
           * Set up a key manager for client authentication
           * if asked by the server.  Use the implementation's
           * default TrustStore and secureRandom routines.
           */
          Properties systemProps = System.getProperties();
          systemProps.put( "javax.net.ssl.trustStore", "cacerts.jks");
          systemProps.put( "javax.net.ssl.trustStorePassword", "changeit");
          System.setProperties(systemProps);
  
          SSLSocketFactory factory = null;
          try {
              SSLContext ctx;
              KeyManagerFactory kmf;
              KeyStore ks;
              char[] passphrase = "changeit".toCharArray();
  
              ctx = SSLContext.getInstance("TLS");
              kmf = KeyManagerFactory.getInstance("SunX509");
              ks = KeyStore.getInstance("JKS");
  
              ks.load(new FileInputStream("keystore.jks"), passphrase);
  
              kmf.init(ks, passphrase);
              ctx.init(kmf.getKeyManagers(), null, null);
  
              factory = ctx.getSocketFactory();
          } catch (Exception e) {
              throw new IOException(e.getMessage());
          }
  
          SSLSocket socket = (SSLSocket)factory.createSocket(host, port);
  </code></pre>