mirror of
https://github.com/square/okhttp.git
synced 2026-01-15 20:56:41 +03:00
Android 4 and Java 1.7 prefer TLSv1.2 provider (#4089)
* java 1.7 TLV v1.2 support * simplify TLSv1.2 vs TLS selection logic * tighten up version checks * cleanup
This commit is contained in:
committed by
Jesse Wilson
parent
714c9ac8b5
commit
bdbe2dad88
@@ -23,12 +23,14 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Security;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.TrustAnchor;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
@@ -427,4 +429,20 @@ class AndroidPlatform extends Platform {
|
||||
return trustManager.hashCode() + 31 * findByIssuerAndSignatureMethod.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public SSLContext getSSLContext() {
|
||||
if (Build.VERSION.SDK_INT >= 16 && Build.VERSION.SDK_INT < 22) {
|
||||
try {
|
||||
return SSLContext.getInstance("TLSv1.2");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// fallback to TLS
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return SSLContext.getInstance("TLS");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("No TLS provider", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@ public class Platform {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void connectSocket(Socket socket, InetSocketAddress address,
|
||||
int connectTimeout) throws IOException {
|
||||
public void connectSocket(Socket socket, InetSocketAddress address, int connectTimeout)
|
||||
throws IOException {
|
||||
socket.connect(address, connectTimeout);
|
||||
}
|
||||
|
||||
@@ -176,8 +176,10 @@ public class Platform {
|
||||
X509TrustManager trustManager = trustManager(sslSocketFactory);
|
||||
|
||||
if (trustManager == null) {
|
||||
throw new IllegalStateException("Unable to extract the trust manager on " + Platform.get()
|
||||
+ ", sslSocketFactory is " + sslSocketFactory.getClass());
|
||||
throw new IllegalStateException("Unable to extract the trust manager on "
|
||||
+ Platform.get()
|
||||
+ ", sslSocketFactory is "
|
||||
+ sslSocketFactory.getClass());
|
||||
}
|
||||
|
||||
return buildCertificateChainCleaner(trustManager);
|
||||
@@ -265,6 +267,16 @@ public class Platform {
|
||||
}
|
||||
|
||||
public SSLContext getSSLContext() {
|
||||
String jvmVersion = System.getProperty("java.specification.version");
|
||||
if ("1.7".equals(jvmVersion)) {
|
||||
try {
|
||||
// JDK 1.7 (public version) only support > TLSv1 with named protocols
|
||||
return SSLContext.getInstance("TLSv1.2");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// fallback to TLS
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return SSLContext.getInstance("TLS");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
||||
Reference in New Issue
Block a user