package k5; import com.google.android.gms.common.api.Api; import h5.b0; import h5.d0; import h5.f0; import h5.g0; import h5.h0; import h5.i; import h5.i0; import h5.j0; import h5.k; import h5.m; import h5.m0; import h5.n; import h5.o; import h5.o0; import h5.p0; import h5.t; import h5.z; import java.io.IOException; import java.net.ConnectException; import java.net.Proxy; import java.net.Socket; import java.net.SocketTimeoutException; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocket; import n5.f; /* loaded from: classes2.dex */ public final class c extends f.b implements m { /* renamed from: b, reason: collision with root package name */ private final n f11224b; /* renamed from: c, reason: collision with root package name */ private final m0 f11225c; /* renamed from: d, reason: collision with root package name */ private Socket f11226d; /* renamed from: e, reason: collision with root package name */ private Socket f11227e; /* renamed from: f, reason: collision with root package name */ private z f11228f; /* renamed from: g, reason: collision with root package name */ private j0 f11229g; /* renamed from: h, reason: collision with root package name */ private n5.f f11230h; /* renamed from: i, reason: collision with root package name */ private h5.f f11231i; /* renamed from: j, reason: collision with root package name */ private h5.e f11232j; /* renamed from: k, reason: collision with root package name */ public boolean f11233k; /* renamed from: l, reason: collision with root package name */ public int f11234l; /* renamed from: m, reason: collision with root package name */ public int f11235m = 1; /* renamed from: n, reason: collision with root package name */ public final List f11236n = new ArrayList(); /* renamed from: o, reason: collision with root package name */ public long f11237o = Long.MAX_VALUE; public c(n nVar, m0 m0Var) { this.f11224b = nVar; this.f11225c = m0Var; } private h0 c() { return new h0.a().h(this.f11225c.a().l()).c("Host", i5.c.s(this.f11225c.a().l(), true)).c("Proxy-Connection", "Keep-Alive").c("User-Agent", i5.d.a()).b(); } private h0 d(int i10, int i11, h0 h0Var, b0 b0Var) { String str = "CONNECT " + i5.c.s(b0Var, true) + " HTTP/1.1"; while (true) { m5.a aVar = new m5.a(null, null, this.f11231i, this.f11232j); TimeUnit timeUnit = TimeUnit.MILLISECONDS; this.f11231i.b().g(i10, timeUnit); this.f11232j.b().g(i11, timeUnit); aVar.o(h0Var.d(), str); aVar.a(); i0 e10 = aVar.b(false).o(h0Var).e(); long c10 = l5.e.c(e10); if (c10 == -1) { c10 = 0; } o0 l10 = aVar.l(c10); i5.c.A(l10, Api.BaseClientBuilder.API_PRIORITY_OTHER, timeUnit); l10.close(); int G = e10.G(); if (G == 200) { if (this.f11231i.a().g() && this.f11232j.a().g()) { return null; } throw new IOException("TLS tunnel buffered too many bytes!"); } if (G != 407) { throw new IOException("Unexpected mobonResponse code for CONNECT: " + e10.G()); } h0 a10 = this.f11225c.a().h().a(this.f11225c, e10); if (a10 == null) { throw new IOException("Failed to authenticate with proxy"); } if ("close".equalsIgnoreCase(e10.O("Connection"))) { return a10; } h0Var = a10; } } private void e(int i10) { this.f11227e.setSoTimeout(0); n5.f a10 = new f.a(true).d(this.f11227e, this.f11225c.a().l().t(), this.f11231i, this.f11232j).b(this).c(i10).a(); this.f11230h = a10; a10.I0(); } private void f(int i10, int i11, int i12, i iVar, t tVar) { h0 c10 = c(); b0 h10 = c10.h(); for (int i13 = 0; i13 < 21; i13++) { g(i10, i11, iVar, tVar); c10 = d(i11, i12, c10, h10); if (c10 == null) { return; } i5.c.k(this.f11226d); this.f11226d = null; this.f11232j = null; this.f11231i = null; tVar.e(iVar, this.f11225c.d(), this.f11225c.b(), null); } } private void g(int i10, int i11, i iVar, t tVar) { Proxy b10 = this.f11225c.b(); this.f11226d = (b10.type() == Proxy.Type.DIRECT || b10.type() == Proxy.Type.HTTP) ? this.f11225c.a().j().createSocket() : new Socket(b10); tVar.g(iVar, this.f11225c.d(), b10); this.f11226d.setSoTimeout(i11); try { o5.a.j().i(this.f11226d, this.f11225c.d(), i10); try { this.f11231i = g0.f(g0.i(this.f11226d)); this.f11232j = g0.e(g0.g(this.f11226d)); } catch (NullPointerException e10) { if ("throw with null exception".equals(e10.toString())) { throw new IOException(e10); } } } catch (ConnectException e11) { ConnectException connectException = new ConnectException("Failed to connect to " + this.f11225c.d()); connectException.initCause(e11); throw connectException; } } private void h(b bVar) { h5.a a10 = this.f11225c.a(); SSLSocket sSLSocket = null; try { try { SSLSocket sSLSocket2 = (SSLSocket) a10.k().createSocket(this.f11226d, a10.l().t(), a10.l().y(), true); try { o b10 = bVar.b(sSLSocket2); if (b10.f()) { o5.a.j().h(sSLSocket2, a10.l().t(), a10.f()); } sSLSocket2.startHandshake(); SSLSession session = sSLSocket2.getSession(); if (!j(session)) { throw new IOException("a valid ssl session was not established"); } z b11 = z.b(session); if (a10.e().verify(a10.l().t(), session)) { a10.b().d(a10.l().t(), b11.c()); String l10 = b10.f() ? o5.a.j().l(sSLSocket2) : null; this.f11227e = sSLSocket2; this.f11231i = g0.f(g0.i(sSLSocket2)); this.f11232j = g0.e(g0.g(this.f11227e)); this.f11228f = b11; this.f11229g = l10 != null ? j0.a(l10) : j0.HTTP_1_1; o5.a.j().c(sSLSocket2); return; } X509Certificate x509Certificate = (X509Certificate) b11.c().get(0); throw new SSLPeerUnverifiedException("Hostname " + a10.l().t() + " not verified:\n certificate: " + k.e(x509Certificate) + "\n DN: " + x509Certificate.getSubjectDN().getName() + "\n subjectAltNames: " + q5.d.c(x509Certificate)); } catch (AssertionError e10) { e = e10; if (!i5.c.y(e)) { throw e; } throw new IOException(e); } catch (Throwable th) { th = th; sSLSocket = sSLSocket2; if (sSLSocket != null) { o5.a.j().c(sSLSocket); } i5.c.k(sSLSocket); throw th; } } catch (AssertionError e11) { e = e11; } } catch (Throwable th2) { th = th2; } } private void i(b bVar, int i10, i iVar, t tVar) { if (this.f11225c.a().k() != null) { tVar.u(iVar); h(bVar); tVar.t(iVar, this.f11228f); if (this.f11229g == j0.HTTP_2) { e(i10); return; } return; } List f10 = this.f11225c.a().f(); j0 j0Var = j0.H2_PRIOR_KNOWLEDGE; if (!f10.contains(j0Var)) { this.f11227e = this.f11226d; this.f11229g = j0.HTTP_1_1; } else { this.f11227e = this.f11226d; this.f11229g = j0Var; e(i10); } } private boolean j(SSLSession sSLSession) { return ("NONE".equals(sSLSession.getProtocol()) || "SSL_NULL_WITH_NULL_NULL".equals(sSLSession.getCipherSuite())) ? false : true; } @Override // n5.f.b public void a(n5.f fVar) { synchronized (this.f11224b) { this.f11235m = fVar.F0(); } } @Override // n5.f.b public void b(n5.g gVar) { gVar.i(n5.b.REFUSED_STREAM); } /* JADX WARN: Removed duplicated region for block: B:32:0x00e4 */ /* JADX WARN: Removed duplicated region for block: B:43:0x00f4 A[ORIG_RETURN, RETURN] */ /* JADX WARN: Removed duplicated region for block: B:47:0x012f */ /* JADX WARN: Removed duplicated region for block: B:49:0x013a */ /* JADX WARN: Removed duplicated region for block: B:54:0x0142 A[SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:56:0x0135 */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public void k(int r17, int r18, int r19, int r20, boolean r21, h5.i r22, h5.t r23) { /* Method dump skipped, instructions count: 344 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: k5.c.k(int, int, int, int, boolean, h5.i, h5.t):void"); } public z l() { return this.f11228f; } public boolean m(h5.a aVar, m0 m0Var) { if (this.f11236n.size() >= this.f11235m || this.f11233k || !i5.a.f10869a.g(this.f11225c.a(), aVar)) { return false; } if (aVar.l().t().equals(q().a().l().t())) { return true; } if (this.f11230h == null || m0Var == null || m0Var.b().type() != Proxy.Type.DIRECT || this.f11225c.b().type() != Proxy.Type.DIRECT || !this.f11225c.d().equals(m0Var.d()) || m0Var.a().e() != q5.d.f13488a || !s(aVar.l())) { return false; } try { aVar.b().d(aVar.l().t(), l().c()); return true; } catch (SSLPeerUnverifiedException unused) { return false; } } public boolean n(boolean z10) { if (this.f11227e.isClosed() || this.f11227e.isInputShutdown() || this.f11227e.isOutputShutdown()) { return false; } if (this.f11230h != null) { return !r0.E0(); } if (z10) { try { int soTimeout = this.f11227e.getSoTimeout(); try { this.f11227e.setSoTimeout(1); return !this.f11231i.g(); } finally { this.f11227e.setSoTimeout(soTimeout); } } catch (SocketTimeoutException unused) { } catch (IOException unused2) { return false; } } return true; } public boolean o() { return this.f11230h != null; } public l5.c p(f0 f0Var, d0.a aVar, g gVar) { if (this.f11230h != null) { return new n5.e(f0Var, aVar, gVar, this.f11230h); } this.f11227e.setSoTimeout(aVar.a()); p0 b10 = this.f11231i.b(); long a10 = aVar.a(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; b10.g(a10, timeUnit); this.f11232j.b().g(aVar.b(), timeUnit); return new m5.a(f0Var, gVar, this.f11231i, this.f11232j); } public m0 q() { return this.f11225c; } public Socket r() { return this.f11227e; } public boolean s(b0 b0Var) { if (b0Var.y() != this.f11225c.a().l().y()) { return false; } if (b0Var.t().equals(this.f11225c.a().l().t())) { return true; } return this.f11228f != null && q5.d.f13488a.e(b0Var.t(), (X509Certificate) this.f11228f.c().get(0)); } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Connection{"); sb.append(this.f11225c.a().l().t()); sb.append(":"); sb.append(this.f11225c.a().l().y()); sb.append(", proxy="); sb.append(this.f11225c.b()); sb.append(" hostAddress="); sb.append(this.f11225c.d()); sb.append(" cipherSuite="); z zVar = this.f11228f; sb.append(zVar != null ? zVar.a() : "none"); sb.append(" protocol="); sb.append(this.f11229g); sb.append('}'); return sb.toString(); } }