【发布时间】:2019-10-13 04:38:12
【问题描述】:
我正在尝试通过带有 openssl 的 java datastax 驱动程序连接到 cassandra 集群,根据此文档 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-static dep 或 tcnative dep,但它似乎仍然不起作用。任何帮助将不胜感激。
提前谢谢你
【问题讨论】:
-
@Jayr 感谢您的回复。我正在使用最新版本,并且还在我的 dep 中添加了 netty-tcnative。不知道根据 github 问题我还能做什么。
-
您是否启用了跟踪?在共享的线程中,在类在临时文件夹中创建“so”后,最终可能会出现一条关于成功加载本机的消息