what-the-bank/sources/okhttp3/internal/platform/AndroidPlatform.java

279 lines
11 KiB
Java

package okhttp3.internal.platform;
import android.os.Build;
import android.security.NetworkSecurityPolicy;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import o.C14875gap;
import o.C14953gcr;
import o.C14957gcv;
import okhttp3.Protocol;
import okhttp3.internal.platform.android.AndroidCertificateChainCleaner;
import okhttp3.internal.platform.android.AndroidSocketAdapter;
import okhttp3.internal.platform.android.BouncyCastleSocketAdapter;
import okhttp3.internal.platform.android.CloseGuard;
import okhttp3.internal.platform.android.ConscryptSocketAdapter;
import okhttp3.internal.platform.android.DeferredSocketAdapter;
import okhttp3.internal.platform.android.SocketAdapter;
import okhttp3.internal.platform.android.StandardAndroidSocketAdapter;
import okhttp3.internal.tls.CertificateChainCleaner;
import okhttp3.internal.tls.TrustRootIndex;
/* loaded from: classes.dex */
public final class AndroidPlatform extends Platform {
public static final Companion Companion = new Companion(null);
private static final boolean isSupported;
private final CloseGuard closeGuard;
private final List<SocketAdapter> socketAdapters;
public AndroidPlatform() {
SocketAdapter[] socketAdapterArr = {StandardAndroidSocketAdapter.Companion.buildIfSupported$default(StandardAndroidSocketAdapter.Companion, null, 1, null), new DeferredSocketAdapter(AndroidSocketAdapter.Companion.getPlayProviderFactory()), new DeferredSocketAdapter(ConscryptSocketAdapter.Companion.getFactory()), new DeferredSocketAdapter(BouncyCastleSocketAdapter.Companion.getFactory())};
C14957gcv.e(socketAdapterArr, "");
C14957gcv.e(socketAdapterArr, "");
List list = (List) C14875gap.d((Object[]) socketAdapterArr, new ArrayList());
ArrayList arrayList = new ArrayList();
for (Object obj : list) {
if (((SocketAdapter) obj).isSupported()) {
arrayList.add(obj);
}
}
this.socketAdapters = arrayList;
this.closeGuard = CloseGuard.Companion.get();
}
@Override // okhttp3.internal.platform.Platform
public final void connectSocket(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
C14957gcv.e(socket, "");
C14957gcv.e(inetSocketAddress, "");
try {
socket.connect(inetSocketAddress, i);
} catch (ClassCastException e) {
if (Build.VERSION.SDK_INT == 26) {
throw new IOException("Exception in connect", e);
}
throw e;
}
}
@Override // okhttp3.internal.platform.Platform
public final X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) {
Object obj;
C14957gcv.e(sSLSocketFactory, "");
Iterator<T> it = this.socketAdapters.iterator();
while (true) {
if (!it.hasNext()) {
obj = null;
break;
}
obj = it.next();
if (((SocketAdapter) obj).matchesSocketFactory(sSLSocketFactory)) {
break;
}
}
SocketAdapter socketAdapter = (SocketAdapter) obj;
if (socketAdapter == null) {
return null;
}
return socketAdapter.trustManager(sSLSocketFactory);
}
@Override // okhttp3.internal.platform.Platform
public final void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
Object obj;
C14957gcv.e(sSLSocket, "");
C14957gcv.e(list, "");
Iterator<T> it = this.socketAdapters.iterator();
while (true) {
if (!it.hasNext()) {
obj = null;
break;
} else {
obj = it.next();
if (((SocketAdapter) obj).matchesSocket(sSLSocket)) {
break;
}
}
}
SocketAdapter socketAdapter = (SocketAdapter) obj;
if (socketAdapter != null) {
socketAdapter.configureTlsExtensions(sSLSocket, str, list);
}
}
@Override // okhttp3.internal.platform.Platform
public final String getSelectedProtocol(SSLSocket sSLSocket) {
Object obj;
C14957gcv.e(sSLSocket, "");
Iterator<T> it = this.socketAdapters.iterator();
while (true) {
if (!it.hasNext()) {
obj = null;
break;
}
obj = it.next();
if (((SocketAdapter) obj).matchesSocket(sSLSocket)) {
break;
}
}
SocketAdapter socketAdapter = (SocketAdapter) obj;
if (socketAdapter == null) {
return null;
}
return socketAdapter.getSelectedProtocol(sSLSocket);
}
@Override // okhttp3.internal.platform.Platform
public final Object getStackTraceForCloseable(String str) {
C14957gcv.e(str, "");
return this.closeGuard.createAndOpen(str);
}
@Override // okhttp3.internal.platform.Platform
public final void logCloseableLeak(String str, Object obj) {
C14957gcv.e(str, "");
if (this.closeGuard.warnIfOpen(obj)) {
return;
}
Platform.log$default(this, str, 5, null, 4, null);
}
@Override // okhttp3.internal.platform.Platform
public final boolean isCleartextTrafficPermitted(String str) {
C14957gcv.e(str, "");
return NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(str);
}
@Override // okhttp3.internal.platform.Platform
public final CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager x509TrustManager) {
C14957gcv.e(x509TrustManager, "");
AndroidCertificateChainCleaner buildIfSupported = AndroidCertificateChainCleaner.Companion.buildIfSupported(x509TrustManager);
return buildIfSupported == null ? super.buildCertificateChainCleaner(x509TrustManager) : buildIfSupported;
}
@Override // okhttp3.internal.platform.Platform
public final TrustRootIndex buildTrustRootIndex(X509TrustManager x509TrustManager) {
C14957gcv.e(x509TrustManager, "");
try {
Method declaredMethod = x509TrustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", X509Certificate.class);
declaredMethod.setAccessible(true);
C14957gcv.c(declaredMethod, "");
return new CustomTrustRootIndex(x509TrustManager, declaredMethod);
} catch (NoSuchMethodException unused) {
return super.buildTrustRootIndex(x509TrustManager);
}
}
/* loaded from: classes.dex */
public static final class CustomTrustRootIndex implements TrustRootIndex {
private final Method findByIssuerAndSignatureMethod;
private final X509TrustManager trustManager;
public CustomTrustRootIndex(X509TrustManager x509TrustManager, Method method) {
C14957gcv.e(x509TrustManager, "");
C14957gcv.e(method, "");
this.trustManager = x509TrustManager;
this.findByIssuerAndSignatureMethod = method;
}
@Override // okhttp3.internal.tls.TrustRootIndex
public final X509Certificate findByIssuerAndSignature(X509Certificate x509Certificate) {
C14957gcv.e(x509Certificate, "");
try {
Object invoke = this.findByIssuerAndSignatureMethod.invoke(this.trustManager, x509Certificate);
if (invoke == null) {
throw new NullPointerException("null cannot be cast to non-null type java.security.cert.TrustAnchor");
}
return ((TrustAnchor) invoke).getTrustedCert();
} catch (IllegalAccessException e) {
throw new AssertionError("unable to get issues and signature", e);
} catch (InvocationTargetException unused) {
return null;
}
}
public final String toString() {
StringBuilder sb = new StringBuilder("CustomTrustRootIndex(trustManager=");
sb.append(this.trustManager);
sb.append(", findByIssuerAndSignatureMethod=");
sb.append(this.findByIssuerAndSignatureMethod);
sb.append(')');
return sb.toString();
}
public final int hashCode() {
return (this.trustManager.hashCode() * 31) + this.findByIssuerAndSignatureMethod.hashCode();
}
public final boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof CustomTrustRootIndex)) {
return false;
}
CustomTrustRootIndex customTrustRootIndex = (CustomTrustRootIndex) obj;
return C14957gcv.b(this.trustManager, customTrustRootIndex.trustManager) && C14957gcv.b(this.findByIssuerAndSignatureMethod, customTrustRootIndex.findByIssuerAndSignatureMethod);
}
public final CustomTrustRootIndex copy(X509TrustManager x509TrustManager, Method method) {
C14957gcv.e(x509TrustManager, "");
C14957gcv.e(method, "");
return new CustomTrustRootIndex(x509TrustManager, method);
}
public static /* synthetic */ CustomTrustRootIndex copy$default(CustomTrustRootIndex customTrustRootIndex, X509TrustManager x509TrustManager, Method method, int i, Object obj) {
if ((i & 1) != 0) {
x509TrustManager = customTrustRootIndex.trustManager;
}
if ((i & 2) != 0) {
method = customTrustRootIndex.findByIssuerAndSignatureMethod;
}
return customTrustRootIndex.copy(x509TrustManager, method);
}
private final Method component2() {
return this.findByIssuerAndSignatureMethod;
}
private final X509TrustManager component1() {
return this.trustManager;
}
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
public final boolean isSupported() {
return AndroidPlatform.isSupported;
}
public final Platform buildIfSupported() {
if (isSupported()) {
return new AndroidPlatform();
}
return null;
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
isSupported = Platform.Companion.isAndroid() && Build.VERSION.SDK_INT < 30;
}
}