mirror of https://github.com/grpc/grpc-java.git
netty: remove 'grpc-exp' from the list of next-protocol-versions in ALPN (#6592)
This commit is contained in:
parent
bee375f205
commit
dba09163de
|
|
@ -50,25 +50,14 @@ public class GrpcSslContexts {
|
||||||
|
|
||||||
private GrpcSslContexts() {}
|
private GrpcSslContexts() {}
|
||||||
|
|
||||||
/*
|
|
||||||
* The experimental "grpc-exp" string identifies gRPC (and by implication
|
|
||||||
* HTTP/2) when used over TLS. This indicates to the server that the client
|
|
||||||
* will only send gRPC traffic on the h2 connection and is negotiated in
|
|
||||||
* preference to h2 when the client and server support it, but is not
|
|
||||||
* standardized. Support for this may be removed at any time.
|
|
||||||
*/
|
|
||||||
private static final String GRPC_EXP_VERSION = "grpc-exp";
|
|
||||||
|
|
||||||
// The "h2" string identifies HTTP/2 when used over TLS
|
// The "h2" string identifies HTTP/2 when used over TLS
|
||||||
private static final String HTTP2_VERSION = "h2";
|
private static final String HTTP2_VERSION = "h2";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* List of ALPN/NPN protocols in order of preference. GRPC_EXP_VERSION
|
* List of ALPN/NPN protocols in order of preference.
|
||||||
* requires that HTTP2_VERSION be present and that GRPC_EXP_VERSION should be
|
|
||||||
* preferenced over HTTP2_VERSION.
|
|
||||||
*/
|
*/
|
||||||
static final List<String> NEXT_PROTOCOL_VERSIONS =
|
static final List<String> NEXT_PROTOCOL_VERSIONS =
|
||||||
Collections.unmodifiableList(Arrays.asList(GRPC_EXP_VERSION, HTTP2_VERSION));
|
Collections.unmodifiableList(Arrays.asList(HTTP2_VERSION));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These configs use ACCEPT due to limited support in OpenSSL. Actual protocol enforcement is
|
* These configs use ACCEPT due to limited support in OpenSSL. Actual protocol enforcement is
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2016 The gRPC Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.grpc.netty;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link io.grpc.netty.GrpcSslContexts}. */
|
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class GrpcSslContextsTest {
|
|
||||||
@Test public void selectApplicationProtocolConfig_grpcExp() {
|
|
||||||
assertTrue(
|
|
||||||
GrpcSslContexts.NEXT_PROTOCOL_VERSIONS.indexOf("grpc-exp") == -1
|
|
||||||
|| GrpcSslContexts.NEXT_PROTOCOL_VERSIONS.indexOf("grpc-exp")
|
|
||||||
< GrpcSslContexts.NEXT_PROTOCOL_VERSIONS.indexOf("h2"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -349,29 +349,6 @@ public class ProtocolNegotiatorsTest {
|
||||||
assertNotNull(grpcHandlerCtx);
|
assertNotNull(grpcHandlerCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void tlsHandler_userEventTriggeredSslEvent_supportedProtocolGrpcExp() throws Exception {
|
|
||||||
SslHandler goodSslHandler = new SslHandler(engine, false) {
|
|
||||||
@Override
|
|
||||||
public String applicationProtocol() {
|
|
||||||
return "grpc-exp";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ChannelHandler handler = new ServerTlsHandler(grpcHandler, sslContext, null);
|
|
||||||
pipeline.addLast(handler);
|
|
||||||
|
|
||||||
pipeline.replace(SslHandler.class, null, goodSslHandler);
|
|
||||||
channelHandlerCtx = pipeline.context(handler);
|
|
||||||
Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
|
|
||||||
|
|
||||||
pipeline.fireUserEventTriggered(sslEvent);
|
|
||||||
|
|
||||||
assertTrue(channel.isOpen());
|
|
||||||
ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
|
|
||||||
assertNotNull(grpcHandlerCtx);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void engineLog() {
|
public void engineLog() {
|
||||||
ChannelHandler handler = new ServerTlsHandler(grpcHandler, sslContext, null);
|
ChannelHandler handler = new ServerTlsHandler(grpcHandler, sslContext, null);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ final class OkHttpTlsUpgrader {
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final List<Protocol> TLS_PROTOCOLS =
|
static final List<Protocol> TLS_PROTOCOLS =
|
||||||
Collections.unmodifiableList(Arrays.asList(Protocol.GRPC_EXP, Protocol.HTTP_2));
|
Collections.unmodifiableList(Arrays.asList(Protocol.HTTP_2));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upgrades given Socket to be an SSLSocket.
|
* Upgrades given Socket to be an SSLSocket.
|
||||||
|
|
|
||||||
|
|
@ -146,26 +146,6 @@ public class OkHttpProtocolNegotiatorTest {
|
||||||
verify(platform).afterHandshake(sock);
|
verify(platform).afterHandshake(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void negotiate_preferGrpcExp() throws Exception {
|
|
||||||
// This test doesn't actually verify that grpc-exp is preferred, since the
|
|
||||||
// mocking of getSelectedProtocol() causes the protocol list to be ignored.
|
|
||||||
// The main usefulness of the test is for future changes to
|
|
||||||
// OkHttpProtocolNegotiator, where we can catch any change that would affect
|
|
||||||
// grpc-exp preference.
|
|
||||||
when(platform.getSelectedProtocol(ArgumentMatchers.<SSLSocket>any())).thenReturn("grpc-exp");
|
|
||||||
OkHttpProtocolNegotiator negotiator = new OkHttpProtocolNegotiator(platform);
|
|
||||||
|
|
||||||
String actual =
|
|
||||||
negotiator.negotiate(sock, "hostname",
|
|
||||||
ImmutableList.of(Protocol.GRPC_EXP, Protocol.HTTP_2));
|
|
||||||
|
|
||||||
assertEquals("grpc-exp", actual);
|
|
||||||
verify(sock).startHandshake();
|
|
||||||
verify(platform).getSelectedProtocol(sock);
|
|
||||||
verify(platform).afterHandshake(sock);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checks that the super class is properly invoked.
|
// Checks that the super class is properly invoked.
|
||||||
@Test
|
@Test
|
||||||
public void negotiate_android_handshakeFails() throws Exception {
|
public void negotiate_android_handshakeFails() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,7 @@ package io.grpc.okhttp;
|
||||||
|
|
||||||
import static io.grpc.okhttp.OkHttpTlsUpgrader.canonicalizeHost;
|
import static io.grpc.okhttp.OkHttpTlsUpgrader.canonicalizeHost;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import io.grpc.okhttp.internal.Protocol;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
|
|
@ -28,12 +26,6 @@ import org.junit.runners.JUnit4;
|
||||||
/** Unit tests for {@link io.grpc.okhttp.OkHttpTlsUpgrader}. */
|
/** Unit tests for {@link io.grpc.okhttp.OkHttpTlsUpgrader}. */
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class OkHttpTlsUpgraderTest {
|
public class OkHttpTlsUpgraderTest {
|
||||||
@Test public void upgrade_grpcExp() {
|
|
||||||
assertTrue(
|
|
||||||
OkHttpTlsUpgrader.TLS_PROTOCOLS.indexOf(Protocol.GRPC_EXP) == -1
|
|
||||||
|| OkHttpTlsUpgrader.TLS_PROTOCOLS.indexOf(Protocol.GRPC_EXP)
|
|
||||||
< OkHttpTlsUpgrader.TLS_PROTOCOLS.indexOf(Protocol.HTTP_2));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test public void canonicalizeHosts() {
|
@Test public void canonicalizeHosts() {
|
||||||
assertEquals("::1", canonicalizeHost("::1"));
|
assertEquals("::1", canonicalizeHost("::1"));
|
||||||
|
|
|
||||||
|
|
@ -70,16 +70,7 @@ public enum Protocol {
|
||||||
* , present in Java 8+ and Android 5+. Servers that enforce this may send an
|
* , present in Java 8+ and Android 5+. Servers that enforce this may send an
|
||||||
* exception message including the string {@code INADEQUATE_SECURITY}.
|
* exception message including the string {@code INADEQUATE_SECURITY}.
|
||||||
*/
|
*/
|
||||||
HTTP_2("h2"),
|
HTTP_2("h2");
|
||||||
|
|
||||||
/**
|
|
||||||
* The experimental "grpc-exp" string identifies gRPC (and by implication
|
|
||||||
* HTTP/2) when used over TLS. This indicates to the server that the client
|
|
||||||
* will only send gRPC traffic on the h2 connection and is negotiated in
|
|
||||||
* preference to h2 when the client and server support it, but is not
|
|
||||||
* standardized. Support for this may be removed at any time.
|
|
||||||
*/
|
|
||||||
GRPC_EXP("grpc-exp");
|
|
||||||
|
|
||||||
private final String protocol;
|
private final String protocol;
|
||||||
|
|
||||||
|
|
@ -96,7 +87,6 @@ public enum Protocol {
|
||||||
if (protocol.equals(HTTP_1_0.protocol)) return HTTP_1_0;
|
if (protocol.equals(HTTP_1_0.protocol)) return HTTP_1_0;
|
||||||
if (protocol.equals(HTTP_1_1.protocol)) return HTTP_1_1;
|
if (protocol.equals(HTTP_1_1.protocol)) return HTTP_1_1;
|
||||||
if (protocol.equals(HTTP_2.protocol)) return HTTP_2;
|
if (protocol.equals(HTTP_2.protocol)) return HTTP_2;
|
||||||
if (protocol.equals(GRPC_EXP.protocol)) return GRPC_EXP;
|
|
||||||
if (protocol.equals(SPDY_3.protocol)) return SPDY_3;
|
if (protocol.equals(SPDY_3.protocol)) return SPDY_3;
|
||||||
throw new IOException("Unexpected protocol: " + protocol);
|
throw new IOException("Unexpected protocol: " + protocol);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue