【问题标题】:connecting cassandra through ssl with datastax cassandra JAVA driver通过 ssl 将 cassandra 与 datastax cassandra JAVA 驱动程序连接
【发布时间】:2021-02-09 20:52:40
【问题描述】:

我正在使用 datastax cassandra 3.6.0 版并尝试使用 ssl 连接到 cassandra。 我有一个 ca 证书已经存储在 dir "/etc/ssl/certs/cassandra.crt" 中。

我在 JAVA 中创建了一个 cassandra 集群:

cluster = Cluster.builder().addContactPoints(hostArray).withPort(Integer.parseInt(port)).withCredentials(username, password).build();
 

我确实在构建器中看到带有withSSL(SSLOptions) 的a, 如何使用上述证书文件在 java 中创建 SSLOPtions 以便我可以使用它来创建集群?

在 Python 中我有

        ssl_opts = {"ca_certs": "/etc/ssl/certs/cassandra.crt"}
        auth_provider = PlainTextAuthProvider( username , password )
        cluster = Cluster(
            cluster_ips,
            auth_provider=auth_provider,
            port=20102,
            ssl_options=ssl_opts,
            load_balancing_policy=DCAwareRoundRobinPolicy()
        )

如何使用crt文件在java中创建集群?

【问题讨论】:

    标签: java ssl cassandra ssl-certificate cassandra-driver


    【解决方案1】:

    您需要先创建 SSLContext。要创建 SSLContext,您可以参考此处的示例SSLContext Example。一旦你有 SSLConext 对象,你可以得到 SSLOptions 如下

     JdkSSLOptions sslOptions = JdkSSLOptions.builder().withSSLContext(context).withCipherSuites(theCipherSuites).build();
    

    然后你可以在 withSSL 方法中传递这个 sslOptions 为

    cluster = Cluster.builder().addContactPoints(hostArray).withPort(Integer.parseInt(port)).withCredentials(username, password).withSSL(sslOptions).build();
    
     
    

    【讨论】:

      【解决方案2】:

      在 Java 驱动程序 v3.6 中,您使用 RemoteEndpointAwareSSLOptions 类配置 SSL,该类使用 JSSE 系统属性(由 -Djavax.net.ssl.* 指定)。

      如果您需要的超出系统属性允许的范围,请使用 RemoteEndpointAwareJdkSSLOptions 类以编程方式配置 SSL。

      详情请见Java driver 3.6 SSL页面。

      附带说明,驱动程序的 v3.6 于 2018 年 8 月发布,所以它非常旧。如果您正在开发新应用,我们建议您使用最新版本的驱动程序。如果您在使用旧版本时遇到问题,则无论如何都需要升级才能获得修复。干杯!

      【讨论】:

      • 4.x 库中withSSL(RemoteEndpointAwareJdkSSLOptions.builder().build()) 的等价物是什么?我尝试使用withSslEngineFactory(DefaultSslEngineFactory(driverContext)) 创建一个CqlSession.builder(),但这需要一个driverContext,我们只能在创建cql 会话(session.getContext())后才能获得它。请告诉我如何将 3.x 代码中的 SSL 部分迁移到 4.x
      • @sujithkrishnan 请记录一个新问题,因为您的后续问题与本文中提出的问题不同。干杯!
      猜你喜欢
      • 2013-12-23
      • 2018-02-15
      • 1970-01-01
      • 2015-10-25
      • 2023-03-21
      • 2018-04-16
      • 2013-07-14
      • 2016-02-27
      • 2017-01-20
      相关资源
      最近更新 更多