diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e4a7e9dd3e..2693c05415bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,20 +13,20 @@ _2014-11-04_ * **TLS configuration updated.** OkHttp now explicitly enables TLSv1.2, TLSv1.1 and TLSv1.0 where they are supported. It will continue to perform only one fallback, to SSLv3. Applications can now configure this with the - `ConnectionConfiguration` class. + `ConnectionSpec` class. To disable TLS fallback: ``` - client.setConnectionConfigurations(Arrays.asList( - ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.CLEARTEXT)); + client.setConnectionSpecs(Arrays.asList( + ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT)); ``` To disable cleartext connections, permitting `https` URLs only: ``` - client.setConnectionConfigurations(Arrays.asList( - ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.COMPATIBLE_TLS)); + client.setConnectionSpecs(Arrays.asList( + ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)); ``` * **New cipher suites.** Please confirm that your webservers are reachable diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java index d14a25b3cbc6..0f832f4d5a2b 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/CallTest.java @@ -644,8 +644,7 @@ public final class CallTest { } @Test public void noRecoveryFromTlsHandshakeFailureWhenTlsFallbackIsDisabled() throws Exception { - client.setConnectionConfigurations(Arrays.asList( - ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.CLEARTEXT)); + client.setConnectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT)); server.useHttps(sslContext.getSocketFactory(), false); server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE)); @@ -665,8 +664,8 @@ public final class CallTest { @Test public void cleartextCallsFailWhenCleartextIsDisabled() throws Exception { // Configure the client with only TLS configurations. No cleartext! - client.setConnectionConfigurations(Arrays.asList( - ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.COMPATIBLE_TLS)); + client.setConnectionSpecs(Arrays.asList( + ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)); server.enqueue(new MockResponse()); server.play(); @@ -676,7 +675,7 @@ public final class CallTest { client.newCall(request).execute(); fail(); } catch (SocketException expected) { - assertTrue(expected.getMessage().contains("exhausted connection configurations")); + assertTrue(expected.getMessage().contains("exhausted connection specs")); } } diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java index 13ad06072102..0d1428aea433 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/ConnectionPoolTest.java @@ -73,13 +73,13 @@ private void setUp(int poolSize) throws Exception { httpServer = new MockWebServer(); spdyServer.useHttps(sslContext.getSocketFactory(), false); - List connectionConfigurations = Util.immutableList( - ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.CLEARTEXT); + List connectionSpecs = Util.immutableList( + ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT); httpServer.play(); httpAddress = new Address(httpServer.getHostName(), httpServer.getPort(), socketFactory, null, null, null, AuthenticatorAdapter.INSTANCE, null, - Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionConfigurations); + Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionSpecs); httpSocketAddress = new InetSocketAddress(InetAddress.getByName(httpServer.getHostName()), httpServer.getPort()); @@ -87,14 +87,14 @@ private void setUp(int poolSize) throws Exception { spdyAddress = new Address(spdyServer.getHostName(), spdyServer.getPort(), socketFactory, sslContext.getSocketFactory(), new RecordingHostnameVerifier(), CertificatePinner.DEFAULT, AuthenticatorAdapter.INSTANCE, null, - Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionConfigurations); + Util.immutableList(Protocol.SPDY_3, Protocol.HTTP_1_1), connectionSpecs); spdySocketAddress = new InetSocketAddress(InetAddress.getByName(spdyServer.getHostName()), spdyServer.getPort()); Route httpRoute = new Route(httpAddress, Proxy.NO_PROXY, httpSocketAddress, - ConnectionConfiguration.CLEARTEXT); + ConnectionSpec.CLEARTEXT); Route spdyRoute = new Route(spdyAddress, Proxy.NO_PROXY, spdySocketAddress, - ConnectionConfiguration.MODERN_TLS); + ConnectionSpec.MODERN_TLS); pool = new ConnectionPool(poolSize, KEEP_ALIVE_DURATION_MS); httpA = new Connection(pool, httpRoute); httpA.connect(200, 200, 200, null); @@ -140,7 +140,7 @@ private void resetWithPoolSize(int poolSize) throws Exception { assertNull(connection); connection = new Connection(pool, new Route(httpAddress, Proxy.NO_PROXY, httpSocketAddress, - ConnectionConfiguration.CLEARTEXT)); + ConnectionSpec.CLEARTEXT)); connection.connect(200, 200, 200, null); connection.setOwner(owner); assertEquals(0, pool.getConnectionCount()); diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java index 8d85c617a080..ab1b71c3a44c 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java @@ -18,7 +18,7 @@ import com.squareup.okhttp.Address; import com.squareup.okhttp.Authenticator; import com.squareup.okhttp.Connection; -import com.squareup.okhttp.ConnectionConfiguration; +import com.squareup.okhttp.ConnectionSpec; import com.squareup.okhttp.ConnectionPool; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Protocol; @@ -53,10 +53,10 @@ import static org.junit.Assert.fail; public final class RouteSelectorTest { - public final List connectionConfigurations = Util.immutableList( - ConnectionConfiguration.MODERN_TLS, - ConnectionConfiguration.COMPATIBLE_TLS, - ConnectionConfiguration.CLEARTEXT); + public final List connectionSpecs = Util.immutableList( + ConnectionSpec.MODERN_TLS, + ConnectionSpec.COMPATIBLE_TLS, + ConnectionSpec.CLEARTEXT); private static final int proxyAPort = 1001; private static final String proxyAHost = "proxyA"; @@ -94,7 +94,7 @@ public final class RouteSelectorTest { .setSslSocketFactory(sslSocketFactory) .setHostnameVerifier(hostnameVerifier) .setProtocols(protocols) - .setConnectionConfigurations(connectionConfigurations) + .setConnectionSpecs(connectionSpecs) .setConnectionPool(ConnectionPool.getDefault()); Internal.instance.setNetwork(client, dns); @@ -115,7 +115,7 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 1); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); dns.assertRequests(uriHost); assertFalse(routeSelector.hasNext()); @@ -136,7 +136,7 @@ public final class RouteSelectorTest { routeDatabase.failed(connection.getRoute()); routeSelector = RouteSelector.get(httpRequest, client); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); assertFalse(routeSelector.hasNext()); try { routeSelector.nextUnconnected(); @@ -147,16 +147,16 @@ public final class RouteSelectorTest { @Test public void explicitProxyTriesThatProxysAddressesOnly() throws Exception { Address address = new Address(uriHost, uriPort, socketFactory, null, null, null, authenticator, - proxyA, protocols, connectionConfigurations); + proxyA, protocols, connectionSpecs); client.setProxy(proxyA); RouteSelector routeSelector = RouteSelector.get(httpRequest, client); assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 2); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], - proxyAPort, ConnectionConfiguration.CLEARTEXT); + proxyAPort, ConnectionSpec.CLEARTEXT); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1], - proxyAPort, ConnectionConfiguration.CLEARTEXT); + proxyAPort, ConnectionSpec.CLEARTEXT); assertFalse(routeSelector.hasNext()); dns.assertRequests(proxyAHost); @@ -165,16 +165,16 @@ public final class RouteSelectorTest { @Test public void explicitDirectProxy() throws Exception { Address address = new Address(uriHost, uriPort, socketFactory, null, null, null, authenticator, - NO_PROXY, protocols, connectionConfigurations); + NO_PROXY, protocols, connectionSpecs); client.setProxy(NO_PROXY); RouteSelector routeSelector = RouteSelector.get(httpRequest, client); assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 2); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); assertFalse(routeSelector.hasNext()); dns.assertRequests(uriHost); @@ -191,7 +191,7 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 1); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); dns.assertRequests(uriHost); assertFalse(routeSelector.hasNext()); @@ -204,9 +204,9 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 2); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); assertFalse(routeSelector.hasNext()); dns.assertRequests(uriHost); @@ -225,23 +225,23 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 2); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], proxyAPort, - ConnectionConfiguration.CLEARTEXT); + ConnectionSpec.CLEARTEXT); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1], proxyAPort, - ConnectionConfiguration.CLEARTEXT); + ConnectionSpec.CLEARTEXT); dns.assertRequests(proxyAHost); // Next try the IP address of the second proxy. assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(254, 1); assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[0], proxyBPort, - ConnectionConfiguration.CLEARTEXT); + ConnectionSpec.CLEARTEXT); dns.assertRequests(proxyBHost); // Finally try the only IP address of the origin server. assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(253, 1); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], uriPort, - ConnectionConfiguration.CLEARTEXT); + ConnectionSpec.CLEARTEXT); dns.assertRequests(uriHost); assertFalse(routeSelector.hasNext()); @@ -258,7 +258,7 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 1); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], uriPort, - ConnectionConfiguration.CLEARTEXT); + ConnectionSpec.CLEARTEXT); dns.assertRequests(uriHost); assertFalse(routeSelector.hasNext()); @@ -276,7 +276,7 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 1); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], - proxyAPort, ConnectionConfiguration.CLEARTEXT); + proxyAPort, ConnectionSpec.CLEARTEXT); dns.assertRequests(proxyAHost); assertTrue(routeSelector.hasNext()); @@ -291,13 +291,13 @@ public final class RouteSelectorTest { assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(255, 1); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], - proxyAPort, ConnectionConfiguration.CLEARTEXT); + proxyAPort, ConnectionSpec.CLEARTEXT); dns.assertRequests(proxyAHost); assertTrue(routeSelector.hasNext()); dns.inetAddresses = makeFakeAddresses(254, 1); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.CLEARTEXT); + uriPort, ConnectionSpec.CLEARTEXT); dns.assertRequests(uriHost); assertFalse(routeSelector.hasNext()); @@ -328,7 +328,7 @@ public final class RouteSelectorTest { @Test public void multipleProxiesMultipleInetAddressesMultipleConfigurations() throws Exception { Address address = new Address(uriHost, uriPort, socketFactory, sslSocketFactory, - hostnameVerifier, null, authenticator, null, protocols, connectionConfigurations); + hostnameVerifier, null, authenticator, null, protocols, connectionSpecs); proxySelector.proxies.add(proxyA); proxySelector.proxies.add(proxyB); RouteSelector routeSelector = RouteSelector.get(httpsRequest, client); @@ -336,38 +336,38 @@ public final class RouteSelectorTest { // Proxy A dns.inetAddresses = makeFakeAddresses(255, 2); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], - proxyAPort, ConnectionConfiguration.MODERN_TLS); + proxyAPort, ConnectionSpec.MODERN_TLS); dns.assertRequests(proxyAHost); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[0], - proxyAPort, ConnectionConfiguration.COMPATIBLE_TLS); + proxyAPort, ConnectionSpec.COMPATIBLE_TLS); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1], - proxyAPort, ConnectionConfiguration.MODERN_TLS); + proxyAPort, ConnectionSpec.MODERN_TLS); assertConnection(routeSelector.nextUnconnected(), address, proxyA, dns.inetAddresses[1], - proxyAPort, ConnectionConfiguration.COMPATIBLE_TLS); + proxyAPort, ConnectionSpec.COMPATIBLE_TLS); // Proxy B dns.inetAddresses = makeFakeAddresses(254, 2); assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[0], - proxyBPort, ConnectionConfiguration.MODERN_TLS); + proxyBPort, ConnectionSpec.MODERN_TLS); dns.assertRequests(proxyBHost); assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[0], - proxyBPort, ConnectionConfiguration.COMPATIBLE_TLS); + proxyBPort, ConnectionSpec.COMPATIBLE_TLS); assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[1], - proxyBPort, ConnectionConfiguration.MODERN_TLS); + proxyBPort, ConnectionSpec.MODERN_TLS); assertConnection(routeSelector.nextUnconnected(), address, proxyB, dns.inetAddresses[1], - proxyBPort, ConnectionConfiguration.COMPATIBLE_TLS); + proxyBPort, ConnectionSpec.COMPATIBLE_TLS); // Origin dns.inetAddresses = makeFakeAddresses(253, 2); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.MODERN_TLS); + uriPort, ConnectionSpec.MODERN_TLS); dns.assertRequests(uriHost); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[0], - uriPort, ConnectionConfiguration.COMPATIBLE_TLS); + uriPort, ConnectionSpec.COMPATIBLE_TLS); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1], - uriPort, ConnectionConfiguration.MODERN_TLS); + uriPort, ConnectionSpec.MODERN_TLS); assertConnection(routeSelector.nextUnconnected(), address, NO_PROXY, dns.inetAddresses[1], - uriPort, ConnectionConfiguration.COMPATIBLE_TLS); + uriPort, ConnectionSpec.COMPATIBLE_TLS); assertFalse(routeSelector.hasNext()); } @@ -402,18 +402,18 @@ public final class RouteSelectorTest { } private void assertConnection(Connection connection, Address address, Proxy proxy, - InetAddress socketAddress, int socketPort, ConnectionConfiguration connectionConfiguration) { + InetAddress socketAddress, int socketPort, ConnectionSpec connectionSpec) { assertEquals(address, connection.getRoute().getAddress()); assertEquals(proxy, connection.getRoute().getProxy()); assertEquals(socketAddress, connection.getRoute().getSocketAddress().getAddress()); assertEquals(socketPort, connection.getRoute().getSocketAddress().getPort()); - assertEquals(connectionConfiguration, connection.getRoute().getConnectionConfiguration()); + assertEquals(connectionSpec, connection.getRoute().getConnectionSpec()); } /** Returns an address that's without an SSL socket factory or hostname verifier. */ private Address httpAddress() { return new Address(uriHost, uriPort, socketFactory, null, null, null, authenticator, null, - protocols, connectionConfigurations); + protocols, connectionSpecs); } private static InetAddress[] makeFakeAddresses(int prefix, int count) { diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java index 586e1add51bd..ae98b44d333f 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java @@ -18,7 +18,7 @@ import com.squareup.okhttp.Cache; import com.squareup.okhttp.Challenge; -import com.squareup.okhttp.ConnectionConfiguration; +import com.squareup.okhttp.ConnectionSpec; import com.squareup.okhttp.ConnectionPool; import com.squareup.okhttp.Credentials; import com.squareup.okhttp.OkHttpClient; @@ -855,8 +855,7 @@ private void testConnectViaHttpProxyToHttps(ProxyConfig proxyConfig) throws Exce // Configure a single IP address for the host and a single configuration, so we only need one // failure to fail permanently. Internal.instance.setNetwork(client.client(), new SingleInetAddressNetwork()); - client.client().setConnectionConfigurations( - Util.immutableList(ConnectionConfiguration.MODERN_TLS)); + client.client().setConnectionSpecs(Util.immutableList(ConnectionSpec.MODERN_TLS)); server.enqueue(response); server.play(); client.client().setProxy(server.toProxyAddress()); diff --git a/okhttp/src/main/java/com/squareup/okhttp/Address.java b/okhttp/src/main/java/com/squareup/okhttp/Address.java index 9f7dfb2c04ff..06894eb93c1a 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Address.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Address.java @@ -44,12 +44,12 @@ public final class Address { final CertificatePinner certificatePinner; final Authenticator authenticator; final List protocols; - final List connectionConfigurations; + final List connectionSpecs; public Address(String uriHost, int uriPort, SocketFactory socketFactory, SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier, CertificatePinner certificatePinner, Authenticator authenticator, Proxy proxy, - List protocols, List connectionConfigurations) { + List protocols, List connectionSpecs) { if (uriHost == null) throw new NullPointerException("uriHost == null"); if (uriPort <= 0) throw new IllegalArgumentException("uriPort <= 0: " + uriPort); if (authenticator == null) throw new IllegalArgumentException("authenticator == null"); @@ -63,7 +63,7 @@ public Address(String uriHost, int uriPort, SocketFactory socketFactory, this.certificatePinner = certificatePinner; this.authenticator = authenticator; this.protocols = Util.immutableList(protocols); - this.connectionConfigurations = Util.immutableList(connectionConfigurations); + this.connectionSpecs = Util.immutableList(connectionSpecs); } /** Returns the hostname of the origin server. */ @@ -115,8 +115,8 @@ public List getProtocols() { return protocols; } - public List getConnectionConfigurations() { - return connectionConfigurations; + public List getConnectionSpecs() { + return connectionSpecs; } /** diff --git a/okhttp/src/main/java/com/squareup/okhttp/Connection.java b/okhttp/src/main/java/com/squareup/okhttp/Connection.java index a87cafd75e67..f1d00154250a 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Connection.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Connection.java @@ -229,7 +229,7 @@ private void upgradeToTls(Request tunnelRequest, int readTimeout, int writeTimeo SSLSocket sslSocket = (SSLSocket) socket; // Configure the socket's ciphers, TLS versions, and extensions. - route.connectionConfiguration.apply(sslSocket, route); + route.connectionSpec.apply(sslSocket, route); // Force handshake. This can throw! sslSocket.startHandshake(); @@ -246,7 +246,7 @@ private void upgradeToTls(Request tunnelRequest, int readTimeout, int writeTimeo handshake = Handshake.get(sslSocket.getSession()); String maybeProtocol; - if (route.connectionConfiguration.supportsTlsExtensions() + if (route.connectionSpec.supportsTlsExtensions() && (maybeProtocol = platform.getSelectedProtocol(sslSocket)) != null) { protocol = Protocol.get(maybeProtocol); // Throws IOE on unknown. } diff --git a/okhttp/src/main/java/com/squareup/okhttp/ConnectionConfiguration.java b/okhttp/src/main/java/com/squareup/okhttp/ConnectionSpec.java similarity index 74% rename from okhttp/src/main/java/com/squareup/okhttp/ConnectionConfiguration.java rename to okhttp/src/main/java/com/squareup/okhttp/ConnectionSpec.java index 2360812bb502..db7e34f6a11f 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/ConnectionConfiguration.java +++ b/okhttp/src/main/java/com/squareup/okhttp/ConnectionSpec.java @@ -22,18 +22,18 @@ import javax.net.ssl.SSLSocket; /** - * Configuration for the socket connection that HTTP traffic travels through. - * For {@code https:} URLs, this includes the TLS version and ciphers to use - * when negotiating a secure connection. + * Specifies configuration for the socket connection that HTTP traffic travels through. For {@code + * https:} URLs, this includes the TLS version and ciphers to use when negotiating a secure + * connection. */ -public final class ConnectionConfiguration { +public final class ConnectionSpec { private static final String TLS_1_2 = "TLSv1.2"; // 2008. private static final String TLS_1_1 = "TLSv1.1"; // 2006. private static final String TLS_1_0 = "TLSv1"; // 1999. private static final String SSL_3_0 = "SSLv3"; // 1996. - /** A modern TLS configuration with extensions like SNI and ALPN available. */ - public static final ConnectionConfiguration MODERN_TLS = new Builder(true) + /** A modern TLS connection with extensions like SNI and ALPN available. */ + public static final ConnectionSpec MODERN_TLS = new Builder(true) .cipherSuites( // This is a subset of the cipher suites supported in Chrome 37, current as of 2014-10-5. // All of these suites are available on Android L; earlier releases support a subset of @@ -61,13 +61,13 @@ public final class ConnectionConfiguration { .supportsTlsExtensions(true) .build(); - /** A backwards-compatible fallback configuration for interop with obsolete servers. */ - public static final ConnectionConfiguration COMPATIBLE_TLS = new Builder(MODERN_TLS) + /** A backwards-compatible fallback connection for interop with obsolete servers. */ + public static final ConnectionSpec COMPATIBLE_TLS = new Builder(MODERN_TLS) .tlsVersions(SSL_3_0) .build(); /** Unencrypted, unauthenticated connections for {@code http:} URLs. */ - public static final ConnectionConfiguration CLEARTEXT = new Builder(false).build(); + public static final ConnectionSpec CLEARTEXT = new Builder(false).build(); final boolean tls; private final String[] cipherSuites; @@ -75,13 +75,13 @@ public final class ConnectionConfiguration { final boolean supportsTlsExtensions; /** - * Caches the subset of this configuration that's supported by the host - * platform. It's possible that the platform hosts multiple implementations of - * {@link SSLSocket}, in which case this cache will be incorrect. + * Caches the subset of this spec that's supported by the host platform. It's possible that the + * platform hosts multiple implementations of {@link SSLSocket}, in which case this cache will be + * incorrect. */ - private ConnectionConfiguration supportedConfiguration; + private ConnectionSpec supportedSpec; - private ConnectionConfiguration(Builder builder) { + private ConnectionSpec(Builder builder) { this.tls = builder.tls; this.cipherSuites = builder.cipherSuites; this.tlsVersions = builder.tlsVersions; @@ -104,19 +104,19 @@ public boolean supportsTlsExtensions() { return supportsTlsExtensions; } - /** Applies this configuration to {@code sslSocket} for {@code route}. */ + /** Applies this spec to {@code sslSocket} for {@code route}. */ void apply(SSLSocket sslSocket, Route route) { - ConnectionConfiguration configurationToApply = supportedConfiguration; - if (configurationToApply == null) { - configurationToApply = supportedConfiguration(sslSocket); - supportedConfiguration = configurationToApply; + ConnectionSpec specToApply = supportedSpec; + if (specToApply == null) { + specToApply = supportedSpec(sslSocket); + supportedSpec = specToApply; } - sslSocket.setEnabledProtocols(configurationToApply.tlsVersions); - sslSocket.setEnabledCipherSuites(configurationToApply.cipherSuites); + sslSocket.setEnabledProtocols(specToApply.tlsVersions); + sslSocket.setEnabledCipherSuites(specToApply.cipherSuites); Platform platform = Platform.get(); - if (configurationToApply.supportsTlsExtensions) { + if (specToApply.supportsTlsExtensions) { platform.configureTlsExtensions(sslSocket, route.address.uriHost, route.address.protocols); } } @@ -125,7 +125,7 @@ void apply(SSLSocket sslSocket, Route route) { * Returns a copy of this that omits cipher suites and TLS versions not * supported by {@code sslSocket}. */ - private ConnectionConfiguration supportedConfiguration(SSLSocket sslSocket) { + private ConnectionSpec supportedSpec(SSLSocket sslSocket) { List supportedCipherSuites = Util.intersect(Arrays.asList(cipherSuites), Arrays.asList(sslSocket.getSupportedCipherSuites())); List supportedTlsVersions = Util.intersect(Arrays.asList(tlsVersions), @@ -137,9 +137,9 @@ private ConnectionConfiguration supportedConfiguration(SSLSocket sslSocket) { } @Override public boolean equals(Object other) { - if (!(other instanceof ConnectionConfiguration)) return false; + if (!(other instanceof ConnectionSpec)) return false; - ConnectionConfiguration that = (ConnectionConfiguration) other; + ConnectionSpec that = (ConnectionSpec) other; if (this.tls != that.tls) return false; if (tls) { @@ -163,12 +163,12 @@ private ConnectionConfiguration supportedConfiguration(SSLSocket sslSocket) { @Override public String toString() { if (tls) { - return "ConnectionConfiguration(cipherSuites=" + Arrays.toString(cipherSuites) + return "ConnectionSpec(cipherSuites=" + Arrays.toString(cipherSuites) + ", tlsVersions=" + Arrays.toString(tlsVersions) + ", supportsTlsExtensions=" + supportsTlsExtensions + ")"; } else { - return "ConnectionConfiguration()"; + return "ConnectionSpec()"; } } @@ -182,11 +182,11 @@ private Builder(boolean tls) { this.tls = tls; } - public Builder(ConnectionConfiguration connectionConfiguration) { - this.tls = connectionConfiguration.tls; - this.cipherSuites = connectionConfiguration.cipherSuites; - this.tlsVersions = connectionConfiguration.tlsVersions; - this.supportsTlsExtensions = connectionConfiguration.supportsTlsExtensions; + public Builder(ConnectionSpec connectionSpec) { + this.tls = connectionSpec.tls; + this.cipherSuites = connectionSpec.cipherSuites; + this.tlsVersions = connectionSpec.tlsVersions; + this.supportsTlsExtensions = connectionSpec.supportsTlsExtensions; } public Builder cipherSuites(String... cipherSuites) { @@ -207,8 +207,8 @@ public Builder supportsTlsExtensions(boolean supportsTlsExtensions) { return this; } - public ConnectionConfiguration build() { - return new ConnectionConfiguration(this); + public ConnectionSpec build() { + return new ConnectionSpec(this); } } } diff --git a/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java b/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java index b51c8b8ea1b9..e723b3333dee 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java +++ b/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java @@ -52,9 +52,8 @@ public class OkHttpClient implements Cloneable { private static final List DEFAULT_PROTOCOLS = Util.immutableList( Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1); - private static final List DEFAULT_CONNECTION_CONFIGURATIONS = - Util.immutableList(ConnectionConfiguration.MODERN_TLS, ConnectionConfiguration.COMPATIBLE_TLS, - ConnectionConfiguration.CLEARTEXT); + private static final List DEFAULT_CONNECTION_SPECS = Util.immutableList( + ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS, ConnectionSpec.CLEARTEXT); static { Internal.instance = new Internal() { @@ -129,7 +128,7 @@ public class OkHttpClient implements Cloneable { private Dispatcher dispatcher; private Proxy proxy; private List protocols; - private List connectionConfigurations; + private List connectionSpecs; private ProxySelector proxySelector; private CookieHandler cookieHandler; @@ -160,7 +159,7 @@ private OkHttpClient(OkHttpClient okHttpClient) { this.dispatcher = okHttpClient.dispatcher; this.proxy = okHttpClient.proxy; this.protocols = okHttpClient.protocols; - this.connectionConfigurations = okHttpClient.connectionConfigurations; + this.connectionSpecs = okHttpClient.connectionSpecs; this.proxySelector = okHttpClient.proxySelector; this.cookieHandler = okHttpClient.cookieHandler; this.cache = okHttpClient.cache; @@ -483,14 +482,13 @@ public final List getProtocols() { return protocols; } - public final OkHttpClient setConnectionConfigurations( - List connectionConfigurations) { - this.connectionConfigurations = Util.immutableList(connectionConfigurations); + public final OkHttpClient setConnectionSpecs(List connectionSpecs) { + this.connectionSpecs = Util.immutableList(connectionSpecs); return this; } - public final List getConnectionConfigurations() { - return connectionConfigurations; + public final List getConnectionSpecs() { + return connectionSpecs; } /** @@ -542,8 +540,8 @@ final OkHttpClient copyWithDefaults() { if (result.protocols == null) { result.protocols = DEFAULT_PROTOCOLS; } - if (result.connectionConfigurations == null) { - result.connectionConfigurations = DEFAULT_CONNECTION_CONFIGURATIONS; + if (result.connectionSpecs == null) { + result.connectionSpecs = DEFAULT_CONNECTION_SPECS; } if (result.network == null) { result.network = Network.DEFAULT; diff --git a/okhttp/src/main/java/com/squareup/okhttp/Route.java b/okhttp/src/main/java/com/squareup/okhttp/Route.java index cadf9eb18d2b..6e6c3bf33c79 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/Route.java +++ b/okhttp/src/main/java/com/squareup/okhttp/Route.java @@ -37,10 +37,10 @@ public final class Route { final Address address; final Proxy proxy; final InetSocketAddress inetSocketAddress; - final ConnectionConfiguration connectionConfiguration; + final ConnectionSpec connectionSpec; public Route(Address address, Proxy proxy, InetSocketAddress inetSocketAddress, - ConnectionConfiguration connectionConfiguration) { + ConnectionSpec connectionSpec) { if (address == null) { throw new NullPointerException("address == null"); } @@ -50,13 +50,13 @@ public Route(Address address, Proxy proxy, InetSocketAddress inetSocketAddress, if (inetSocketAddress == null) { throw new NullPointerException("inetSocketAddress == null"); } - if (connectionConfiguration == null) { + if (connectionSpec == null) { throw new NullPointerException("connectionConfiguration == null"); } this.address = address; this.proxy = proxy; this.inetSocketAddress = inetSocketAddress; - this.connectionConfiguration = connectionConfiguration; + this.connectionSpec = connectionSpec; } public Address getAddress() { @@ -78,8 +78,8 @@ public InetSocketAddress getSocketAddress() { return inetSocketAddress; } - public ConnectionConfiguration getConnectionConfiguration() { - return connectionConfiguration; + public ConnectionSpec getConnectionSpec() { + return connectionSpec; } /** @@ -96,7 +96,7 @@ public boolean requiresTunnel() { return address.equals(other.address) && proxy.equals(other.proxy) && inetSocketAddress.equals(other.inetSocketAddress) - && connectionConfiguration.equals(other.connectionConfiguration); + && connectionSpec.equals(other.connectionSpec); } return false; } @@ -106,7 +106,7 @@ public boolean requiresTunnel() { result = 31 * result + address.hashCode(); result = 31 * result + proxy.hashCode(); result = 31 * result + inetSocketAddress.hashCode(); - result = 31 * result + connectionConfiguration.hashCode(); + result = 31 * result + connectionSpec.hashCode(); return result; } } diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java index c5a24b564a05..a6e6022c9d61 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java +++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java @@ -18,7 +18,7 @@ import com.squareup.okhttp.Address; import com.squareup.okhttp.CertificatePinner; import com.squareup.okhttp.Connection; -import com.squareup.okhttp.ConnectionConfiguration; +import com.squareup.okhttp.ConnectionSpec; import com.squareup.okhttp.ConnectionPool; import com.squareup.okhttp.OkHttpClient; import com.squareup.okhttp.Request; @@ -64,7 +64,7 @@ public final class RouteSelector { /* The most recently attempted route. */ private Proxy lastProxy; private InetSocketAddress lastInetSocketAddress; - private ConnectionConfiguration lastConfiguration; + private ConnectionSpec lastSpec; /* State for negotiating the next proxy to use. */ private List proxies = Collections.emptyList(); @@ -74,9 +74,9 @@ public final class RouteSelector { private List inetSocketAddresses = Collections.emptyList(); private int nextInetSocketAddressIndex; - /* TLS configuration to attempt with the connection. */ - private List connectionConfigurations = Collections.emptyList(); - private int nextConfigurationIndex; + /* Specs to attempt with the connection. */ + private List connectionSpecs = Collections.emptyList(); + private int nextSpecIndex; /* State for negotiating failed routes */ private final List postponedRoutes = new ArrayList<>(); @@ -112,7 +112,7 @@ public static RouteSelector get(Request request, OkHttpClient client) throws IOE Address address = new Address(uriHost, getEffectivePort(request.url()), client.getSocketFactory(), sslSocketFactory, hostnameVerifier, certificatePinner, client.getAuthenticator(), client.getProxy(), client.getProtocols(), - client.getConnectionConfigurations()); + client.getConnectionSpecs()); return new RouteSelector(address, request.uri(), client, request); } @@ -122,7 +122,7 @@ public static RouteSelector get(Request request, OkHttpClient client) throws IOE * least one route. */ public boolean hasNext() { - return hasNextConnectionConfiguration() + return hasNextConnectionSpec() || hasNextInetSocketAddress() || hasNextProxy() || hasNextPostponed(); @@ -148,7 +148,7 @@ Connection nextUnconnected() throws IOException { } // Compute the next route to attempt. - if (!hasNextConnectionConfiguration()) { + if (!hasNextConnectionSpec()) { if (!hasNextInetSocketAddress()) { if (!hasNextProxy()) { if (!hasNextPostponed()) { @@ -160,9 +160,9 @@ Connection nextUnconnected() throws IOException { } lastInetSocketAddress = nextInetSocketAddress(); } - lastConfiguration = nextConnectionConfiguration(); + lastSpec = nextConnectionSpec(); - Route route = new Route(address, lastProxy, lastInetSocketAddress, lastConfiguration); + Route route = new Route(address, lastProxy, lastInetSocketAddress, lastSpec); if (routeDatabase.shouldPostpone(route)) { postponedRoutes.add(route); // We will only recurse in order to skip previously failed routes. They will be tried last. @@ -188,14 +188,13 @@ public void connectFailed(Connection connection, IOException failure) { routeDatabase.failed(failedRoute); - // If the previously returned route's problem was not related to the - // connection's configuration, and the next route only changes that, we - // shouldn't even attempt it. This suppresses it in both this selector - // and also in the route database. + // If the previously returned route's problem was not related to the connection's spec, and the + // next route only changes that, we shouldn't even attempt it. This suppresses it in both this + // selector and also in the route database. if (!(failure instanceof SSLHandshakeException) && !(failure instanceof SSLProtocolException)) { - while (nextConfigurationIndex < connectionConfigurations.size()) { + while (nextSpecIndex < connectionSpecs.size()) { Route toSuppress = new Route(address, lastProxy, lastInetSocketAddress, - connectionConfigurations.get(nextConfigurationIndex++)); + connectionSpecs.get(nextSpecIndex++)); routeDatabase.failed(toSuppress); } } @@ -275,33 +274,33 @@ private InetSocketAddress nextInetSocketAddress() throws IOException { + "; exhausted inet socket addresses: " + inetSocketAddresses); } InetSocketAddress result = inetSocketAddresses.get(nextInetSocketAddressIndex++); - resetConnectionConfigurations(); + resetConnectionSpecs(); return result; } - /** Prepares the connection configurations to attempt. */ - private void resetConnectionConfigurations() { - connectionConfigurations = new ArrayList<>(); - for (ConnectionConfiguration configuration : address.getConnectionConfigurations()) { - if (request.isHttps() == configuration.isTls()) { - connectionConfigurations.add(configuration); + /** Prepares the connection specs to attempt. */ + private void resetConnectionSpecs() { + connectionSpecs = new ArrayList<>(); + for (ConnectionSpec spec : address.getConnectionSpecs()) { + if (request.isHttps() == spec.isTls()) { + connectionSpecs.add(spec); } } - nextConfigurationIndex = 0; + nextSpecIndex = 0; } - /** Returns true if there's another connection configuration to try. */ - private boolean hasNextConnectionConfiguration() { - return nextConfigurationIndex < connectionConfigurations.size(); + /** Returns true if there's another connection spec to try. */ + private boolean hasNextConnectionSpec() { + return nextSpecIndex < connectionSpecs.size(); } - /** Returns the next connection configuration to try. */ - private ConnectionConfiguration nextConnectionConfiguration() throws IOException { - if (!hasNextConnectionConfiguration()) { + /** Returns the next connection spec to try. */ + private ConnectionSpec nextConnectionSpec() throws IOException { + if (!hasNextConnectionSpec()) { throw new SocketException("No route to " + address.getUriHost() - + "; exhausted connection configurations: " + connectionConfigurations); + + "; exhausted connection specs: " + connectionSpecs); } - return connectionConfigurations.get(nextConfigurationIndex++); + return connectionSpecs.get(nextSpecIndex++); } /** Returns true if there is another postponed route to try. */