Skip to content

Commit aa59e30

Browse files
committed
Upgrade Netty to 4.1.135
S2ATrustManager now needs to implement X509ExtendedTrustManager because Netty is now doing hostname verification itself if the trust manager is not extended (netty/netty@09e72c4fd8). S2A didn't need to be extended because it received the desired hostname to verify from its constructor, so doesn't need to look it up in SSLSocket/SSLEngine. NettyClientTransportTest is seeing a different failure now because the server is no longer failing the RPC before sending the response headers (netty/netty@b831454889).
1 parent 243b79e commit aa59e30

5 files changed

Lines changed: 76 additions & 38 deletions

File tree

MODULE.bazel

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
2525
"dev.cel:common:0.12.0",
2626
"com.squareup.okhttp:okhttp:2.7.5",
2727
"com.squareup.okio:okio:2.10.0", # 3.0+ needs swapping to -jvm; need work to avoid flag-day
28-
"io.netty:netty-buffer:4.1.133.Final",
29-
"io.netty:netty-codec-http2:4.1.133.Final",
30-
"io.netty:netty-codec-http:4.1.133.Final",
31-
"io.netty:netty-codec-socks:4.1.133.Final",
32-
"io.netty:netty-codec:4.1.133.Final",
33-
"io.netty:netty-common:4.1.133.Final",
34-
"io.netty:netty-handler-proxy:4.1.133.Final",
35-
"io.netty:netty-handler:4.1.133.Final",
36-
"io.netty:netty-resolver:4.1.133.Final",
28+
"io.netty:netty-buffer:4.1.135.Final",
29+
"io.netty:netty-codec-http2:4.1.135.Final",
30+
"io.netty:netty-codec-http:4.1.135.Final",
31+
"io.netty:netty-codec-socks:4.1.135.Final",
32+
"io.netty:netty-codec:4.1.135.Final",
33+
"io.netty:netty-common:4.1.135.Final",
34+
"io.netty:netty-handler-proxy:4.1.135.Final",
35+
"io.netty:netty-handler:4.1.135.Final",
36+
"io.netty:netty-resolver:4.1.135.Final",
3737
"io.netty:netty-tcnative-boringssl-static:2.0.75.Final",
3838
"io.netty:netty-tcnative-classes:2.0.75.Final",
39-
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.133.Final",
40-
"io.netty:netty-transport-native-unix-common:4.1.133.Final",
41-
"io.netty:netty-transport:4.1.133.Final",
39+
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.135.Final",
40+
"io.netty:netty-transport-native-unix-common:4.1.135.Final",
41+
"io.netty:netty-transport:4.1.135.Final",
4242
"io.opencensus:opencensus-api:0.31.0",
4343
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
4444
"io.perfmark:perfmark-api:0.27.0",
@@ -65,6 +65,7 @@ android_sdk_repository_extension = use_extension(
6565
"android_sdk_repository_extension",
6666
)
6767
use_repo(android_sdk_repository_extension, "androidsdk")
68+
6869
register_toolchains("@androidsdk//:sdk-toolchain", "@androidsdk//:all")
6970

7071
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
@@ -83,6 +84,8 @@ use_repo(maven, "maven")
8384
grpc_android_maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven", dev_dependency = True)
8485
grpc_android_maven.install(
8586
name = "grpc_android_maven",
87+
# Set this explicitly since the default guess is incorrect under Bzlmod.
88+
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
8689
artifacts = [
8790
"androidx.annotation:annotation:1.6.0",
8891
"androidx.annotation:annotation-jvm:1.6.0",
@@ -96,8 +99,6 @@ grpc_android_maven.install(
9699
strict_visibility = True,
97100
# For Bazel 8+ compatibility.
98101
use_starlark_android_rules = True,
99-
# Set this explicitly since the default guess is incorrect under Bzlmod.
100-
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
101102
)
102103
use_repo(grpc_android_maven, "grpc_android_maven")
103104

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ mockito-android = "org.mockito:mockito-android:4.4.0"
104104
mockito-core = "org.mockito:mockito-core:4.4.0"
105105
# Need to decide when we require users to absorb the breaking changes in 4.2
106106
# checkForUpdates: netty-codec-http2:4.1.+
107-
netty-codec-http2 = "io.netty:netty-codec-http2:4.1.133.Final"
107+
netty-codec-http2 = "io.netty:netty-codec-http2:4.1.135.Final"
108108
# checkForUpdates: netty-handler-proxy:4.1.+
109-
netty-handler-proxy = "io.netty:netty-handler-proxy:4.1.133.Final"
109+
netty-handler-proxy = "io.netty:netty-handler-proxy:4.1.135.Final"
110110
# Keep the following references of tcnative version in sync whenever it's updated:
111111
# SECURITY.md
112112
netty-tcnative = "io.netty:netty-tcnative-boringssl-static:2.0.75.Final"
113113
netty-tcnative-classes = "io.netty:netty-tcnative-classes:2.0.75.Final"
114114
# checkForUpdates: netty-transport-epoll:4.1.+
115-
netty-transport-epoll = "io.netty:netty-transport-native-epoll:4.1.133.Final"
115+
netty-transport-epoll = "io.netty:netty-transport-native-epoll:4.1.135.Final"
116116
# checkForUpdates: netty-unix-common:4.1.+
117-
netty-unix-common = "io.netty:netty-transport-native-unix-common:4.1.133.Final"
117+
netty-unix-common = "io.netty:netty-transport-native-unix-common:4.1.135.Final"
118118
okhttp = "com.squareup.okhttp:okhttp:2.7.5"
119119
# okio 3.5+ uses Kotlin 1.9+ which requires Android Gradle Plugin 9+
120120
# checkForUpdates: okio:3.4.+

netty/src/test/java/io/grpc/netty/NettyClientTransportTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import io.netty.channel.socket.SocketChannelConfig;
9999
import io.netty.channel.socket.nio.NioServerSocketChannel;
100100
import io.netty.channel.socket.nio.NioSocketChannel;
101+
import io.netty.handler.codec.http2.Http2Exception;
101102
import io.netty.handler.codec.http2.StreamBufferingEncoder;
102103
import io.netty.handler.ssl.ClientAuth;
103104
import io.netty.handler.ssl.SslContext;
@@ -610,8 +611,12 @@ public void channelFactoryShouldNNotSetSocketOptionKeepAlive() throws Exception
610611
public void maxHeaderListSizeShouldBeEnforcedOnClient() throws Exception {
611612
startServer();
612613

614+
// We want the header list size limit to be half-way close to the RPC's header size, otherwise
615+
// Netty will kill the connection instead of just the stream. While we can kill the connection,
616+
// we want to make sure there's a more graceful failure first. We don't want a cliff where if an
617+
// app adds one byte suddenly RPCs kill the connection.
613618
NettyClientTransport transport =
614-
newTransport(newNegotiator(), DEFAULT_MAX_MESSAGE_SIZE, 1, null, true);
619+
newTransport(newNegotiator(), DEFAULT_MAX_MESSAGE_SIZE, 75, null, true);
615620
callMeMaybe(transport.start(clientTransportListener));
616621
verify(clientTransportListener, timeout(5000)).transportReady();
617622

@@ -621,11 +626,17 @@ public void maxHeaderListSizeShouldBeEnforcedOnClient() throws Exception {
621626
fail("The stream should have been failed due to client received header exceeds header list"
622627
+ " size limit!");
623628
} catch (Exception e) {
624-
Throwable rootCause = getRootCause(e);
625-
Status status = ((StatusException) rootCause).getStatus();
629+
Status status = ((StatusException) e.getCause()).getStatus();
626630
assertEquals(Status.Code.INTERNAL, status.getCode());
627-
assertEquals("RST_STREAM closed stream. HTTP/2 error code: PROTOCOL_ERROR",
628-
status.getDescription());
631+
if (status.getCause() instanceof Http2Exception.StreamException) {
632+
// Netty 4.1.135+ stream-level error that is generated by the client.
633+
assertThat(status.getCause()).hasMessageThat()
634+
.contains("Header size exceeded max allowed size");
635+
} else {
636+
// Older Netty failed the stream on the the server-side.
637+
assertEquals("RST_STREAM closed stream. HTTP/2 error code: PROTOCOL_ERROR",
638+
status.getDescription());
639+
}
629640
}
630641
}
631642

repositories.bzl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ IO_GRPC_GRPC_JAVA_ARTIFACTS = [
3030
"dev.cel:common:0.12.0",
3131
"com.squareup.okhttp:okhttp:2.7.5",
3232
"com.squareup.okio:okio:2.10.0", # 3.0+ needs swapping to -jvm; need work to avoid flag-day
33-
"io.netty:netty-buffer:4.1.133.Final",
34-
"io.netty:netty-codec-http2:4.1.133.Final",
35-
"io.netty:netty-codec-http:4.1.133.Final",
36-
"io.netty:netty-codec-socks:4.1.133.Final",
37-
"io.netty:netty-codec:4.1.133.Final",
38-
"io.netty:netty-common:4.1.133.Final",
39-
"io.netty:netty-handler-proxy:4.1.133.Final",
40-
"io.netty:netty-handler:4.1.133.Final",
41-
"io.netty:netty-resolver:4.1.133.Final",
33+
"io.netty:netty-buffer:4.1.135.Final",
34+
"io.netty:netty-codec-http2:4.1.135.Final",
35+
"io.netty:netty-codec-http:4.1.135.Final",
36+
"io.netty:netty-codec-socks:4.1.135.Final",
37+
"io.netty:netty-codec:4.1.135.Final",
38+
"io.netty:netty-common:4.1.135.Final",
39+
"io.netty:netty-handler-proxy:4.1.135.Final",
40+
"io.netty:netty-handler:4.1.135.Final",
41+
"io.netty:netty-resolver:4.1.135.Final",
4242
"io.netty:netty-tcnative-boringssl-static:2.0.75.Final",
4343
"io.netty:netty-tcnative-classes:2.0.75.Final",
44-
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.133.Final",
45-
"io.netty:netty-transport-native-unix-common:4.1.133.Final",
46-
"io.netty:netty-transport:4.1.133.Final",
44+
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.135.Final",
45+
"io.netty:netty-transport-native-unix-common:4.1.135.Final",
46+
"io.netty:netty-transport:4.1.135.Final",
4747
"io.opencensus:opencensus-api:0.31.0",
4848
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
4949
"io.perfmark:perfmark-api:0.27.0",

s2a/src/main/java/io/grpc/s2a/internal/handshaker/S2ATrustManager.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@
2828
import com.google.s2a.proto.v2.ValidatePeerCertificateChainResp;
2929
import io.grpc.s2a.internal.handshaker.S2AIdentity;
3030
import java.io.IOException;
31+
import java.net.Socket;
3132
import java.security.cert.CertificateEncodingException;
3233
import java.security.cert.CertificateException;
3334
import java.security.cert.X509Certificate;
3435
import java.util.Optional;
3536
import javax.annotation.concurrent.NotThreadSafe;
36-
import javax.net.ssl.X509TrustManager;
37+
import javax.net.ssl.SSLEngine;
38+
import javax.net.ssl.X509ExtendedTrustManager;
3739
import org.checkerframework.checker.nullness.qual.Nullable;
3840

3941
/** Offloads verification of the peer certificate chain to S2A. */
4042
@NotThreadSafe
41-
final class S2ATrustManager implements X509TrustManager {
43+
final class S2ATrustManager extends X509ExtendedTrustManager {
4244
private final Optional<S2AIdentity> localIdentity;
4345
private final S2AStub stub;
4446
private final String hostname;
@@ -71,6 +73,18 @@ public void checkClientTrusted(X509Certificate[] chain, String authType)
7173
checkPeerTrusted(chain, /* isCheckingClientCertificateChain= */ true);
7274
}
7375

76+
@Override
77+
public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket)
78+
throws CertificateException {
79+
checkClientTrusted(chain, authType);
80+
}
81+
82+
@Override
83+
public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine)
84+
throws CertificateException {
85+
checkClientTrusted(chain, authType);
86+
}
87+
7488
/**
7589
* Validates the given certificate chain provided by the peer.
7690
*
@@ -86,6 +100,18 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
86100
checkPeerTrusted(chain, /* isCheckingClientCertificateChain= */ false);
87101
}
88102

103+
@Override
104+
public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket)
105+
throws CertificateException {
106+
checkServerTrusted(chain, authType);
107+
}
108+
109+
@Override
110+
public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine)
111+
throws CertificateException {
112+
checkServerTrusted(chain, authType);
113+
}
114+
89115
/**
90116
* Returns null because the accepted issuers are held in S2A and this class receives decision made
91117
* from S2A on the fly about which to use to verify a given chain.
@@ -156,4 +182,4 @@ private static ImmutableList<ByteString> certificateChainToDerChain(X509Certific
156182
}
157183
return derChain.build();
158184
}
159-
}
185+
}

0 commit comments

Comments
 (0)