Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ensureAlpnAndH2Enabled to reflect NPN protocol #8836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions netty/src/main/java/io/grpc/netty/GrpcSslContexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,17 @@ private static Provider findJdkProvider() {
return null;
}

@SuppressWarnings("deprecation")
static void ensureAlpnAndH2Enabled(
io.netty.handler.ssl.ApplicationProtocolNegotiator alpnNegotiator) {
checkArgument(alpnNegotiator != null, "ALPN must be configured");
checkArgument(alpnNegotiator.protocols() != null && !alpnNegotiator.protocols().isEmpty(),
"ALPN must be enabled and list HTTP/2 as a supported protocol.");
static void ensureProtocolNegotiationAndH2Enabled(
io.netty.handler.ssl.ApplicationProtocolNegotiator protocolNegotiator) {
checkArgument(protocolNegotiator != null, "ALPN or NPN must be configured");
List<String> protocols = protocolNegotiator.protocols();
checkArgument(protocols != null && !protocols.isEmpty(),
"ALPN or NPN must be enabled and list HTTP/2 as a supported protocol.");
checkArgument(
alpnNegotiator.protocols().contains(HTTP2_VERSION),
"This ALPN config does not support HTTP/2. Expected %s, but got %s'.",
protocols.contains(HTTP2_VERSION),
"This ApplicationProtocolConfig does not support HTTP/2. Expected %s, but got %s'.",
HTTP2_VERSION,
alpnNegotiator.protocols());
protocols);
}

private static class ConscryptHolder {
Expand Down
2 changes: 1 addition & 1 deletion netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public NettyChannelBuilder sslContext(SslContext sslContext) {
if (sslContext != null) {
checkArgument(sslContext.isClient(),
"Server SSL context can not be used for client channel");
GrpcSslContexts.ensureAlpnAndH2Enabled(sslContext.applicationProtocolNegotiator());
GrpcSslContexts.ensureProtocolNegotiationAndH2Enabled(sslContext.applicationProtocolNegotiator());
}
if (!(protocolNegotiatorFactory instanceof DefaultProtocolNegotiator)) {
// Do nothing for compatibility
Expand Down
2 changes: 1 addition & 1 deletion netty/src/main/java/io/grpc/netty/NettyServerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public NettyServerBuilder sslContext(SslContext sslContext) {
if (sslContext != null) {
checkArgument(sslContext.isServer(),
"Client SSL context can not be used for server");
GrpcSslContexts.ensureAlpnAndH2Enabled(sslContext.applicationProtocolNegotiator());
GrpcSslContexts.ensureProtocolNegotiationAndH2Enabled(sslContext.applicationProtocolNegotiator());
protocolNegotiatorFactory = ProtocolNegotiators.serverTlsFactory(sslContext);
} else {
protocolNegotiatorFactory = ProtocolNegotiators.serverPlaintextFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private NettySslContextChannelCredentials() {}
public static ChannelCredentials create(SslContext sslContext) {
Preconditions.checkArgument(sslContext.isClient(),
"Server SSL context can not be used for client channel");
GrpcSslContexts.ensureAlpnAndH2Enabled(sslContext.applicationProtocolNegotiator());
GrpcSslContexts.ensureProtocolNegotiationAndH2Enabled(sslContext.applicationProtocolNegotiator());
return NettyChannelCredentials.create(ProtocolNegotiators.tlsClientFactory(sslContext));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private NettySslContextServerCredentials() {}
public static ServerCredentials create(SslContext sslContext) {
Preconditions.checkArgument(sslContext.isServer(),
"Client SSL context can not be used for server");
GrpcSslContexts.ensureAlpnAndH2Enabled(sslContext.applicationProtocolNegotiator());
GrpcSslContexts.ensureProtocolNegotiationAndH2Enabled(sslContext.applicationProtocolNegotiator());
return NettyServerCredentials.create(ProtocolNegotiators.serverTlsFactory(sslContext));
}
}