Load a keystore and build an SSLContext from it
Load a keystore and build an SSLContext from it
Answer
char[] password = System.console().readPassword(); KeyStore store = KeyStore.getInstance("PKCS12"); store.load(new FileInputStream("server.p12"), password); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(store, password); SSLContext context = SSLContext.getInstance("TLS"); context.init(kmf.getKeyManagers(), null, null); Arrays.fill(password, '0');
This is the whole ceremony the client side never needed. The two nulls accept the default trust managers and the default randomness source; the final fill wipes the passphrase out of the heap rather than waiting for the collector.
Harold 4e ch10 §Creating Secure Server Sockets; §Configuring SSLServerSockets