Grpc client not invoking gRPC call after establishing SSL handshake (Using ALPN)
Hi,
It seems that the SSL handshake is successful when the client try to establish a connection to the server. The log ends with the following at server-side:
io.netty.handler.ssl.SslHandler (SslHandler.java:setHandshakeSuccess(1251)) - [id: 0x7db3896c, /172.27.41.162:23913 => /172.27.44.228:7001] HANDSHAKEN: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
while the client side log ends with:
SETTINGS: ack=false, settings={HEADER_TABLE_SIZE=4096, ENABLE_PUSH=0, MAX_CONCURRENT_STREAMS=0, INITIAL_WINDOW_SIZE=66560, MAX_FRAME_SIZE=16384, MAX_HEADER_LIST_SIZE=2147483647}
However, after some tracing, the RPC methods that were invoked by the client, seemed to be stucked at getUnchecked(Future
The client code to call the server is as follows:
boolean useTls = config.getString("use.ssl").equalsIgnoreCase("true") ? true : false;
InetAddress address = null;
try {
address = InetAddress.getByName(serverHost);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SslContext sslContext = null;
if (useTls) {
try {
sslContext = GrpcSslContexts.forClient().trustManager(loadCert("serverselfsignedcert.pem","C:\\temp\\serverselfsignedcert.pem")).build();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
channel = NettyChannelBuilder
.forAddress(new InetSocketAddress(address, serverPort))
.streamWindowSize(65*1024).connectionWindowSize(65*1024)
.negotiationType(
useTls ? NegotiationType.TLS
: NegotiationType.PLAINTEXT)
.sslContext(sslContext).build();
blockingStub = PeerImplGrpc.newBlockingStub(channel);
ByteString byteStrKey = ByteString.copyFrom(HashUtil.encode("abc", serverHost.getBytes()));
PeerId request = PeerId.newBuilder().setPeerId(byteStrKey).build();
checkPeerAlive(request, response);
Response test = blockingStub.checkPeerAlive(request);
I also amended the implementation of TestUtils loadCert method to the following:
public static File loadCert(String name, String path) throws IOException {
FileInputStream in = new FileInputStream(new File(path));
File tmpFile = File.createTempFile(name, "");
tmpFile.deleteOnExit();
BufferedWriter writer = new BufferedWriter(new FileWriter(tmpFile));
try {
int b;
while ((b = in.read()) != -1) {
writer.write(b);
}
} finally {
writer.close();
in.close();
}
return tmpFile;
}
Is there something that I might have missed out?
@megapowers First thing that sticks out is that you want to avoid using GCM. As a temporary work-around you can set sslContextBuilder.ciphers(null), which will force the context to use the default ciphers from the JDK.
Also, what version of grpc-java are you using? Judging by the streamWindowSize method, I'd say you're on an older release. You might want to consider upgrading to 0.8.0 or just build against head.
Closing due to no reply. A lot has happened on the SSL/TLS front; using a newer version is highly recommended.