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

304 lines
11 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.internal.platform;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.Security;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import o.C14953gcr;
import o.C14957gcv;
import o.C15111ghZ;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.internal.Util;
import okhttp3.internal.platform.android.AndroidLog;
import okhttp3.internal.tls.BasicCertificateChainCleaner;
import okhttp3.internal.tls.BasicTrustRootIndex;
import okhttp3.internal.tls.CertificateChainCleaner;
import okhttp3.internal.tls.TrustRootIndex;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
/* loaded from: classes.dex */
public class Platform {
public static final Companion Companion;
public static final int INFO = 4;
public static final int WARN = 5;
private static final Logger logger;
private static volatile Platform platform;
public SSLContext newSSLContext() {
SSLContext sSLContext = SSLContext.getInstance(SSLSocketFactory.TLS);
C14957gcv.c(sSLContext, "");
return sSLContext;
}
public X509TrustManager platformTrustManager() {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init((KeyStore) null);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
C14957gcv.e(trustManagers);
if (trustManagers.length == 1) {
TrustManager trustManager = trustManagers[0];
if (trustManager instanceof X509TrustManager) {
if (trustManager != null) {
return (X509TrustManager) trustManager;
}
throw new NullPointerException("null cannot be cast to non-null type javax.net.ssl.X509TrustManager");
}
}
String arrays = Arrays.toString(trustManagers);
C14957gcv.c((Object) arrays, "");
throw new IllegalStateException(C14957gcv.c("Unexpected default trust managers: ", (Object) arrays).toString());
}
public X509TrustManager trustManager(javax.net.ssl.SSLSocketFactory sSLSocketFactory) {
C14957gcv.e(sSLSocketFactory, "");
try {
Class<?> cls = Class.forName("sun.security.ssl.SSLContextImpl");
C14957gcv.c(cls, "");
Object readFieldOrNull = Util.readFieldOrNull(sSLSocketFactory, cls, "context");
if (readFieldOrNull == null) {
return null;
}
return (X509TrustManager) Util.readFieldOrNull(readFieldOrNull, X509TrustManager.class, "trustManager");
} catch (ClassNotFoundException unused) {
return null;
} catch (RuntimeException e) {
if (C14957gcv.b((Object) e.getClass().getName(), (Object) "java.lang.reflect.InaccessibleObjectException")) {
return null;
}
throw e;
}
}
public void connectSocket(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException {
C14957gcv.e(socket, "");
C14957gcv.e(inetSocketAddress, "");
socket.connect(inetSocketAddress, i);
}
public static /* synthetic */ void log$default(Platform platform2, String str, int i, Throwable th, int i2, Object obj) {
if (obj != null) {
throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: log");
}
if ((i2 & 2) != 0) {
i = 4;
}
if ((i2 & 4) != 0) {
th = null;
}
platform2.log(str, i, th);
}
public void log(String str, int i, Throwable th) {
C14957gcv.e(str, "");
logger.log(i == 5 ? Level.WARNING : Level.INFO, str, th);
}
public Object getStackTraceForCloseable(String str) {
C14957gcv.e(str, "");
if (logger.isLoggable(Level.FINE)) {
return new Throwable(str);
}
return null;
}
public void logCloseableLeak(String str, Object obj) {
C14957gcv.e(str, "");
if (obj == null) {
str = C14957gcv.c(str, (Object) " To see where this was allocated, set the OkHttpClient logger level to FINE: Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);");
}
log(str, 5, (Throwable) obj);
}
public CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager x509TrustManager) {
C14957gcv.e(x509TrustManager, "");
return new BasicCertificateChainCleaner(buildTrustRootIndex(x509TrustManager));
}
public TrustRootIndex buildTrustRootIndex(X509TrustManager x509TrustManager) {
C14957gcv.e(x509TrustManager, "");
X509Certificate[] acceptedIssuers = x509TrustManager.getAcceptedIssuers();
C14957gcv.c(acceptedIssuers, "");
return new BasicTrustRootIndex((X509Certificate[]) Arrays.copyOf(acceptedIssuers, acceptedIssuers.length));
}
public javax.net.ssl.SSLSocketFactory newSslSocketFactory(X509TrustManager x509TrustManager) {
C14957gcv.e(x509TrustManager, "");
try {
SSLContext newSSLContext = newSSLContext();
newSSLContext.init(null, new TrustManager[]{x509TrustManager}, null);
javax.net.ssl.SSLSocketFactory socketFactory = newSSLContext.getSocketFactory();
C14957gcv.c(socketFactory, "");
return socketFactory;
} catch (GeneralSecurityException e) {
throw new AssertionError(C14957gcv.c("No System TLS: ", e), e);
}
}
public String toString() {
String simpleName = getClass().getSimpleName();
C14957gcv.c((Object) simpleName, "");
return simpleName;
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
public final Platform get() {
return Platform.platform;
}
public static /* synthetic */ void resetForTests$default(Companion companion, Platform platform, int i, Object obj) {
if ((i & 1) != 0) {
platform = companion.findPlatform();
}
companion.resetForTests(platform);
}
public final void resetForTests(Platform platform) {
C14957gcv.e(platform, "");
Platform.platform = platform;
}
public final List<String> alpnProtocolNames(List<? extends Protocol> list) {
C14957gcv.e(list, "");
ArrayList arrayList = new ArrayList();
for (Object obj : list) {
if (((Protocol) obj) != Protocol.HTTP_1_0) {
arrayList.add(obj);
}
}
ArrayList arrayList2 = arrayList;
C14957gcv.e(arrayList2, "");
ArrayList arrayList3 = new ArrayList(arrayList2.size());
Iterator it = arrayList2.iterator();
while (it.hasNext()) {
arrayList3.add(((Protocol) it.next()).toString());
}
return arrayList3;
}
public final boolean isAndroid() {
return C14957gcv.b((Object) "Dalvik", (Object) System.getProperty("java.vm.name"));
}
private final boolean isConscryptPreferred() {
return C14957gcv.b((Object) "Conscrypt", (Object) Security.getProviders()[0].getName());
}
private final boolean isOpenJSSEPreferred() {
return C14957gcv.b((Object) "OpenJSSE", (Object) Security.getProviders()[0].getName());
}
private final boolean isBouncyCastlePreferred() {
return C14957gcv.b((Object) BouncyCastleProvider.PROVIDER_NAME, (Object) Security.getProviders()[0].getName());
}
/* JADX INFO: Access modifiers changed from: private */
public final Platform findPlatform() {
if (isAndroid()) {
return findAndroidPlatform();
}
return findJvmPlatform();
}
private final Platform findAndroidPlatform() {
AndroidLog.INSTANCE.enable();
Platform buildIfSupported = Android10Platform.Companion.buildIfSupported();
if (buildIfSupported != null) {
return buildIfSupported;
}
Platform buildIfSupported2 = AndroidPlatform.Companion.buildIfSupported();
C14957gcv.e(buildIfSupported2);
return buildIfSupported2;
}
private final Platform findJvmPlatform() {
OpenJSSEPlatform buildIfSupported;
BouncyCastlePlatform buildIfSupported2;
ConscryptPlatform buildIfSupported3;
if (isConscryptPreferred() && (buildIfSupported3 = ConscryptPlatform.Companion.buildIfSupported()) != null) {
return buildIfSupported3;
}
if (isBouncyCastlePreferred() && (buildIfSupported2 = BouncyCastlePlatform.Companion.buildIfSupported()) != null) {
return buildIfSupported2;
}
if (isOpenJSSEPreferred() && (buildIfSupported = OpenJSSEPlatform.Companion.buildIfSupported()) != null) {
return buildIfSupported;
}
Jdk9Platform buildIfSupported4 = Jdk9Platform.Companion.buildIfSupported();
if (buildIfSupported4 != null) {
return buildIfSupported4;
}
Platform buildIfSupported5 = Jdk8WithJettyBootPlatform.Companion.buildIfSupported();
return buildIfSupported5 != null ? buildIfSupported5 : new Platform();
}
public final byte[] concatLengthPrefixed(List<? extends Protocol> list) {
C14957gcv.e(list, "");
C15111ghZ c15111ghZ = new C15111ghZ();
for (String str : alpnProtocolNames(list)) {
c15111ghZ.b(str.length());
C14957gcv.e(str, "");
c15111ghZ.c(str, 0, str.length());
}
return c15111ghZ.e(c15111ghZ.c);
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
Companion companion = new Companion(null);
Companion = companion;
platform = companion.findPlatform();
logger = Logger.getLogger(OkHttpClient.class.getName());
}
public boolean isCleartextTrafficPermitted(String str) {
C14957gcv.e(str, "");
return true;
}
public String getSelectedProtocol(SSLSocket sSLSocket) {
C14957gcv.e(sSLSocket, "");
return null;
}
public final String getPrefix() {
return "OkHttp";
}
public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
C14957gcv.e(sSLSocket, "");
C14957gcv.e(list, "");
}
public void afterHandshake(SSLSocket sSLSocket) {
C14957gcv.e(sSLSocket, "");
}
public static final Platform get() {
return Companion.get();
}
}