164 lines
6.5 KiB
Java
164 lines
6.5 KiB
Java
package okhttp3.internal.platform.android;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.util.List;
|
|
import javax.net.ssl.SSLSocket;
|
|
import javax.net.ssl.SSLSocketFactory;
|
|
import javax.net.ssl.X509TrustManager;
|
|
import o.C14953gcr;
|
|
import o.C14957gcv;
|
|
import o.gdP;
|
|
import o.gdZ;
|
|
import okhttp3.Protocol;
|
|
import okhttp3.internal.platform.AndroidPlatform;
|
|
import okhttp3.internal.platform.Platform;
|
|
import okhttp3.internal.platform.android.DeferredSocketAdapter;
|
|
import okhttp3.internal.platform.android.SocketAdapter;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class AndroidSocketAdapter implements SocketAdapter {
|
|
public static final Companion Companion;
|
|
private static final DeferredSocketAdapter.Factory playProviderFactory;
|
|
private final Method getAlpnSelectedProtocol;
|
|
private final Method setAlpnProtocols;
|
|
private final Method setHostname;
|
|
private final Method setUseSessionTickets;
|
|
private final Class<? super SSLSocket> sslSocketClass;
|
|
|
|
public AndroidSocketAdapter(Class<? super SSLSocket> cls) {
|
|
C14957gcv.e(cls, "");
|
|
this.sslSocketClass = cls;
|
|
Method declaredMethod = cls.getDeclaredMethod("setUseSessionTickets", Boolean.TYPE);
|
|
C14957gcv.c(declaredMethod, "");
|
|
this.setUseSessionTickets = declaredMethod;
|
|
this.setHostname = cls.getMethod("setHostname", String.class);
|
|
this.getAlpnSelectedProtocol = cls.getMethod("getAlpnSelectedProtocol", new Class[0]);
|
|
this.setAlpnProtocols = cls.getMethod("setAlpnProtocols", byte[].class);
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.SocketAdapter
|
|
public boolean matchesSocketFactory(SSLSocketFactory sSLSocketFactory) {
|
|
return SocketAdapter.DefaultImpls.matchesSocketFactory(this, sSLSocketFactory);
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.SocketAdapter
|
|
public X509TrustManager trustManager(SSLSocketFactory sSLSocketFactory) {
|
|
return SocketAdapter.DefaultImpls.trustManager(this, sSLSocketFactory);
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.SocketAdapter
|
|
public boolean isSupported() {
|
|
return AndroidPlatform.Companion.isSupported();
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.SocketAdapter
|
|
public boolean matchesSocket(SSLSocket sSLSocket) {
|
|
C14957gcv.e(sSLSocket, "");
|
|
return this.sslSocketClass.isInstance(sSLSocket);
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.SocketAdapter
|
|
public void configureTlsExtensions(SSLSocket sSLSocket, String str, List<? extends Protocol> list) {
|
|
C14957gcv.e(sSLSocket, "");
|
|
C14957gcv.e(list, "");
|
|
if (matchesSocket(sSLSocket)) {
|
|
try {
|
|
this.setUseSessionTickets.invoke(sSLSocket, Boolean.TRUE);
|
|
if (str != null) {
|
|
this.setHostname.invoke(sSLSocket, str);
|
|
}
|
|
this.setAlpnProtocols.invoke(sSLSocket, Platform.Companion.concatLengthPrefixed(list));
|
|
} catch (IllegalAccessException e) {
|
|
throw new AssertionError(e);
|
|
} catch (InvocationTargetException e2) {
|
|
throw new AssertionError(e2);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.SocketAdapter
|
|
public String getSelectedProtocol(SSLSocket sSLSocket) {
|
|
C14957gcv.e(sSLSocket, "");
|
|
if (!matchesSocket(sSLSocket)) {
|
|
return null;
|
|
}
|
|
try {
|
|
byte[] bArr = (byte[]) this.getAlpnSelectedProtocol.invoke(sSLSocket, new Object[0]);
|
|
if (bArr == null) {
|
|
return null;
|
|
}
|
|
return new String(bArr, gdP.a);
|
|
} catch (IllegalAccessException e) {
|
|
throw new AssertionError(e);
|
|
} catch (InvocationTargetException e2) {
|
|
Throwable cause = e2.getCause();
|
|
if ((cause instanceof NullPointerException) && C14957gcv.b((Object) ((NullPointerException) cause).getMessage(), (Object) "ssl == null")) {
|
|
return null;
|
|
}
|
|
throw new AssertionError(e2);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public final DeferredSocketAdapter.Factory getPlayProviderFactory() {
|
|
return AndroidSocketAdapter.playProviderFactory;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final AndroidSocketAdapter build(Class<? super SSLSocket> cls) {
|
|
Class<? super SSLSocket> cls2 = cls;
|
|
while (cls2 != null && !C14957gcv.b((Object) cls2.getSimpleName(), (Object) "OpenSSLSocketImpl")) {
|
|
cls2 = cls2.getSuperclass();
|
|
if (cls2 == null) {
|
|
throw new AssertionError(C14957gcv.c("No OpenSSLSocketImpl superclass of socket of type ", cls));
|
|
}
|
|
}
|
|
C14957gcv.e(cls2);
|
|
return new AndroidSocketAdapter(cls2);
|
|
}
|
|
|
|
public final DeferredSocketAdapter.Factory factory(final String str) {
|
|
C14957gcv.e(str, "");
|
|
return new DeferredSocketAdapter.Factory(str) { // from class: okhttp3.internal.platform.android.AndroidSocketAdapter$Companion$factory$1
|
|
final String $packageName;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
{
|
|
this.$packageName = str;
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.DeferredSocketAdapter.Factory
|
|
public final boolean matchesSocket(SSLSocket sSLSocket) {
|
|
C14957gcv.e(sSLSocket, "");
|
|
String name = sSLSocket.getClass().getName();
|
|
C14957gcv.c((Object) name, "");
|
|
return gdZ.e(name, C14957gcv.c(this.$packageName, (Object) "."), false);
|
|
}
|
|
|
|
@Override // okhttp3.internal.platform.android.DeferredSocketAdapter.Factory
|
|
public final SocketAdapter create(SSLSocket sSLSocket) {
|
|
AndroidSocketAdapter build;
|
|
C14957gcv.e(sSLSocket, "");
|
|
build = AndroidSocketAdapter.Companion.build(sSLSocket.getClass());
|
|
return build;
|
|
}
|
|
};
|
|
}
|
|
|
|
public /* synthetic */ Companion(C14953gcr c14953gcr) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
static {
|
|
Companion companion = new Companion(null);
|
|
Companion = companion;
|
|
playProviderFactory = companion.factory("com.google.android.gms.org.conscrypt");
|
|
}
|
|
}
|