Instaclustr has a post on their site which describes how to connect with Spark to Cassandra over SSL: Instaclustr Spark with SSL Configured Cassandra
In Step #6, they provide detail on creating a Cassandra connection factory class, which has a createSSLOptions
method that allows for the specification of specific details:
SSLOptions createSSLOPtions (CassandraConnectorConf.CassandraSSLConf conf) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException, KeyManagementException {
if (conf.trustStorePath().isEmpty()) {
return null;
}
try (InputStream trustStore = this.getClass().getClassLoader().getResourceAsStream(conf.trustStorePath().get())) {
KeyStore keyStore = KeyStore.getInstance(conf.trustStoreType());
keyStore.load(trustStore, conf.trustStorePassword().isDefined() ? conf.trustStorePassword().get().toCharArray() : null);
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext context = SSLContext.getInstance(conf.protocol());
context.init(null, tmf.getTrustManagers(), new SecureRandom());
ClassTag<String> tag = scala.reflect.ClassTag$.MODULE$.apply(String.class);
return JdkSSLOptions.builder()
.withSSLContext(context)
.withCipherSuites((String[]) conf.enabledAlgorithms().toArray(tag)).build();
}
}
They then call that method to put the finishing touches on their connection builder object:
if (conf.cassandraSSLConf().enabled()) {
SSLOptions options = createSSLOPtions(conf.cassandraSSLConf());
if (null != options) {
builder = builder.withSSL(options);
} else {
builder = builder.withSSL();
}
}
return builder;
Check out their site, and see if you can augment it to fit your needs.