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

135 lines
5.1 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.internal.platform;
import java.security.KeyStore;
import java.security.Provider;
import java.util.Arrays;
import java.util.List;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
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.openjsse.javax.net.ssl.SSLParameters;
import org.openjsse.net.ssl.OpenJSSE;
/* loaded from: classes.dex */
public final class OpenJSSEPlatform extends Platform {
public static final Companion Companion;
private static final boolean isSupported;
private final Provider provider;
private OpenJSSEPlatform() {
this.provider = new OpenJSSE();
}
@Override // okhttp3.internal.platform.Platform
public final SSLContext newSSLContext() {
SSLContext sSLContext = SSLContext.getInstance("TLSv1.3", this.provider);
C14957gcv.c(sSLContext, "");
return sSLContext;
}
@Override // okhttp3.internal.platform.Platform
public final X509TrustManager platformTrustManager() {
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm(), this.provider);
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());
}
@Override // okhttp3.internal.platform.Platform
public final X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) {
C14957gcv.e(sSLSocketFactory, "");
throw new UnsupportedOperationException("clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with OpenJSSE");
}
@Override // okhttp3.internal.platform.Platform
public final void configureTlsExtensions(SSLSocket sSLSocket, String str, List<Protocol> list) {
C14957gcv.e(sSLSocket, "");
C14957gcv.e(list, "");
if (sSLSocket instanceof org.openjsse.javax.net.ssl.SSLSocket) {
org.openjsse.javax.net.ssl.SSLSocket sSLSocket2 = (org.openjsse.javax.net.ssl.SSLSocket) sSLSocket;
SSLParameters sSLParameters = sSLSocket2.getSSLParameters();
if (sSLParameters instanceof SSLParameters) {
SSLParameters sSLParameters2 = sSLParameters;
Object[] array = Platform.Companion.alpnProtocolNames(list).toArray(new String[0]);
if (array != null) {
sSLParameters2.setApplicationProtocols((String[]) array);
sSLSocket2.setSSLParameters(sSLParameters);
return;
}
throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
}
return;
}
super.configureTlsExtensions(sSLSocket, str, list);
}
@Override // okhttp3.internal.platform.Platform
public final String getSelectedProtocol(SSLSocket sSLSocket) {
C14957gcv.e(sSLSocket, "");
if (sSLSocket instanceof org.openjsse.javax.net.ssl.SSLSocket) {
String applicationProtocol = ((org.openjsse.javax.net.ssl.SSLSocket) sSLSocket).getApplicationProtocol();
if (applicationProtocol == null || C14957gcv.b((Object) applicationProtocol, (Object) "")) {
return null;
}
return applicationProtocol;
}
return super.getSelectedProtocol(sSLSocket);
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
public final boolean isSupported() {
return OpenJSSEPlatform.isSupported;
}
public final OpenJSSEPlatform buildIfSupported() {
C14953gcr c14953gcr = null;
if (isSupported()) {
return new OpenJSSEPlatform(c14953gcr);
}
return null;
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
Companion companion = new Companion(null);
Companion = companion;
boolean z = false;
try {
Class.forName("org.openjsse.net.ssl.OpenJSSE", false, companion.getClass().getClassLoader());
z = true;
} catch (ClassNotFoundException unused) {
}
isSupported = z;
}
public /* synthetic */ OpenJSSEPlatform(C14953gcr c14953gcr) {
this();
}
}