我正在尝试连接到cassandra集群通过java datastax驱动程序与openssl按照这个文件https://docs.datastax.com/en/developer/java-driver/3.1/manual/ssl/ 以我的客户机证书和密钥以及信任库为例,我的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静态dep或tcnative dep,但似乎仍然不起作用。任何帮助都将不胜感激。
先谢谢你
1条答案
按热度按时间oo7oh9g91#
我怀疑这里可能发生的事情是由于
netty
,netty-tcnative
以及netty-tcnative-boringssl-static
在这里使用。在以前的实验中,我发现
netty
以及netty-tcnative
尤其重要的是,两者之间可能存在不兼容。datastax java driver 3.6.0依赖于netty 4.0.56.final,并将netty tcnative 2.0.7.final列为可选依赖项。您还可以在java driver 3.6.0的文档中找到建议使用的2.0.7.final:
较新版本的netty tcnative与驱动程序使用的netty版本之间存在已知的运行时不兼容。为了获得最佳效果,请使用版本2.0.7.final。
我还怀疑没有使用相同版本的
netty-tcnative
以及netty-tcnative-boringssl-static
可能导致不兼容。我建议尝试同样的版本。既然我已经测试过了,我将首先尝试以下配置: