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

176 lines
6.5 KiB
Java

package okhttp3.internal.platform;
import java.security.KeyStore;
import java.security.Provider;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
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 okhttp3.Protocol;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.conscrypt.Conscrypt;
import org.conscrypt.ConscryptHostnameVerifier;
/* loaded from: classes.dex */
public final class ConscryptPlatform extends Platform {
public static final Companion Companion;
private static final boolean isSupported;
private final Provider provider;
private ConscryptPlatform() {
Provider newProvider = Conscrypt.newProvider();
C14957gcv.c(newProvider, "");
this.provider = newProvider;
}
@Override // okhttp3.internal.platform.Platform
public final SSLContext newSSLContext() {
SSLContext sSLContext = SSLContext.getInstance(SSLSocketFactory.TLS, this.provider);
C14957gcv.c(sSLContext, "");
return sSLContext;
}
@Override // okhttp3.internal.platform.Platform
public final 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) {
X509TrustManager x509TrustManager = (X509TrustManager) trustManager;
Conscrypt.setHostnameVerifier(x509TrustManager, DisabledHostnameVerifier.INSTANCE);
return x509TrustManager;
}
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());
}
/* loaded from: classes.dex */
public static final class DisabledHostnameVerifier implements ConscryptHostnameVerifier {
public static final DisabledHostnameVerifier INSTANCE = new DisabledHostnameVerifier();
public final boolean verify(String str, SSLSession sSLSession) {
return true;
}
public final boolean verify(X509Certificate[] x509CertificateArr, String str, SSLSession sSLSession) {
return true;
}
private DisabledHostnameVerifier() {
}
}
@Override // okhttp3.internal.platform.Platform
public final void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
C14957gcv.e(sSLSocket, "");
C14957gcv.e(list, "");
if (Conscrypt.isConscrypt(sSLSocket)) {
Conscrypt.setUseSessionTickets(sSLSocket, true);
Object[] array = Platform.Companion.alpnProtocolNames(list).toArray(new String[0]);
if (array != null) {
Conscrypt.setApplicationProtocols(sSLSocket, (String[]) array);
return;
}
throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
}
super.configureTlsExtensions(sSLSocket, str, list);
}
@Override // okhttp3.internal.platform.Platform
public final String getSelectedProtocol(SSLSocket sSLSocket) {
C14957gcv.e(sSLSocket, "");
if (Conscrypt.isConscrypt(sSLSocket)) {
return Conscrypt.getApplicationProtocol(sSLSocket);
}
return super.getSelectedProtocol(sSLSocket);
}
@Override // okhttp3.internal.platform.Platform
public final javax.net.ssl.SSLSocketFactory newSslSocketFactory(X509TrustManager x509TrustManager) {
C14957gcv.e(x509TrustManager, "");
SSLContext newSSLContext = newSSLContext();
newSSLContext.init(null, new TrustManager[]{x509TrustManager}, null);
javax.net.ssl.SSLSocketFactory socketFactory = newSSLContext.getSocketFactory();
C14957gcv.c(socketFactory, "");
return socketFactory;
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
public final boolean isSupported() {
return ConscryptPlatform.isSupported;
}
public final ConscryptPlatform buildIfSupported() {
C14953gcr c14953gcr = null;
if (isSupported()) {
return new ConscryptPlatform(c14953gcr);
}
return null;
}
public static /* synthetic */ boolean atLeastVersion$default(Companion companion, int i, int i2, int i3, int i4, Object obj) {
if ((i4 & 2) != 0) {
i2 = 0;
}
if ((i4 & 4) != 0) {
i3 = 0;
}
return companion.atLeastVersion(i, i2, i3);
}
public final boolean atLeastVersion(int i, int i2, int i3) {
Conscrypt.Version version = Conscrypt.version();
return version.major() != i ? version.major() > i : version.minor() != i2 ? version.minor() > i2 : version.patch() >= i3;
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
Companion companion = new Companion(null);
Companion = companion;
boolean z = false;
try {
Class.forName("org.conscrypt.Conscrypt$Version", false, companion.getClass().getClassLoader());
if (Conscrypt.isAvailable()) {
if (companion.atLeastVersion(2, 1, 0)) {
z = true;
}
}
} catch (ClassNotFoundException | NoClassDefFoundError unused) {
}
isSupported = z;
}
@Override // okhttp3.internal.platform.Platform
public final X509TrustManager trustManager(javax.net.ssl.SSLSocketFactory sSLSocketFactory) {
C14957gcv.e(sSLSocketFactory, "");
return null;
}
public /* synthetic */ ConscryptPlatform(C14953gcr c14953gcr) {
this();
}
}