【发布时间】:2020-04-28 12:37:51
【问题描述】:
我正在尝试在 Android 应用中使用 grpc
代码的重要部分是这样的:
private val managedChannel: ManagedChannel = ManagedChannelBuilder
.forTarget("misserverurl.com")
.build()
带有版本和依赖的build.gradle:
minSdkVersion 19
implementation "io.grpc:grpc-okhttp:1.26.0"
implementation "io.grpc:grpc-protobuf:1.26.0"
implementation "io.grpc:grpc-stub:1.26.0"
protos 似乎没问题,并且应用程序在没有 TLS 的情况下也能正常工作 (.usePlaintext())
但我收到此错误:
java.lang.RuntimeException: TLS ALPN negotiation failed with protocols: [grpc-exp, h2]
SSL 握手似乎有问题。
奇怪的是服务器使用 BloomRCP 使用 TLS 工作。
我尝试了不同的 minSdkVersions,也使用了不同的 io.grpc.* lib 版本,并创建了一个空的 repo,其中只有 proto 文件和运行它的基本代码,但没有添加 .connectionSpec() 和不同的 CipherSuite 作为好吧。
使用 Wireshark 我可以看到我发送的 TLS 版本是 1.2,这是正确且符合预期的(也许它没有使用 HTTP2?)
有客人吗? 提前致谢!
----------------------------------------------- - - 编辑 - - - - - - - - - - - - - - - - - - - - - - - ------
查看我发现这个方法的库:useTransportSecurity()
/**
* Sets the negotiation type for the HTTP/2 connection to TLS (this is the default).
...
*/
@Override
public final OkHttpChannelBuilder useTransportSecurity() { ... }
我们默认使用带有 HTTP/2 的 TLS,所以这不是问题...
【问题讨论】: