我正在尝试通过 GRPC-SSL 将 Java 客户端连接到非 Java 服务器。不使用 SSL 时,我能够连接到服务器。当我尝试使用 SSL 上下文(使用提供的 pem 文件)创建 ManagedChannel 时,出现以下异常(相同的 pem 文件适用于 NodeJS 客户端)。
ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 10010)
.sslContext(GrpcSslContexts.forClient().trustManager(new File("./test/myprivkey.pem")).build())
.build();
trustManager 调用的异常:
Exception in thread "main" java.lang.IllegalArgumentException: File does not contain valid certificates: /Users/continue/IdeaProjects/git/test/build/resources/main/keys/myprivkey.pem
at io.netty.handler.ssl.SslContextBuilder.trustManager(SslContextBuilder.java:162)
at com.test.io.grpc.test.client.Connection.getSslContext(Connection.java:65)
at com.test.io.grpc.test.client.Connection.getSecure(Connection.java:41)
at com.test.io.grpc.mgcs.client.TestClient.<init>(TestClient.java:36)
at com.test.io.grpc.test.client.TestClient.main(TestClient.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.security.cert.CertificateException: found no certificates in input stream
at io.netty.handler.ssl.PemReader.readCertificates(PemReader.java:98)
at io.netty.handler.ssl.PemReader.readCertificates(PemReader.java:64)
at io.netty.handler.ssl.SslContext.toX509Certificates(SslContext.java:999)
at io.netty.handler.ssl.SslContextBuilder.trustManager(SslContextBuilder.java:160)
build.gradle 相关部分
compile 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork26'
有什么想法可能导致问题或如何进一步解决这个问题?