code_junkie

Java Client to connect to Server with Openssl and Client Auth

Nov 13th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. KeyStore tks = KeyStore.getInstance(KeyStore.getDefaultType());
  2. tks.load(...); /* Load the trust key store with root CAs. */
  3. TrustManagerFactory tmf =
  4. TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  5. tmf.init(tks);
  6. KeyStore iks = KeyStore.getInstance(KeyStore.getDefaultType());
  7. iks.load(...); /* Load the identity key store with your key/cert. */
  8. KeyManagerFactory kmf =
  9. KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  10. kmf.init(iks, password);
  11. SSLContext ctx = SSLContext.getInstance("TLS");
  12. ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
  13. SocketFactory factory = ctx.getSocketFactory();
  14. Socket socket = factory.createSocket(host, port);
  15.  
  16. SocketFactory factory = SSLSocketFactory.getDefault();
  17. Socket socket = factory.createSocket(host, port);
Add Comment
Please, Sign In to add comment