Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,26 @@ private enum NegotiationType {
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256

// TLS 1.3 does not work so far. See issues:
// https://github.com/grpc/grpc-java/issues/7765
//
// TLS 1.3
//CipherSuite.TLS_AES_128_GCM_SHA256,
//CipherSuite.TLS_AES_256_GCM_SHA384,
//CipherSuite.TLS_CHACHA20_POLY1305_SHA256
)
.tlsVersions(/*TlsVersion.TLS_1_3,*/ TlsVersion.TLS_1_2)
CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_AES_128_GCM_SHA256,
CipherSuite.TLS_AES_256_GCM_SHA384,
CipherSuite.TLS_CHACHA20_POLY1305_SHA256)
.tlsVersions(TlsVersion.TLS_1_3, TlsVersion.TLS_1_2)
.supportsTlsExtensions(true)
.build();

// @VisibleForTesting
static final ConnectionSpec INTERNAL_LEGACY_CONNECTION_SPEC =
new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.cipherSuites(
// The following items should be sync with Netty's Http2SecurityUtil.CIPHERS.
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
CipherSuite.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256)
.tlsVersions(TlsVersion.TLS_1_2)
.supportsTlsExtensions(true)
.build();

Expand Down Expand Up @@ -184,7 +193,7 @@ public static OkHttpChannelBuilder forTarget(String target, ChannelCredentials c
private SSLSocketFactory sslSocketFactory;
private final boolean freezeSecurityConfiguration;
private HostnameVerifier hostnameVerifier;
private ConnectionSpec connectionSpec = INTERNAL_DEFAULT_CONNECTION_SPEC;
private ConnectionSpec connectionSpec;
private NegotiationType negotiationType = NegotiationType.TLS;
private long keepAliveTimeNanos = KEEPALIVE_TIME_NANOS_DISABLED;
private long keepAliveTimeoutNanos = DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
Expand All @@ -199,6 +208,12 @@ public static OkHttpChannelBuilder forTarget(String target, ChannelCredentials c
*/
private final boolean useGetForSafeMethods = false;

private static ConnectionSpec initialConnectionSpec() {
return (OkHttpProtocolNegotiator.get() instanceof OkHttpProtocolNegotiator.AndroidNegotiator)
? INTERNAL_DEFAULT_CONNECTION_SPEC
: INTERNAL_LEGACY_CONNECTION_SPEC;
}

private OkHttpChannelBuilder(String host, int port) {
this(GrpcUtil.authorityFromHostAndPort(host, port));
}
Expand All @@ -209,6 +224,7 @@ private OkHttpChannelBuilder(String target) {
new OkHttpChannelDefaultPortProvider());
this.freezeSecurityConfiguration = false;
this.channelCredentials = null;
this.connectionSpec = initialConnectionSpec();
}

OkHttpChannelBuilder(
Expand All @@ -222,6 +238,7 @@ private OkHttpChannelBuilder(String target) {
this.negotiationType = factory == null ? NegotiationType.PLAINTEXT : NegotiationType.TLS;
this.freezeSecurityConfiguration = true;
this.channelCredentials = channelCreds;
this.connectionSpec = initialConnectionSpec();
}

private final class OkHttpChannelTransportFactoryBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static final class ServerCredentials extends io.grpc.ServerCredentials {
private final ConnectionSpec connectionSpec;

ServerCredentials(SSLSocketFactory factory) {
this(factory, OkHttpChannelBuilder.INTERNAL_DEFAULT_CONNECTION_SPEC);
this(factory, OkHttpChannelBuilder.INTERNAL_LEGACY_CONNECTION_SPEC);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt it be OkHttpChannelBuilder.initialConnectionSpec() then?

}

ServerCredentials(SSLSocketFactory factory, ConnectionSpec connectionSpec) {
Expand Down
Loading