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

132 lines
5.0 KiB
Java

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.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.bouncycastle.jsse.BCSSLParameters;
import org.bouncycastle.jsse.BCSSLSocket;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
/* loaded from: classes.dex */
public final class BouncyCastlePlatform extends Platform {
public static final Companion Companion;
private static final boolean isSupported;
private final Provider provider;
private BouncyCastlePlatform() {
this.provider = new BouncyCastleJsseProvider();
}
@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("PKIX", "BCJSSE");
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(javax.net.ssl.SSLSocketFactory sSLSocketFactory) {
C14957gcv.e(sSLSocketFactory, "");
throw new UnsupportedOperationException("clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with BouncyCastle");
}
@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 BCSSLSocket) {
BCSSLSocket bCSSLSocket = (BCSSLSocket) sSLSocket;
BCSSLParameters parameters = bCSSLSocket.getParameters();
Object[] array = Platform.Companion.alpnProtocolNames(list).toArray(new String[0]);
if (array != null) {
parameters.setApplicationProtocols((String[]) array);
bCSSLSocket.setParameters(parameters);
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 (sSLSocket instanceof BCSSLSocket) {
String applicationProtocol = ((BCSSLSocket) 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 BouncyCastlePlatform.isSupported;
}
public final BouncyCastlePlatform buildIfSupported() {
C14953gcr c14953gcr = null;
if (isSupported()) {
return new BouncyCastlePlatform(c14953gcr);
}
return null;
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
Companion companion = new Companion(null);
Companion = companion;
boolean z = false;
try {
Class.forName("org.bouncycastle.jsse.provider.BouncyCastleJsseProvider", false, companion.getClass().getClassLoader());
z = true;
} catch (ClassNotFoundException unused) {
}
isSupported = z;
}
public /* synthetic */ BouncyCastlePlatform(C14953gcr c14953gcr) {
this();
}
}