what-the-bank/sources/okhttp3/repackaged/internal/Platform.java

346 lines
14 KiB
Java

package okhttp3.repackaged.internal;
import com.google.android.gms.analytics.ecommerce.ProductAction;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import o.giM;
import okhttp3.repackaged.Protocol;
import okhttp3.repackaged.internal.tls.AndroidTrustRootIndex;
import okhttp3.repackaged.internal.tls.RealTrustRootIndex;
import okhttp3.repackaged.internal.tls.TrustRootIndex;
/* loaded from: classes6.dex */
public class Platform {
private static final Platform ajm = uA();
public void afterHandshake(SSLSocket sSLSocket) {
}
public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
}
public String getSelectedProtocol(SSLSocket sSLSocket) {
return null;
}
public void logW(String str) {
System.out.println(str);
}
public X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) {
try {
Object readFieldOrNull = readFieldOrNull(sSLSocketFactory, Class.forName("sun.security.ssl.SSLContextImpl"), "context");
if (readFieldOrNull == null) {
return null;
}
return (X509TrustManager) readFieldOrNull(readFieldOrNull, X509TrustManager.class, "trustManager");
} catch (ClassNotFoundException unused) {
return null;
}
}
public TrustRootIndex trustRootIndex(X509TrustManager x509TrustManager) {
return new RealTrustRootIndex(x509TrustManager.getAcceptedIssuers());
}
public void connectSocket(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
socket.connect(inetSocketAddress, i);
}
public void log(String str) {
System.out.println(str);
}
private static Platform uA() {
Class<?> cls;
okhttp3.repackaged.internal.b bVar;
okhttp3.repackaged.internal.b bVar2;
okhttp3.repackaged.internal.b bVar3;
try {
try {
try {
cls = Class.forName("com.android.org.conscrypt.SSLParametersImpl");
} catch (ClassNotFoundException unused) {
Class<?> cls2 = Class.forName("org.eclipse.jetty.alpn.ALPN");
return new b(cls2.getMethod("put", SSLSocket.class, Class.forName("org.eclipse.jetty.alpn.ALPN$Provider")), cls2.getMethod("get", SSLSocket.class), cls2.getMethod(ProductAction.ACTION_REMOVE, SSLSocket.class), Class.forName("org.eclipse.jetty.alpn.ALPN$ClientProvider"), Class.forName("org.eclipse.jetty.alpn.ALPN$ServerProvider"));
}
} catch (ClassNotFoundException | NoSuchMethodException unused2) {
return new Platform();
}
} catch (ClassNotFoundException unused3) {
cls = Class.forName("org.apache.harmony.xnet.provider.jsse.SSLParametersImpl");
}
Class<?> cls3 = cls;
okhttp3.repackaged.internal.b bVar4 = new okhttp3.repackaged.internal.b(null, "setUseSessionTickets", Boolean.TYPE);
okhttp3.repackaged.internal.b bVar5 = new okhttp3.repackaged.internal.b(null, "setHostname", String.class);
try {
Class.forName("android.net.Network");
bVar = new okhttp3.repackaged.internal.b(byte[].class, "getAlpnSelectedProtocol", new Class[0]);
} catch (ClassNotFoundException unused4) {
bVar = null;
}
try {
bVar3 = new okhttp3.repackaged.internal.b(null, "setAlpnProtocols", byte[].class);
bVar2 = bVar;
} catch (ClassNotFoundException unused5) {
bVar2 = bVar;
bVar3 = null;
return new a(cls3, bVar4, bVar5, bVar2, bVar3);
}
return new a(cls3, bVar4, bVar5, bVar2, bVar3);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public static class a extends Platform {
private static final int ajn = 4000;
private final Class<?> ajo;
private final okhttp3.repackaged.internal.b<Socket> ajp;
private final okhttp3.repackaged.internal.b<Socket> ajq;
private final okhttp3.repackaged.internal.b<Socket> ajr;
private final okhttp3.repackaged.internal.b<Socket> ajs;
@Override // okhttp3.repackaged.internal.Platform
public void log(String str) {
}
public a(Class<?> cls, okhttp3.repackaged.internal.b<Socket> bVar, okhttp3.repackaged.internal.b<Socket> bVar2, okhttp3.repackaged.internal.b<Socket> bVar3, okhttp3.repackaged.internal.b<Socket> bVar4) {
this.ajo = cls;
this.ajp = bVar;
this.ajq = bVar2;
this.ajr = bVar3;
this.ajs = bVar4;
}
@Override // okhttp3.repackaged.internal.Platform
public void connectSocket(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
try {
socket.connect(inetSocketAddress, i);
} catch (AssertionError e) {
if (!Util.isAndroidGetsocknameError(e)) {
throw e;
}
throw new IOException(e);
} catch (SecurityException e2) {
IOException iOException = new IOException("Exception in connect");
iOException.initCause(e2);
throw iOException;
}
}
@Override // okhttp3.repackaged.internal.Platform
public X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) {
Object readFieldOrNull = readFieldOrNull(sSLSocketFactory, this.ajo, "sslParameters");
if (readFieldOrNull == null) {
try {
readFieldOrNull = readFieldOrNull(sSLSocketFactory, Class.forName("com.google.android.gms.org.conscrypt.SSLParametersImpl", false, sSLSocketFactory.getClass().getClassLoader()), "sslParameters");
} catch (ClassNotFoundException unused) {
return super.trustManager(sSLSocketFactory);
}
}
X509TrustManager x509TrustManager = (X509TrustManager) readFieldOrNull(readFieldOrNull, X509TrustManager.class, "x509TrustManager");
return x509TrustManager != null ? x509TrustManager : (X509TrustManager) readFieldOrNull(readFieldOrNull, X509TrustManager.class, "trustManager");
}
@Override // okhttp3.repackaged.internal.Platform
public TrustRootIndex trustRootIndex(X509TrustManager x509TrustManager) {
TrustRootIndex trustRootIndex = AndroidTrustRootIndex.get(x509TrustManager);
return trustRootIndex != null ? trustRootIndex : super.trustRootIndex(x509TrustManager);
}
@Override // okhttp3.repackaged.internal.Platform
public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
if (str != null) {
this.ajp.invokeOptionalWithoutCheckedException(sSLSocket, Boolean.TRUE);
this.ajq.invokeOptionalWithoutCheckedException(sSLSocket, str);
}
okhttp3.repackaged.internal.b<Socket> bVar = this.ajs;
if (bVar == null || !bVar.isSupported(sSLSocket)) {
return;
}
this.ajs.invokeWithoutCheckedException(sSLSocket, concatLengthPrefixed(list));
}
@Override // okhttp3.repackaged.internal.Platform
public String getSelectedProtocol(SSLSocket sSLSocket) {
byte[] bArr;
okhttp3.repackaged.internal.b<Socket> bVar = this.ajr;
if (bVar == null || !bVar.isSupported(sSLSocket) || (bArr = (byte[]) this.ajr.invokeWithoutCheckedException(sSLSocket, new Object[0])) == null) {
return null;
}
return new String(bArr, Util.UTF_8);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes6.dex */
public static class b extends Platform {
private final Method ajt;
private final Method aju;
private final Method ajv;
private final Class<?> ajw;
private final Class<?> ajx;
public b(Method method, Method method2, Method method3, Class<?> cls, Class<?> cls2) {
this.ajt = method;
this.aju = method2;
this.ajv = method3;
this.ajw = cls;
this.ajx = cls2;
}
@Override // okhttp3.repackaged.internal.Platform
public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
ArrayList arrayList = new ArrayList(list.size());
int size = list.size();
for (int i = 0; i < size; i++) {
Protocol protocol = list.get(i);
if (protocol != Protocol.HTTP_1_0) {
arrayList.add(protocol.toString());
}
}
try {
this.ajt.invoke(null, sSLSocket, Proxy.newProxyInstance(Platform.class.getClassLoader(), new Class[]{this.ajw, this.ajx}, new c(arrayList)));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
}
}
@Override // okhttp3.repackaged.internal.Platform
public void afterHandshake(SSLSocket sSLSocket) {
try {
this.ajv.invoke(null, sSLSocket);
} catch (IllegalAccessException | InvocationTargetException unused) {
throw new AssertionError();
}
}
@Override // okhttp3.repackaged.internal.Platform
public String getSelectedProtocol(SSLSocket sSLSocket) {
try {
c cVar = (c) Proxy.getInvocationHandler(this.aju.invoke(null, sSLSocket));
if (!cVar.unsupported && cVar.selected == null) {
Internal.logger.log(Level.INFO, "ALPN callback dropped: SPDY and HTTP/2 are disabled. Is alpn-boot on the boot class path?");
return null;
}
if (cVar.unsupported) {
return null;
}
return cVar.selected;
} catch (IllegalAccessException | InvocationTargetException unused) {
throw new AssertionError();
}
}
}
/* loaded from: classes6.dex */
static class c implements InvocationHandler {
private final List<String> protocols;
private String selected;
private boolean unsupported;
public c(List<String> list) {
this.protocols = list;
}
@Override // java.lang.reflect.InvocationHandler
public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
String name = method.getName();
Class<?> returnType = method.getReturnType();
if (objArr == null) {
objArr = Util.EMPTY_STRING_ARRAY;
}
if (name.equals("supports") && Boolean.TYPE == returnType) {
return Boolean.TRUE;
}
if (name.equals("unsupported") && Void.TYPE == returnType) {
this.unsupported = true;
return null;
}
if (name.equals("protocols") && objArr.length == 0) {
return this.protocols;
}
if ((name.equals("selectProtocol") || name.equals("select")) && String.class == returnType && objArr.length == 1) {
Object obj2 = objArr[0];
if (obj2 instanceof List) {
List list = (List) obj2;
int size = list.size();
for (int i = 0; i < size; i++) {
if (this.protocols.contains(list.get(i))) {
String str = (String) list.get(i);
this.selected = str;
return str;
}
}
String str2 = this.protocols.get(0);
this.selected = str2;
return str2;
}
}
if ((name.equals("protocolSelected") || name.equals("selected")) && objArr.length == 1) {
this.selected = (String) objArr[0];
return null;
}
return method.invoke(this, objArr);
}
}
static byte[] concatLengthPrefixed(List<Protocol> list) {
giM gim = new giM();
int size = list.size();
for (int i = 0; i < size; i++) {
Protocol protocol = list.get(i);
if (protocol != Protocol.HTTP_1_0) {
gim.b(protocol.toString().length());
String obj = protocol.toString();
gim.b(obj, 0, obj.length());
}
}
return gim.j();
}
static <T> T readFieldOrNull(Object obj, Class<T> cls, String str) {
do {
for (Class<?> cls2 = obj.getClass(); cls2 != Object.class; cls2 = cls2.getSuperclass()) {
try {
Field declaredField = cls2.getDeclaredField(str);
declaredField.setAccessible(true);
Object obj2 = declaredField.get(obj);
if (obj2 != null && cls.isInstance(obj2)) {
return cls.cast(obj2);
}
return null;
} catch (IllegalAccessException unused) {
throw new AssertionError();
} catch (NoSuchFieldException unused2) {
}
}
if (str.equals("delegate")) {
break;
}
obj = readFieldOrNull(obj, Object.class, "delegate");
} while (obj != null);
return null;
}
public String getPrefix() {
return "OkHttp";
}
public static Platform get() {
return ajm;
}
}