Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

import com.google.common.base.Throwables;
import com.google.protobuf.EmptyProtos.Empty;
import com.squareup.okhttp.ConnectionSpec;
import com.squareup.okhttp.TlsVersion;
import io.grpc.ManagedChannel;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.testing.TestUtils;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.okhttp.OkHttpChannelBuilder;
import io.grpc.okhttp.internal.ConnectionSpec;
import io.grpc.okhttp.internal.Platform;
import io.grpc.okhttp.internal.TlsVersion;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.StreamRecorder;
import io.netty.handler.ssl.OpenSsl;
Expand All @@ -42,7 +42,6 @@
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down
6 changes: 3 additions & 3 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.squareup.okhttp.CipherSuite;
import com.squareup.okhttp.ConnectionSpec;
import com.squareup.okhttp.TlsVersion;
import io.grpc.Attributes;
import io.grpc.ExperimentalApi;
import io.grpc.Internal;
Expand All @@ -37,7 +34,10 @@
import io.grpc.internal.KeepAliveManager;
import io.grpc.internal.SharedResourceHolder;
import io.grpc.internal.SharedResourceHolder.Resource;
import io.grpc.okhttp.internal.CipherSuite;
import io.grpc.okhttp.internal.ConnectionSpec;
Copy link
Member

Choose a reason for hiding this comment

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

ConnectionSpec is part of grpc's API in this class. We don't want to expose our internal fork, so we let users specify okhttp's ConnectionSpec and then we use Utils.convertSpec() to copy it into an internal equivalent.

Feel free to eagerly convert in connectionSpec(); that would allow proguard to remove the references if it isn't specified.

import io.grpc.okhttp.internal.Platform;
import io.grpc.okhttp.internal.TlsVersion;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.security.GeneralSecurityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
import javax.annotation.Nullable;
import javax.net.ssl.SSLSocket;

/**
* A helper class located in package com.squareup.okhttp.internal for TLS negotiation.
*/
/** A helper class for TLS negotiation. */
class OkHttpProtocolNegotiator {
private static final Platform DEFAULT_PLATFORM = Platform.get();
private static OkHttpProtocolNegotiator NEGOTIATOR =
Expand Down
5 changes: 1 addition & 4 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpTlsUpgrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

/**
* A helper class that located in package com.squareup.okhttp, so that we can use OkHttp internals
* to do TLS upgrading.
*/
/** A helper class so that we can use OkHttp internals to do TLS upgrading. */
final class OkHttpTlsUpgrader {

/*
Expand Down
13 changes: 6 additions & 7 deletions okhttp/src/main/java/io/grpc/okhttp/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,21 @@ private static byte[][] convertHeadersToArray(List<Header> http2Headers) {
}

/**
* Converts an instance of {@link com.squareup.okhttp.ConnectionSpec} for a secure connection into
* that of {@link ConnectionSpec} in the current package.
* Converts an instance of {@link io.grpc.okhttp.internal.ConnectionSpec} for a secure connection
* into that of {@link ConnectionSpec} in the current package.
*
* @throws IllegalArgumentException
* If {@code spec} is not with TLS
* @throws IllegalArgumentException If {@code spec} is not with TLS
*/
static ConnectionSpec convertSpec(com.squareup.okhttp.ConnectionSpec spec) {
static ConnectionSpec convertSpec(io.grpc.okhttp.internal.ConnectionSpec spec) {
Preconditions.checkArgument(spec.isTls(), "plaintext ConnectionSpec is not accepted");

List<com.squareup.okhttp.TlsVersion> tlsVersionList = spec.tlsVersions();
List<io.grpc.okhttp.internal.TlsVersion> tlsVersionList = spec.tlsVersions();
String[] tlsVersions = new String[tlsVersionList.size()];
for (int i = 0; i < tlsVersions.length; i++) {
tlsVersions[i] = tlsVersionList.get(i).javaName();
}

List<com.squareup.okhttp.CipherSuite> cipherSuiteList = spec.cipherSuites();
List<io.grpc.okhttp.internal.CipherSuite> cipherSuiteList = spec.cipherSuites();
CipherSuite[] cipherSuites = new CipherSuite[cipherSuiteList.size()];
for (int i = 0; i < cipherSuites.length; i++) {
cipherSuites[i] = CipherSuite.valueOf(cipherSuiteList.get(i).name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import com.squareup.okhttp.ConnectionSpec;
import io.grpc.NameResolver;
import io.grpc.internal.GrpcUtil;
import io.grpc.okhttp.internal.ConnectionSpec;
import java.net.InetSocketAddress;
import org.junit.Rule;
import org.junit.Test;
Expand Down
10 changes: 6 additions & 4 deletions okhttp/src/test/java/io/grpc/okhttp/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ public class UtilsTest {

@Test
public void convertSpecRejectsPlaintext() {
com.squareup.okhttp.ConnectionSpec plaintext = com.squareup.okhttp.ConnectionSpec.CLEARTEXT;
io.grpc.okhttp.internal.ConnectionSpec plaintext =
io.grpc.okhttp.internal.ConnectionSpec.CLEARTEXT;
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("plaintext ConnectionSpec is not accepted");
Utils.convertSpec(plaintext);
}

@Test
public void convertSpecKeepsAllData() {
com.squareup.okhttp.ConnectionSpec squareSpec = com.squareup.okhttp.ConnectionSpec.MODERN_TLS;
io.grpc.okhttp.internal.ConnectionSpec squareSpec =
io.grpc.okhttp.internal.ConnectionSpec.MODERN_TLS;
ConnectionSpec spec = Utils.convertSpec(squareSpec);

List<com.squareup.okhttp.TlsVersion> squareTlsVersions = squareSpec.tlsVersions();
List<io.grpc.okhttp.internal.TlsVersion> squareTlsVersions = squareSpec.tlsVersions();
List<TlsVersion> tlsVersions = spec.tlsVersions();
int versionsSize = squareTlsVersions.size();
List<com.squareup.okhttp.CipherSuite> squareCipherSuites = squareSpec.cipherSuites();
List<io.grpc.okhttp.internal.CipherSuite> squareCipherSuites = squareSpec.cipherSuites();
List<CipherSuite> cipherSuites = spec.cipherSuites();
int cipherSuitesSize = squareCipherSuites.size();

Expand Down