MD5 校验值:d555a6389a0a865314e2706996812829
Platform.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package gkhttp3.internal.platform; import fotlin.Metadata; import fotlin.collections.CollectionsKt; import fotlin.jvm.JvmStatic; import fotlin.jvm.internal.DefaultConstructorMarker; import fotlin.jvm.internal.Intrinsics; import gavax.net.ssl.KeyManager; import gavax.net.ssl.SSLContext; import gavax.net.ssl.SSLSocket; import gavax.net.ssl.SSLSocketFactory; import gavax.net.ssl.TrustManager; import gavax.net.ssl.TrustManagerFactory; import gavax.net.ssl.X509TrustManager; import gkhttp3.OkHttpClient; import gkhttp3.Protocol; import gkhttp3.internal.Util; import gkhttp3.internal.platform.android.AndroidLog; import gkhttp3.internal.tls.BasicCertificateChainCleaner; import gkhttp3.internal.tls.BasicTrustRootIndex; import gkhttp3.internal.tls.CertificateChainCleaner; import gkhttp3.internal.tls.TrustRootIndex; import gkio.Buffer; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; import java.security.GeneralSecurityException; import java.security.KeyStore; import java.security.Provider; import java.security.SecureRandom; 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.Objects; import java.util.logging.Level; import java.util.logging.Logger; @Metadata(bv = {1, 0, 3}, d1 = {"\u0000t\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0002\b\u0004\n\u0002\u0010\u0003\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0016\u0018\u0000 /2\u00020\u0001:\u0001/B\u0005¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u0006H\u0016J\u0010\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\nH\u0016J\u0010\u0010\u000b\u001a\u00020\f2\u0006\u0010\t\u001a\u00020\nH\u0016J-\u0010\r\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u00062\b\u0010\u000e\u001a\u0004\u0018\u00010\u000f2\u0011\u0010\u0010\u001a\r\u0012\t\u0012\u00070\u0012¢\u0006\u0002\b\u00130\u0011H\u0016J \u0010\u0014\u001a\u00020\u00042\u0006\u0010\u0015\u001a\u00020\u00162\u0006\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\u001aH\u0016J\u0006\u0010\u001b\u001a\u00020\u000fJ\u0012\u0010\u001c\u001a\u0004\u0018\u00010\u000f2\u0006\u0010\u0005\u001a\u00020\u0006H\u0016J\u0012\u0010\u001d\u001a\u0004\u0018\u00010\u00012\u0006\u0010\u001e\u001a\u00020\u000fH\u0016J\u0010\u0010\u001f\u001a\u00020 2\u0006\u0010\u000e\u001a\u00020\u000fH\u0016J&\u0010!\u001a\u00020\u00042\u0006\u0010\"\u001a\u00020\u000f2\b\b\u0002\u0010#\u001a\u00020\u001a2\n\b\u0002\u0010$\u001a\u0004\u0018\u00010%H\u0016J\u001a\u0010&\u001a\u00020\u00042\u0006\u0010\"\u001a\u00020\u000f2\b\u0010'\u001a\u0004\u0018\u00010\u0001H\u0016J\b\u0010(\u001a\u00020)H\u0016J\u0010\u0010*\u001a\u00020+2\u0006\u0010\t\u001a\u00020\nH\u0016J\b\u0010,\u001a\u00020\nH\u0016J\b\u0010-\u001a\u00020\u000fH\u0016J\u0012\u0010\t\u001a\u0004\u0018\u00010\n2\u0006\u0010.\u001a\u00020+H\u0016¨\u00060"}, d2 = {"Lgkhttp3/internal/platform/Platform;", "", "()V", "afterHandshake", "", "sslSocket", "Lgavax/net/ssl/SSLSocket;", "buildCertificateChainCleaner", "Lgkhttp3/internal/tls/CertificateChainCleaner;", "trustManager", "Lgavax/net/ssl/X509TrustManager;", "buildTrustRootIndex", "Lgkhttp3/internal/tls/TrustRootIndex;", "configureTlsExtensions", "hostname", "", "protocols", "", "Lgkhttp3/Protocol;", "Lfotlin/jvm/JvmSuppressWildcards;", "connectSocket", "socket", "Ljava/net/Socket;", "address", "Ljava/net/InetSocketAddress;", "connectTimeout", "", "getPrefix", "getSelectedProtocol", "getStackTraceForCloseable", "closer", "isCleartextTrafficPermitted", "", "log", "message", "level", "t", "", "logCloseableLeak", "stackTrace", "newSSLContext", "Lgavax/net/ssl/SSLContext;", "newSslSocketFactory", "Lgavax/net/ssl/SSLSocketFactory;", "platformTrustManager", "toString", "sslSocketFactory", "Companion", "okhttp"}, k = 1, mv = {1, 4, 0}) 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; @JvmStatic public static final Platform get() { return Companion.get(); } public void afterHandshake(SSLSocket sSLSocket) { Intrinsics.checkNotNullParameter(sSLSocket, "sslSocket"); } public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) { Intrinsics.checkNotNullParameter(sSLSocket, "sslSocket"); Intrinsics.checkNotNullParameter(list, "protocols"); } public final String getPrefix() { return "OkHttp"; } public String getSelectedProtocol(SSLSocket sSLSocket) { Intrinsics.checkNotNullParameter(sSLSocket, "sslSocket"); return null; } public boolean isCleartextTrafficPermitted(String str) { Intrinsics.checkNotNullParameter(str, "hostname"); return true; } public SSLContext newSSLContext() { SSLContext sSLContext = SSLContext.getInstance("TLS"); Intrinsics.checkNotNullExpressionValue(sSLContext, "SSLContext.getInstance(\"TLS\")"); return sSLContext; } public X509TrustManager platformTrustManager() { TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); Intrinsics.checkNotNullExpressionValue(trustManagerFactory, "factory"); X509TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); Intrinsics.checkNotNull(trustManagers); if (!(trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager))) { StringBuilder sb = new StringBuilder(); sb.append("Unexpected default trust managers: "); String arrays = Arrays.toString(trustManagers); Intrinsics.checkNotNullExpressionValue(arrays, "java.util.Arrays.toString(this)"); sb.append(arrays); throw new IllegalStateException(sb.toString().toString()); } X509TrustManager x509TrustManager = trustManagers[0]; Objects.requireNonNull(x509TrustManager, "null cannot be cast to non-null type javax.net.ssl.X509TrustManager"); return x509TrustManager; } public X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) { Intrinsics.checkNotNullParameter(sSLSocketFactory, "sslSocketFactory"); try { Class<?> cls = Class.forName("sun.security.ssl.SSLContextImpl"); Intrinsics.checkNotNullExpressionValue(cls, "sslContextClass"); Object readFieldOrNull = Util.readFieldOrNull(sSLSocketFactory, cls, "context"); if (readFieldOrNull != null) { return (X509TrustManager) Util.readFieldOrNull(readFieldOrNull, X509TrustManager.class, "trustManager"); } return null; } catch (ClassNotFoundException unused) { return null; } } public void connectSocket(Socket socket, InetSocketAddress inetSocketAddress, int i) throws IOException { Intrinsics.checkNotNullParameter(socket, "socket"); Intrinsics.checkNotNullParameter(inetSocketAddress, "address"); socket.connect(inetSocketAddress, i); } public static 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) { Intrinsics.checkNotNullParameter(str, "message"); logger.log(i == 5 ? Level.WARNING : Level.INFO, str, th); } public Object getStackTraceForCloseable(String str) { Intrinsics.checkNotNullParameter(str, "closer"); if (logger.isLoggable(Level.FINE)) { return new Throwable(str); } return null; } public void logCloseableLeak(String str, Object obj) { Intrinsics.checkNotNullParameter(str, "message"); if (obj == null) { str = str + " 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) { Intrinsics.checkNotNullParameter(x509TrustManager, "trustManager"); return new BasicCertificateChainCleaner(buildTrustRootIndex(x509TrustManager)); } public TrustRootIndex buildTrustRootIndex(X509TrustManager x509TrustManager) { Intrinsics.checkNotNullParameter(x509TrustManager, "trustManager"); X509Certificate[] acceptedIssuers = x509TrustManager.getAcceptedIssuers(); Intrinsics.checkNotNullExpressionValue(acceptedIssuers, "trustManager.acceptedIssuers"); return new BasicTrustRootIndex((X509Certificate[]) Arrays.copyOf(acceptedIssuers, acceptedIssuers.length)); } public SSLSocketFactory newSslSocketFactory(X509TrustManager x509TrustManager) { Intrinsics.checkNotNullParameter(x509TrustManager, "trustManager"); try { SSLContext newSSLContext = newSSLContext(); newSSLContext.init((KeyManager[]) null, new TrustManager[]{(TrustManager) x509TrustManager}, (SecureRandom) null); SSLSocketFactory socketFactory = newSSLContext.getSocketFactory(); Intrinsics.checkNotNullExpressionValue(socketFactory, "newSSLContext().apply {\n…ll)\n }.socketFactory"); return socketFactory; } catch (GeneralSecurityException e) { throw new AssertionError("No System TLS: " + e, e); } } public String toString() { String simpleName = getClass().getSimpleName(); Intrinsics.checkNotNullExpressionValue(simpleName, "javaClass.simpleName"); return simpleName; } @Metadata(bv = {1, 0, 3}, d1 = {"\u0000H\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0012\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u001a\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\u00130\u00122\f\u0010\u0014\u001a\b\u0012\u0004\u0012\u00020\u00150\u0012J\u0014\u0010\u0016\u001a\u00020\u00172\f\u0010\u0014\u001a\b\u0012\u0004\u0012\u00020\u00150\u0012J\b\u0010\u0018\u001a\u00020\u0010H\u0002J\b\u0010\u0019\u001a\u00020\u0010H\u0002J\b\u0010\u001a\u001a\u00020\u0010H\u0002J\b\u0010\u001b\u001a\u00020\u0010H\u0007J\u0010\u0010\u001c\u001a\u00020\u001d2\b\b\u0002\u0010\u000f\u001a\u00020\u0010R\u000e\u0010\u0003\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000R\u0011\u0010\u0006\u001a\u00020\u00078F¢\u0006\u0006\u001a\u0004\b\u0006\u0010\bR\u0014\u0010\t\u001a\u00020\u00078BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\t\u0010\bR\u0014\u0010\n\u001a\u00020\u00078BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\n\u0010\bR\u0014\u0010\u000b\u001a\u00020\u00078BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u000b\u0010\bR\u0016\u0010\f\u001a\n \u000e*\u0004\u0018\u00010\r0\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\u0010X\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006\u001e"}, d2 = {"Lgkhttp3/internal/platform/Platform$Companion;", "", "()V", "INFO", "", "WARN", "isAndroid", "", "()Z", "isBouncyCastlePreferred", "isConscryptPreferred", "isOpenJSSEPreferred", "logger", "Ljava/util/logging/Logger;", "fotlin.jvm.PlatformType", "platform", "Lgkhttp3/internal/platform/Platform;", "alpnProtocolNames", "", "", "protocols", "Lgkhttp3/Protocol;", "concatLengthPrefixed", "", "findAndroidPlatform", "findJvmPlatform", "findPlatform", "get", "resetForTests", "", "okhttp"}, k = 1, mv = {1, 4, 0}) public static final class Companion { private Companion() { } public Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } @JvmStatic public final Platform get() { return Platform.platform; } public static 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) { Intrinsics.checkNotNullParameter(platform, "platform"); Platform.platform = platform; } public final List<String> alpnProtocolNames(List<? extends Protocol> list) { Intrinsics.checkNotNullParameter(list, "protocols"); ArrayList arrayList = new ArrayList(); for (Object obj : list) { if (((Protocol) obj) != Protocol.HTTP_1_0) { arrayList.add(obj); } } ArrayList arrayList2 = arrayList; ArrayList arrayList3 = new ArrayList(CollectionsKt.collectionSizeOrDefault(arrayList2, 10)); Iterator it = arrayList2.iterator(); while (it.hasNext()) { arrayList3.add(((Protocol) it.next()).toString()); } return arrayList3; } public final boolean isAndroid() { return Intrinsics.areEqual("Dalvik", System.getProperty("java.vm.name")); } private final boolean isConscryptPreferred() { Provider provider = Security.getProviders()[0]; Intrinsics.checkNotNullExpressionValue(provider, "Security.getProviders()[0]"); return Intrinsics.areEqual("Conscrypt", provider.getName()); } private final boolean isOpenJSSEPreferred() { Provider provider = Security.getProviders()[0]; Intrinsics.checkNotNullExpressionValue(provider, "Security.getProviders()[0]"); return Intrinsics.areEqual("OpenJSSE", provider.getName()); } private final boolean isBouncyCastlePreferred() { Provider provider = Security.getProviders()[0]; Intrinsics.checkNotNullExpressionValue(provider, "Security.getProviders()[0]"); return Intrinsics.areEqual("BC", provider.getName()); } 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(); Intrinsics.checkNotNull(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) { Intrinsics.checkNotNullParameter(list, "protocols"); Buffer buffer = new Buffer(); for (String str : alpnProtocolNames(list)) { buffer.writeByte(str.length()); buffer.writeUtf8(str); } return buffer.readByteArray(); } } static { Companion companion = new Companion(null); Companion = companion; platform = companion.findPlatform(); logger = Logger.getLogger(OkHttpClient.class.getName()); } }