|
23 | 23 |
|
24 | 24 | import com.google.common.annotations.VisibleForTesting; |
25 | 25 | import com.google.common.base.Preconditions; |
26 | | -import com.squareup.okhttp.CipherSuite; |
27 | | -import com.squareup.okhttp.ConnectionSpec; |
28 | | -import com.squareup.okhttp.TlsVersion; |
29 | 26 | import io.grpc.Attributes; |
30 | 27 | import io.grpc.ExperimentalApi; |
31 | 28 | import io.grpc.Internal; |
|
40 | 37 | import io.grpc.internal.SharedResourceHolder; |
41 | 38 | import io.grpc.internal.SharedResourceHolder.Resource; |
42 | 39 | import io.grpc.internal.TransportTracer; |
| 40 | +import io.grpc.okhttp.internal.CipherSuite; |
| 41 | +import io.grpc.okhttp.internal.ConnectionSpec; |
43 | 42 | import io.grpc.okhttp.internal.Platform; |
| 43 | +import io.grpc.okhttp.internal.TlsVersion; |
44 | 44 | import java.net.InetSocketAddress; |
45 | 45 | import java.net.SocketAddress; |
46 | 46 | import java.security.GeneralSecurityException; |
|
62 | 62 | public class OkHttpChannelBuilder extends |
63 | 63 | AbstractManagedChannelImplBuilder<OkHttpChannelBuilder> { |
64 | 64 |
|
65 | | - public static final ConnectionSpec DEFAULT_CONNECTION_SPEC = |
| 65 | + /** |
| 66 | + * ConnectionSpec closely matching the default configuration that could be used as a basis for |
| 67 | + * modification. |
| 68 | + * |
| 69 | + * <p>Since this field is the only reference in gRPC to ConnectionSpec that may not be ProGuarded, |
| 70 | + * we are removing the field to reduce method count. We've been unable to find any existing users |
| 71 | + * of the field, and any such user would highly likely at least be changing the cipher suites, |
| 72 | + * which is sort of the only part that's non-obvious. Any existing user should instead create |
| 73 | + * their own spec from scratch or base it off ConnectionSpec.MODERN_TLS if believed to be |
| 74 | + * necessary. If this was providing you with value and don't want to see it removed, open a GitHub |
| 75 | + * issue to discuss keeping it. |
| 76 | + * |
| 77 | + * @deprecated Deemed of little benefit and users weren't using it. Just define one yourself |
| 78 | + */ |
| 79 | + @Deprecated |
| 80 | + public static final com.squareup.okhttp.ConnectionSpec DEFAULT_CONNECTION_SPEC = |
| 81 | + new com.squareup.okhttp.ConnectionSpec.Builder(com.squareup.okhttp.ConnectionSpec.MODERN_TLS) |
| 82 | + .cipherSuites( |
| 83 | + // The following items should be sync with Netty's Http2SecurityUtil.CIPHERS. |
| 84 | + com.squareup.okhttp.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
| 85 | + com.squareup.okhttp.CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, |
| 86 | + com.squareup.okhttp.CipherSuite.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, |
| 87 | + com.squareup.okhttp.CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, |
| 88 | + com.squareup.okhttp.CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, |
| 89 | + com.squareup.okhttp.CipherSuite.TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, |
| 90 | + com.squareup.okhttp.CipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, |
| 91 | + com.squareup.okhttp.CipherSuite.TLS_DHE_DSS_WITH_AES_256_GCM_SHA384) |
| 92 | + .tlsVersions(com.squareup.okhttp.TlsVersion.TLS_1_2) |
| 93 | + .supportsTlsExtensions(true) |
| 94 | + .build(); |
| 95 | + |
| 96 | + @VisibleForTesting |
| 97 | + static final ConnectionSpec INTERNAL_DEFAULT_CONNECTION_SPEC = |
66 | 98 | new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) |
67 | 99 | .cipherSuites( |
68 | 100 | // The following items should be sync with Netty's Http2SecurityUtil.CIPHERS. |
@@ -110,7 +142,7 @@ public static OkHttpChannelBuilder forTarget(String target) { |
110 | 142 |
|
111 | 143 | private SSLSocketFactory sslSocketFactory; |
112 | 144 | private HostnameVerifier hostnameVerifier; |
113 | | - private ConnectionSpec connectionSpec = DEFAULT_CONNECTION_SPEC; |
| 145 | + private ConnectionSpec connectionSpec = INTERNAL_DEFAULT_CONNECTION_SPEC; |
114 | 146 | private NegotiationType negotiationType = NegotiationType.TLS; |
115 | 147 | private long keepAliveTimeNanos = KEEPALIVE_TIME_NANOS_DISABLED; |
116 | 148 | private long keepAliveTimeoutNanos = DEFAULT_KEEPALIVE_TIMEOUT_NANOS; |
@@ -272,17 +304,18 @@ public final OkHttpChannelBuilder hostnameVerifier(@Nullable HostnameVerifier ho |
272 | 304 | * For secure connection, provides a ConnectionSpec to specify Cipher suite and |
273 | 305 | * TLS versions. |
274 | 306 | * |
275 | | - * <p>By default {@link #DEFAULT_CONNECTION_SPEC} will be used. |
| 307 | + * <p>By default a modern, HTTP/2-compatible spec will be used. |
276 | 308 | * |
277 | 309 | * <p>This method is only used when building a secure connection. For plaintext |
278 | 310 | * connection, use {@link #usePlaintext()} instead. |
279 | 311 | * |
280 | 312 | * @throws IllegalArgumentException |
281 | 313 | * If {@code connectionSpec} is not with TLS |
282 | 314 | */ |
283 | | - public final OkHttpChannelBuilder connectionSpec(ConnectionSpec connectionSpec) { |
| 315 | + public final OkHttpChannelBuilder connectionSpec( |
| 316 | + com.squareup.okhttp.ConnectionSpec connectionSpec) { |
284 | 317 | Preconditions.checkArgument(connectionSpec.isTls(), "plaintext ConnectionSpec is not accepted"); |
285 | | - this.connectionSpec = connectionSpec; |
| 318 | + this.connectionSpec = Utils.convertSpec(connectionSpec); |
286 | 319 | return this; |
287 | 320 | } |
288 | 321 |
|
@@ -481,7 +514,7 @@ public void run() { |
481 | 514 | executor, |
482 | 515 | socketFactory, |
483 | 516 | hostnameVerifier, |
484 | | - Utils.convertSpec(connectionSpec), |
| 517 | + connectionSpec, |
485 | 518 | maxMessageSize, |
486 | 519 | proxy, |
487 | 520 | tooManyPingsRunnable, |
|
0 commit comments