Rabbit-R1/android (non root)/java/sources/okhttp3/internal/platform/BouncyCastlePlatform.java
2024-05-21 17:08:36 -04:00

140 lines
7.8 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.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import okhttp3.Protocol;
import org.bouncycastle.jsse.BCSSLParameters;
import org.bouncycastle.jsse.BCSSLSocket;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
/* compiled from: BouncyCastlePlatform.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000J\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\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\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0018\u0000 \u00172\u00020\u0001:\u0001\u0017B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J-\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\b\u0010\t\u001a\u0004\u0018\u00010\n2\u0011\u0010\u000b\u001a\r\u0012\t\u0012\u00070\\u0006\u0002\b\u000e0\fH\u0016J\u0012\u0010\u000f\u001a\u0004\u0018\u00010\n2\u0006\u0010\u0007\u001a\u00020\bH\u0016J\b\u0010\u0010\u001a\u00020\u0011H\u0016J\b\u0010\u0012\u001a\u00020\u0013H\u0016J\u0012\u0010\u0014\u001a\u0004\u0018\u00010\u00132\u0006\u0010\u0015\u001a\u00020\u0016H\u0016R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0018"}, d2 = {"Lokhttp3/internal/platform/BouncyCastlePlatform;", "Lokhttp3/internal/platform/Platform;", "()V", "provider", "Ljava/security/Provider;", "configureTlsExtensions", "", "sslSocket", "Ljavax/net/ssl/SSLSocket;", "hostname", "", "protocols", "", "Lokhttp3/Protocol;", "Lkotlin/jvm/JvmSuppressWildcards;", "getSelectedProtocol", "newSSLContext", "Ljavax/net/ssl/SSLContext;", "platformTrustManager", "Ljavax/net/ssl/X509TrustManager;", "trustManager", "sslSocketFactory", "Ljavax/net/ssl/SSLSocketFactory;", "Companion", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class BouncyCastlePlatform extends Platform {
/* renamed from: Companion, reason: from kotlin metadata */
public static final Companion INSTANCE;
private static final boolean isSupported;
private final Provider provider;
private BouncyCastlePlatform() {
this.provider = new BouncyCastleJsseProvider();
}
public /* synthetic */ BouncyCastlePlatform(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
@Override // okhttp3.internal.platform.Platform
public SSLContext newSSLContext() {
SSLContext sSLContext = SSLContext.getInstance("TLS", this.provider);
Intrinsics.checkNotNullExpressionValue(sSLContext, "SSLContext.getInstance(\"TLS\", provider)");
return sSLContext;
}
@Override // okhttp3.internal.platform.Platform
public X509TrustManager platformTrustManager() {
TrustManagerFactory factory = TrustManagerFactory.getInstance("PKIX", "BCJSSE");
factory.init((KeyStore) null);
Intrinsics.checkNotNullExpressionValue(factory, "factory");
TrustManager[] trustManagers = factory.getTrustManagers();
Intrinsics.checkNotNull(trustManagers);
if (!(trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager))) {
StringBuilder sb = new StringBuilder("Unexpected default trust managers: ");
String arrays = Arrays.toString(trustManagers);
Intrinsics.checkNotNullExpressionValue(arrays, "java.util.Arrays.toString(this)");
throw new IllegalStateException(sb.append(arrays).toString().toString());
}
TrustManager trustManager = trustManagers[0];
if (trustManager != null) {
return (X509TrustManager) trustManager;
}
throw new NullPointerException("null cannot be cast to non-null type javax.net.ssl.X509TrustManager");
}
@Override // okhttp3.internal.platform.Platform
public X509TrustManager trustManager(SSLSocketFactory sslSocketFactory) {
Intrinsics.checkNotNullParameter(sslSocketFactory, "sslSocketFactory");
throw new UnsupportedOperationException("clientBuilder.sslSocketFactory(SSLSocketFactory) not supported with BouncyCastle");
}
@Override // okhttp3.internal.platform.Platform
public void configureTlsExtensions(SSLSocket sslSocket, String hostname, List<Protocol> protocols) {
Intrinsics.checkNotNullParameter(sslSocket, "sslSocket");
Intrinsics.checkNotNullParameter(protocols, "protocols");
if (sslSocket instanceof BCSSLSocket) {
BCSSLSocket bCSSLSocket = (BCSSLSocket) sslSocket;
BCSSLParameters sslParameters = bCSSLSocket.getParameters();
List<String> alpnProtocolNames = Platform.INSTANCE.alpnProtocolNames(protocols);
Intrinsics.checkNotNullExpressionValue(sslParameters, "sslParameters");
Object[] array = alpnProtocolNames.toArray(new String[0]);
if (array != null) {
sslParameters.setApplicationProtocols((String[]) array);
bCSSLSocket.setParameters(sslParameters);
return;
}
throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T>");
}
super.configureTlsExtensions(sslSocket, hostname, protocols);
}
@Override // okhttp3.internal.platform.Platform
public String getSelectedProtocol(SSLSocket sslSocket) {
Intrinsics.checkNotNullParameter(sslSocket, "sslSocket");
if (sslSocket instanceof BCSSLSocket) {
String applicationProtocol = ((BCSSLSocket) sslSocket).getApplicationProtocol();
if (applicationProtocol == null || (applicationProtocol.hashCode() == 0 && applicationProtocol.equals(""))) {
return null;
}
return applicationProtocol;
}
return super.getSelectedProtocol(sslSocket);
}
/* compiled from: BouncyCastlePlatform.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\b\u0010\u0006\u001a\u0004\u0018\u00010\u0007R\u0011\u0010\u0003\u001a\u00020\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0003\u0010\u0005¨\u0006\b"}, d2 = {"Lokhttp3/internal/platform/BouncyCastlePlatform$Companion;", "", "()V", "isSupported", "", "()Z", "buildIfSupported", "Lokhttp3/internal/platform/BouncyCastlePlatform;", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final boolean isSupported() {
return BouncyCastlePlatform.isSupported;
}
public final BouncyCastlePlatform buildIfSupported() {
DefaultConstructorMarker defaultConstructorMarker = null;
if (isSupported()) {
return new BouncyCastlePlatform(defaultConstructorMarker);
}
return null;
}
}
static {
Companion companion = new Companion(null);
INSTANCE = companion;
boolean z = false;
try {
Class.forName("org.bouncycastle.jsse.provider.BouncyCastleJsseProvider", false, companion.getClass().getClassLoader());
z = true;
} catch (ClassNotFoundException unused) {
}
isSupported = z;
}
}