I read a lot of material for setting up my client / server SSL system (without HTTP).
I inspired myself with the example of secure chat and the ssl server server ssl example . A cert.jks file has already been created with the command
keytool -genkey -alias app-keysize 2048 -validity 36500 -keyalg RSA -dname "CN=app" -keypass mysecret-storepass mysecret -keystore cert.jks
The secure chat example has this class:
public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi { private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } @Override public void checkClientTrusted( X509Certificate[] chain, String authType) throws CertificateException {
How do you implement this class correctly?
And in this code (in the SecureChatSslContextFactory class):
SSLContext serverContext = null; SSLContext clientContext = null; try { KeyStore ks = KeyStore.getInstance("JKS"); ks.load(SecureChatKeyStore.asInputStream(), SecureChatKeyStore.getKeyStorePassword()); // Set up key manager factory to use our key store KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); kmf.init(ks, SecureChatKeyStore.getCertificatePassword()); // Initialize the SSLContext to work with our key managers. serverContext = SSLContext.getInstance(PROTOCOL); serverContext.init(kmf.getKeyManagers(), null, null); } catch (Exception e) { throw new Error( "Failed to initialize the server-side SSLContext", e); } try { clientContext = SSLContext.getInstance(PROTOCOL); clientContext.init(null, SecureChatTrustManagerFactory.getTrustManagers(), null); } catch (Exception e) { throw new Error( "Failed to initialize the client-side SSLContext", e); }
Why do they put null
instead of tmf.getTrustManagers()
in the line serverContext.init(kmf.getKeyManagers(), null, null);
?
source share