【问题标题】:Channel closed when running simple example with TLS使用 TLS 运行简单示例时通道关闭
【发布时间】:2018-10-08 07:40:34
【问题描述】:

我正在尝试使用 TLS 运行官方的“Hello, World”示例,由 gRPC 团队 (code on GitHub) 提供。

我已经克隆了官方仓库并签出了标签v1.15.0

我已按如下方式运行安装脚本(如文档所示):

./gradlew installDist

我编辑了hello-world-serverhello-world-client 的启动脚本,分别运行io.grpc.examples.helloworldtls.HelloWorldServerTlsio.grpc.examples.helloworldtls.HelloWorldClientTls 类。

我已经使用 the script provided as part of the documentation 创建了 TLS 身份验证所需的证书,并将它们存储在我命名为 cert 的目录中。

最后,我运行服务器如下:

./build/install/examples/bin/hello-world-server localhost 50440 cert/server.crt cert/server.pem

服务器正常启动,输出如下:

Oct 08, 2018 9:15:10 AM io.grpc.examples.helloworldtls.HelloWorldServerTls start
INFO: Server started, listening on 50440

最后,我尝试使用以下命令在另一个 shell 上启动客户端:

./build/install/examples/bin/hello-world-client localhost 50440 cert/ca.crt

不幸的是,客户端失败并显示以下输出:

Oct 08, 2018 9:25:22 AM io.grpc.examples.helloworldtls.HelloWorldClientTls greet
INFO: Will try to greet localhost ...
Oct 08, 2018 9:25:22 AM io.grpc.examples.helloworldtls.HelloWorldClientTls greet
WARNING: RPC failed: Status{code=UNKNOWN, description=channel closed, cause=java.nio.channels.ClosedChannelException
    at io.grpc.netty.Utils.statusFromThrowable(Utils.java:169)
    at io.grpc.netty.NettyClientTransport$5.operationComplete(NettyClientTransport.java:260)
    at io.grpc.netty.NettyClientTransport$5.operationComplete(NettyClientTransport.java:254)
    at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:511)
    at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:485)
    at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:424)
    at io.netty.util.concurrent.DefaultPromise.setFailure(DefaultPromise.java:112)
    at io.netty.channel.DefaultChannelPromise.setFailure(DefaultChannelPromise.java:89)
    at io.grpc.netty.ProtocolNegotiators$AbstractBufferingHandler.fail(ProtocolNegotiators.java:564)
    at io.grpc.netty.ProtocolNegotiators$BufferUntilTlsNegotiatedHandler.userEventTriggered(ProtocolNegotiators.java:661)
    at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:329)
    at io.netty.channel.AbstractChannelHandlerContext.invokeUserEventTriggered(AbstractChannelHandlerContext.java:315)
    at io.netty.channel.AbstractChannelHandlerContext.fireUserEventTriggered(AbstractChannelHandlerContext.java:307)
    at io.netty.handler.ssl.SslUtils.handleHandshakeFailure(SslUtils.java:318)
    at io.netty.handler.ssl.SslHandler.setHandshakeFailure(SslHandler.java:1551)
    at io.netty.handler.ssl.SslHandler.channelInactive(SslHandler.java:1023)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1429)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231)
    at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:947)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:822)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:464)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.nio.channels.ClosedChannelException
    at io.netty.handler.ssl.SslHandler.channelInactive(...)(Unknown Source)
}

相互身份验证也会发生错误。

我不知道出了什么问题或者如何找到它的根本原因,你有什么指点吗?

【问题讨论】:

    标签: java ssl tls1.2 grpc grpc-java


    【解决方案1】:

    事实证明,我使用的 gRPC 和 BoringSSL 版本不兼容。

    this document 的“疑难解答”部分包含一个包含已知兼容版本库的表。

    下表是截至 2018 年 10 月的已知兼容版本:

    grpc-netty version | netty-handler version | netty-tcnative-boringssl-static version
    ------------------ | --------------------- | ---------------------------------------
    1.0.0-1.0.1        | 4.1.3.Final           | 1.1.33.Fork19
    1.0.2-1.0.3        | 4.1.6.Final           | 1.1.33.Fork23
    1.1.x-1.3.x        | 4.1.8.Final           | 1.1.33.Fork26
    1.4.x              | 4.1.11.Final          | 2.0.1.Final
    1.5.x              | 4.1.12.Final          | 2.0.5.Final
    1.6.x              | 4.1.14.Final          | 2.0.5.Final
    1.7.x-1.8.x        | 4.1.16.Final          | 2.0.6.Final
    1.9.x-1.10.x       | 4.1.17.Final          | 2.0.7.Final
    1.11.x-1.12.x      | 4.1.22.Final          | 2.0.7.Final
    1.13.x             | 4.1.25.Final          | 2.0.8.Final
    1.14.x-            | 4.1.27.Final          | 2.0.12.Final
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-15
      • 2010-10-15
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2012-04-30
      • 2011-07-12
      • 1970-01-01
      相关资源
      最近更新 更多