package dr;

import android.security.NetworkSecurityPolicy;
import er.i;
import er.j;
import er.k;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.X509TrustManager;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import sm.u;

/* loaded from: classes3.dex */
public final class b extends h {

    /* renamed from: e, reason: collision with root package name */
    public static final a f16571e = new a(null);

    /* renamed from: f, reason: collision with root package name */
    private static final boolean f16572f;

    /* renamed from: d, reason: collision with root package name */
    private final List f16573d;

    /* loaded from: classes3.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(k kVar) {
            this();
        }

        public final h a() {
            if (b()) {
                return new b();
            }
            return null;
        }

        public final boolean b() {
            return b.f16572f;
        }
    }

    /* renamed from: dr.b$b, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public static final class C0359b implements hr.e {

        /* renamed from: a, reason: collision with root package name */
        private final X509TrustManager f16574a;

        /* renamed from: b, reason: collision with root package name */
        private final Method f16575b;

        public C0359b(X509TrustManager trustManager, Method findByIssuerAndSignatureMethod) {
            t.g(trustManager, "trustManager");
            t.g(findByIssuerAndSignatureMethod, "findByIssuerAndSignatureMethod");
            this.f16574a = trustManager;
            this.f16575b = findByIssuerAndSignatureMethod;
        }

        @Override // hr.e
        public X509Certificate a(X509Certificate cert) {
            t.g(cert, "cert");
            try {
                Object invoke = this.f16575b.invoke(this.f16574a, cert);
                t.e(invoke, "null cannot be cast to non-null type java.security.cert.TrustAnchor");
                return ((TrustAnchor) invoke).getTrustedCert();
            } catch (IllegalAccessException e10) {
                throw new AssertionError("unable to get issues and signature", e10);
            } catch (InvocationTargetException unused) {
                return null;
            }
        }

        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (!(obj instanceof C0359b)) {
                return false;
            }
            C0359b c0359b = (C0359b) obj;
            return t.b(this.f16574a, c0359b.f16574a) && t.b(this.f16575b, c0359b.f16575b);
        }

        public int hashCode() {
            return (this.f16574a.hashCode() * 31) + this.f16575b.hashCode();
        }

        public String toString() {
            return "CustomTrustRootIndex(trustManager=" + this.f16574a + ", findByIssuerAndSignatureMethod=" + this.f16575b + ')';
        }
    }

    static {
        h.f16598a.h();
        f16572f = false;
    }

    public b() {
        List p10;
        p10 = u.p(k.a.b(er.k.f17304j, null, 1, null), new i(er.f.f17290f.d()), new i(er.h.f17300a.a()), new i(er.g.f17298a.a()));
        ArrayList arrayList = new ArrayList();
        for (Object obj : p10) {
            if (((j) obj).b()) {
                arrayList.add(obj);
            }
        }
        this.f16573d = arrayList;
    }

    @Override // dr.h
    public hr.c c(X509TrustManager trustManager) {
        t.g(trustManager, "trustManager");
        er.b a10 = er.b.f17283d.a(trustManager);
        return a10 != null ? a10 : super.c(trustManager);
    }

    @Override // dr.h
    public hr.e d(X509TrustManager trustManager) {
        t.g(trustManager, "trustManager");
        try {
            Method method = trustManager.getClass().getDeclaredMethod("findTrustAnchorByIssuerAndSignature", X509Certificate.class);
            method.setAccessible(true);
            t.f(method, "method");
            return new C0359b(trustManager, method);
        } catch (NoSuchMethodException unused) {
            return super.d(trustManager);
        }
    }

    @Override // dr.h
    public void e(SSLSocket sslSocket, String str, List protocols) {
        Object obj;
        t.g(sslSocket, "sslSocket");
        t.g(protocols, "protocols");
        Iterator it = this.f16573d.iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            } else {
                obj = it.next();
                if (((j) obj).a(sslSocket)) {
                    break;
                }
            }
        }
        j jVar = (j) obj;
        if (jVar != null) {
            jVar.d(sslSocket, str, protocols);
        }
    }

    @Override // dr.h
    public void f(Socket socket, InetSocketAddress address, int i10) {
        t.g(socket, "socket");
        t.g(address, "address");
        socket.connect(address, i10);
    }

    @Override // dr.h
    public String g(SSLSocket sslSocket) {
        Object obj;
        t.g(sslSocket, "sslSocket");
        Iterator it = this.f16573d.iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            }
            obj = it.next();
            if (((j) obj).a(sslSocket)) {
                break;
            }
        }
        j jVar = (j) obj;
        if (jVar != null) {
            return jVar.c(sslSocket);
        }
        return null;
    }

    @Override // dr.h
    public boolean i(String hostname) {
        t.g(hostname, "hostname");
        return NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(hostname);
    }
}
