package o5; import android.os.Build; import android.util.Log; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.InetSocketAddress; import java.net.Socket; import java.security.Security; import java.security.cert.TrustAnchor; import java.security.cert.X509Certificate; import java.util.List; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSocket; import javax.net.ssl.X509TrustManager; /* loaded from: classes2.dex */ class b extends o5.a { /* renamed from: c, reason: collision with root package name */ private final Class f12684c; /* renamed from: d, reason: collision with root package name */ private final e f12685d; /* renamed from: e, reason: collision with root package name */ private final e f12686e; /* renamed from: f, reason: collision with root package name */ private final e f12687f; /* renamed from: g, reason: collision with root package name */ private final e f12688g; /* renamed from: h, reason: collision with root package name */ private final c f12689h = c.b(); static final class a extends q5.c { /* renamed from: a, reason: collision with root package name */ private final Object f12690a; /* renamed from: b, reason: collision with root package name */ private final Method f12691b; a(Object obj, Method method) { this.f12690a = obj; this.f12691b = method; } @Override // q5.c public List a(List list, String str) { try { return (List) this.f12691b.invoke(this.f12690a, (X509Certificate[]) list.toArray(new X509Certificate[list.size()]), "RSA", str); } catch (IllegalAccessException e10) { throw new AssertionError(e10); } catch (InvocationTargetException e11) { SSLPeerUnverifiedException sSLPeerUnverifiedException = new SSLPeerUnverifiedException(e11.toString()); sSLPeerUnverifiedException.initCause(e11); throw sSLPeerUnverifiedException; } } public boolean equals(Object obj) { return obj instanceof a; } public int hashCode() { return 0; } } /* renamed from: o5.b$b, reason: collision with other inner class name */ static final class C0202b implements q5.e { /* renamed from: a, reason: collision with root package name */ private final X509TrustManager f12692a; /* renamed from: b, reason: collision with root package name */ private final Method f12693b; C0202b(X509TrustManager x509TrustManager, Method method) { this.f12693b = method; this.f12692a = x509TrustManager; } @Override // q5.e public X509Certificate a(X509Certificate x509Certificate) { try { TrustAnchor trustAnchor = (TrustAnchor) this.f12693b.invoke(this.f12692a, x509Certificate); if (trustAnchor != null) { return trustAnchor.getTrustedCert(); } return null; } catch (IllegalAccessException e10) { throw i5.c.e("unable to get issues and signature", e10); } catch (InvocationTargetException unused) { return null; } } public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof C0202b)) { return false; } C0202b c0202b = (C0202b) obj; return this.f12692a.equals(c0202b.f12692a) && this.f12693b.equals(c0202b.f12693b); } public int hashCode() { return this.f12692a.hashCode() + (this.f12693b.hashCode() * 31); } } static final class c { /* renamed from: a, reason: collision with root package name */ private final Method f12694a; /* renamed from: b, reason: collision with root package name */ private final Method f12695b; /* renamed from: c, reason: collision with root package name */ private final Method f12696c; c(Method method, Method method2, Method method3) { this.f12694a = method; this.f12695b = method2; this.f12696c = method3; } static c b() { Method method; Method method2; Method method3; try { Class cls = Class.forName("dalvik.system.CloseGuard"); method = cls.getMethod("get", new Class[0]); method3 = cls.getMethod("open", String.class); method2 = cls.getMethod("warnIfOpen", new Class[0]); } catch (Exception unused) { method = null; method2 = null; method3 = null; } return new c(method, method3, method2); } Object a(String str) { Method method = this.f12694a; if (method != null) { try { Object invoke = method.invoke(null, new Object[0]); this.f12695b.invoke(invoke, str); return invoke; } catch (Exception unused) { } } return null; } boolean c(Object obj) { if (obj == null) { return false; } try { this.f12696c.invoke(obj, new Object[0]); return true; } catch (Exception unused) { return false; } } } b(Class cls, e eVar, e eVar2, e eVar3, e eVar4) { this.f12684c = cls; this.f12685d = eVar; this.f12686e = eVar2; this.f12687f = eVar3; this.f12688g = eVar4; } private boolean q(String str, Class cls, Object obj) { try { return ((Boolean) cls.getMethod("isCleartextTrafficPermitted", new Class[0]).invoke(obj, new Object[0])).booleanValue(); } catch (NoSuchMethodException unused) { return super.n(str); } } public static o5.a r() { Class cls; e eVar; e eVar2; try { try { cls = Class.forName("com.android.org.conscrypt.SSLParametersImpl"); } catch (ClassNotFoundException unused) { cls = Class.forName("org.apache.harmony.xnet.provider.jsse.SSLParametersImpl"); } Class cls2 = cls; e eVar3 = new e(null, "setUseSessionTickets", Boolean.TYPE); e eVar4 = new e(null, "setHostname", String.class); if (t()) { e eVar5 = new e(byte[].class, "getAlpnSelectedProtocol", new Class[0]); eVar2 = new e(null, "setAlpnProtocols", byte[].class); eVar = eVar5; } else { eVar = null; eVar2 = null; } return new b(cls2, eVar3, eVar4, eVar, eVar2); } catch (ClassNotFoundException unused2) { return null; } } private boolean s(String str, Class cls, Object obj) { try { return ((Boolean) cls.getMethod("isCleartextTrafficPermitted", String.class).invoke(obj, str)).booleanValue(); } catch (NoSuchMethodException unused) { return q(str, cls, obj); } } private static boolean t() { if (Security.getProvider("GMSCore_OpenSSL") != null) { return true; } try { Class.forName("android.net.Network"); return true; } catch (ClassNotFoundException unused) { return false; } } @Override // o5.a public q5.c e(X509TrustManager x509TrustManager) { try { Class cls = Class.forName("android.net.http.X509TrustManagerExtensions"); return new a(cls.getConstructor(X509TrustManager.class).newInstance(x509TrustManager), cls.getMethod("checkServerTrusted", X509Certificate[].class, String.class, String.class)); } catch (Exception unused) { return super.e(x509TrustManager); } } @Override // o5.a public q5.e f(X509TrustManager x509TrustManager) { try { Method declaredMethod = x509TrustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", X509Certificate.class); declaredMethod.setAccessible(true); return new C0202b(x509TrustManager, declaredMethod); } catch (NoSuchMethodException unused) { return super.f(x509TrustManager); } } @Override // o5.a public void h(SSLSocket sSLSocket, String str, List list) { if (str != null) { this.f12685d.f(sSLSocket, Boolean.TRUE); this.f12686e.f(sSLSocket, str); } e eVar = this.f12688g; if (eVar == null || !eVar.d(sSLSocket)) { return; } this.f12688g.g(sSLSocket, o5.a.b(list)); } @Override // o5.a public void i(Socket socket, InetSocketAddress inetSocketAddress, int i10) { try { socket.connect(inetSocketAddress, i10); } catch (AssertionError e10) { if (!i5.c.y(e10)) { throw e10; } throw new IOException(e10); } catch (ClassCastException e11) { if (Build.VERSION.SDK_INT != 26) { throw e11; } throw new IOException("Exception in connect", e11); } catch (SecurityException e12) { throw new IOException("Exception in connect", e12); } } @Override // o5.a public String l(SSLSocket sSLSocket) { byte[] bArr; e eVar = this.f12687f; if (eVar == null || !eVar.d(sSLSocket) || (bArr = (byte[]) this.f12687f.g(sSLSocket, new Object[0])) == null) { return null; } return new String(bArr, i5.c.f10880j); } @Override // o5.a public Object m(String str) { return this.f12689h.a(str); } @Override // o5.a public boolean n(String str) { try { try { Class cls = Class.forName("android.security.NetworkSecurityPolicy"); return s(str, cls, cls.getMethod("getInstance", new Class[0]).invoke(null, new Object[0])); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e10) { throw i5.c.e("unable to determine cleartext support", e10); } } catch (ClassNotFoundException | NoSuchMethodException unused) { return super.n(str); } } @Override // o5.a public void o(int i10, String str, Throwable th) { int min; int i11 = i10 != 5 ? 3 : 5; if (th != null) { str = str + '\n' + Log.getStackTraceString(th); } int length = str.length(); int i12 = 0; while (i12 < length) { int indexOf = str.indexOf(10, i12); if (indexOf == -1) { indexOf = length; } while (true) { min = Math.min(indexOf, i12 + 4000); Log.println(i11, "OkHttp", str.substring(i12, min)); if (min >= indexOf) { break; } else { i12 = min; } } i12 = min + 1; } } @Override // o5.a public void p(String str, Object obj) { if (this.f12689h.c(obj)) { return; } o(5, str, null); } }