~/ learn/ comp-348/ cards/ SSLServerSocket and keystores
1 of 5

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

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/8d6fac14-0616-4a8e-9ae5-e9ecfbfcd189/flashcard utf-8 LF