protected static SSLContext getSSLContext(MongoDBConnectionConfig config) { try { KeyStore trustStore = loadKeyStore(config.trustStorePath, config.trustStorePassword, config.trustStoreType); KeyStore keyStore = loadKeyStore(config.keyStorePath, config.keyStorePassword, config.keyStoreType); if (trustStore == null && keyStore == null) { return null; } SSLContextBuilder sslContextBuilder = SSLContexts.custom(); if (trustStore != null) { sslContextBuilder.loadTrustMaterial(trustStore, null); } if (keyStore != null) { sslContextBuilder.loadKeyMaterial(keyStore, null); } return sslContextBuilder.build(); } catch (GeneralSecurityException | IOException e) { throw new RuntimeException("Cannot setup SSL context: " + config, e); } }