Java 无法通过SSL从客户端通过还原代理(HAProxy)连接到gRPC服务器

Java 无法通过SSL从客户端通过还原代理(HAProxy)连接到gRPC服务器,java,ssl,haproxy,grpc,grpc-java,Java,Ssl,Haproxy,Grpc,Grpc Java,在我使用GRPCJava的项目中,我使用OpenSSL通过还原代理(HAProxy)在客户端和服务器之间建立安全连接 由于客户端和服务器通过还原代理进行交互,因此我只为HAProxy配置SSL,不需要对服务器执行任何操作。因此: 客户端代理:TLS/SSL 代理服务器:原始数据 我成功地运行了服务器,并在HAProxy上配置了SSL,我用检查了SSL配置,一切正常 此处的文档提到,安全通道的客户端代码如下: ManagedChannel channel = ManagedChannelBui

在我使用GRPCJava的项目中,我使用OpenSSL通过还原代理(HAProxy)在客户端和服务器之间建立安全连接

由于客户端和服务器通过还原代理进行交互,因此我只为HAProxy配置SSL,不需要对服务器执行任何操作。因此:

  • 客户端代理:TLS/SSL
  • 代理服务器:原始数据
我成功地运行了服务器,并在HAProxy上配置了SSL,我用检查了SSL配置,一切正常

此处的文档提到,安全通道的客户端代码如下:

ManagedChannel channel = ManagedChannelBuilder.forAddress("myservice.example.com", 443).build();
GreeterGrpc.GreeterStub stub = GreeterGrpc.newStub(channel);
这是我的代码:

channel = ManagedChannelBuilder
                    .forAddress(domain, port)
                    .usePlaintext(false)
                    .build();
interceptChannel = ClientInterceptors.intercept(channel, new ClientHeaderInterceptor());
asyncStub = GatewayServiceGrpc.newStub(channel);
blockingStub = GatewayServiceGrpc.newBlockingStub(interceptChannel);
但问题是我无法连接到服务器,没有响应,而且它根本不会抛出任何异常或错误

但是,如果我从客户端将usePlaintextfalse更改为true(禁用TLS),并且代理仍然具有SSL,那么我将收到此异常:

io.grpc.StatusRuntimeException: UNAVAILABLE: Network closed for unknown reason
        at io.grpc.Status.asRuntimeException(Status.java:526)
        at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:385)
        at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:41)
        at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:339)
        at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:443)
        at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:63)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:525)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:446)
        at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:557)
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:107)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
这是客户端的依赖项:

<dependencies>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty</artifactId>
            <version>1.7.0</version>
        </dependency>

        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>1.7.0</version>
        </dependency>

        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
            <version>1.7.0</version>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-tcnative-boringssl-static</artifactId>
            <version>2.0.6.Final</version>
        </dependency>

        <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.3.7</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>

</dependencies>

io.grpc
grpc netty
1.7.0
io.grpc
grpc协议
1.7.0
io.grpc
grpc存根
1.7.0
伊奥·内蒂
netty Tcing boringssl静态
2.0.6.1最终版本
com.lmax
破坏者
3.3.7
回写
回归经典
1.2.3

我正在使用gRPC版本1.7.0

在创建频道时删除
。使用明文(false)
将解决问题。

在创建频道时删除
。使用明文(false)
将解决问题。

gRPC仅基于http2。您的代理服务器支持http2吗?是的。事实上,我成功地建立了联系,但那是几个月前的事了。但现在,在相同的配置下,它不起作用。当时我使用的是gRPC版本1.0.3。如果我为我的代理关闭TLS,一切正常,因此我非常确定我的代理确实支持
http2
gRPC仅基于http2。您的代理服务器支持http2吗?是的。事实上,我成功地建立了联系,但那是几个月前的事了。但现在,在相同的配置下,它不起作用。当时我使用的是gRPC版本1.0.3。如果我为我的代理关闭TLS,一切正常,因此我非常确定我的代理确实支持
http2