我有信任库和密钥库文件,以及与cassandra帐户有关的所有信息。我用来连接到cassandra的应用程序有一个限制,因为它没有提供给我指定我的信任库和密钥库文件的选项,因此我一直在寻找是否可以使用连接url属性(url属性)通过ssl连接到cassandra )
感谢您的帮助!
答案 0 :(得分:0)
Instaclustr在其网站上有一篇帖子,描述了如何通过SSL通过Spark与Cassandra连接Spark:Instaclustr Spark with SSL Configured Cassandra
在步骤#6中,他们提供了有关创建Cassandra连接工厂类的详细信息,该类具有createSSLOptions
方法,该方法允许指定特定的细节:
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();
}
}
然后,他们调用该方法在其连接构建器对象上进行最后的修饰:
if (conf.cassandraSSLConf().enabled()) {
SSLOptions options = createSSLOPtions(conf.cassandraSSLConf());
if (null != options) {
builder = builder.withSSL(options);
} else {
builder = builder.withSSL();
}
}
return builder;
查看他们的网站,看看是否可以扩展以满足您的需求。