gpt4 book ai didi

java - 使用 openssl 的 cassandra java 客户端

转载 作者:行者123 更新时间:2023-11-30 01:50:16 29 4
gpt4 key购买 nike

我正在尝试按照此文档 https://docs.datastax.com/en/developer/java-driver/3.1/manual/ssl/ 通过 java datastax 驱动程序和 openssl 连接到 cassandra 集群使用我的客户端证书和 key 以及信任库,因为我的 cassandra 集群需要两种方式的相互证书身份验证

这是我的代码

public static void main( String[] args ) throws Exception
{
KeyStore ks = KeyStore.getInstance("JKS");
// make sure you close this stream properly (not shown here for brevity)
InputStream trustStore = new FileInputStream("MyTrustStore");
ks.load(trustStore, "abcdef".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);

SslContextBuilder builder = SslContextBuilder
.forClient()
.sslProvider(SslProvider.OPENSSL)
.trustManager(tmf)
// only if you use client authentication
.keyManager(new File("client_cert"), new File("private_key"));


SSLOptions sslOptions = new NettySSLOptions(builder.build());


Cluster cluster = Cluster.builder()
.addContactPoint("w.x.y.z")
.withSSL(sslOptions)
.build();


}

我的 pom 中有以下依赖项

<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>2.0.25.Final</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.0.Final</version>
<classifier>osx-x86_64</classifier>
</dependency>
</dependencies>

但是我收到错误

Exception in thread "main" java.lang.UnsatisfiedLinkError: failed to load the required native library
at io.netty.handler.ssl.OpenSsl.ensureAvailability(OpenSsl.java:327)
at io.netty.handler.ssl.ReferenceCountedOpenSslContext.<init>(ReferenceCountedOpenSslContext.java:193)
at io.netty.handler.ssl.ReferenceCountedOpenSslContext.<init>(ReferenceCountedOpenSslContext.java:182)
at io.netty.handler.ssl.OpenSslContext.<init>(OpenSslContext.java:34)
at io.netty.handler.ssl.OpenSslClientContext.<init>(OpenSslClientContext.java:188)
at io.netty.handler.ssl.SslContext.newClientContextInternal(SslContext.java:775)
at io.netty.handler.ssl.SslContextBuilder.build(SslContextBuilder.java:446)
at com.example.App.main(App.java:41)
Caused by: java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_osx_x86_64, netty_tcnative_x86_64, netty_tcnative]
at io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:93)
at io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:421)
at io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:89)
... 7 more

我尝试从 pom 中删除 Boringssl-static dep 或 tcnative dep,但它似乎仍然不起作用。任何帮助将不胜感激。

提前谢谢

最佳答案

我怀疑这里可能发生的情况是由 nettynetty-tcnativenetty-tcnative-boringssl-static 版本之间的不兼容引起的 在这里使用。

在之前的实验中,我发现 nettynetty-tcnative 的版本特别重要,因为两者之间可能存在不兼容性。

datastax java 驱动程序 3.6.0 依赖于 netty 4.0.56.Final 并将 netty-tcnative 2.0.7.Final 列为可选依赖项。您还可以find in the documentation对于 java 驱动程序 3.6.0,建议使用 2.0.7.Final:

There are known runtime incompatibilities between newer versions of netty-tcnative and the version of netty that the driver uses. For best results, use version 2.0.7.Final.

我还怀疑不使用相同版本的 netty-tcnativenetty-tcnative-boringssl-static 可能会导致不兼容。我建议尝试相同的版本。

既然我已经对此进行了测试,我将首先尝试以下配置:

<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative</artifactId>
<version>2.0.7.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.7.Final</version>
<classifier>osx-x86_64</classifier>
</dependency>
</dependencies>

关于java - 使用 openssl 的 cassandra java 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56328840/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com