package p447.p448.p460;

import java.security.GeneralSecurityException;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SSLPeerUnverifiedException;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;

/* JADX INFO: renamed from: ސ.ޣ.ދ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7090 extends AbstractC7093 {

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final InterfaceC7096 f20613;

    /* JADX INFO: renamed from: ސ.ޣ.ދ.֏$֏, reason: contains not printable characters */
    public static final class C7091 {
        public C7091() {
        }

        public /* synthetic */ C7091(DefaultConstructorMarker defaultConstructorMarker) {
        }
    }

    static {
        new C7091(null);
    }

    public C7090(InterfaceC7096 interfaceC7096) {
        if (interfaceC7096 != null) {
            this.f20613 = interfaceC7096;
        } else {
            C6635.m9824("trustRootIndex");
            throw null;
        }
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        return (obj instanceof C7090) && C6635.m9825(((C7090) obj).f20613, this.f20613);
    }

    public int hashCode() {
        return this.f20613.hashCode();
    }

    @Override // p447.p448.p460.AbstractC7093
    /* JADX INFO: renamed from: ֏ */
    public List<Certificate> mo10390(List<? extends Certificate> list, String str) throws SSLPeerUnverifiedException {
        if (list == null) {
            C6635.m9824("chain");
            throw null;
        }
        if (str == null) {
            C6635.m9824("hostname");
            throw null;
        }
        ArrayDeque arrayDeque = new ArrayDeque(list);
        ArrayList arrayList = new ArrayList();
        Object objRemoveFirst = arrayDeque.removeFirst();
        C6635.m9823(objRemoveFirst, "queue.removeFirst()");
        arrayList.add(objRemoveFirst);
        boolean z = false;
        for (int i = 0; i < 9; i++) {
            Object obj = arrayList.get(arrayList.size() - 1);
            if (obj == null) {
                throw new TypeCastException("null cannot be cast to non-null type java.security.cert.X509Certificate");
            }
            X509Certificate x509Certificate = (X509Certificate) obj;
            X509Certificate x509CertificateMo10374 = this.f20613.mo10374(x509Certificate);
            if (x509CertificateMo10374 == null) {
                Iterator it = arrayDeque.iterator();
                C6635.m9823((Object) it, "queue.iterator()");
                while (it.hasNext()) {
                    Object next = it.next();
                    if (next == null) {
                        throw new TypeCastException("null cannot be cast to non-null type java.security.cert.X509Certificate");
                    }
                    X509Certificate x509Certificate2 = (X509Certificate) next;
                    if (m10393(x509Certificate, x509Certificate2)) {
                        it.remove();
                        arrayList.add(x509Certificate2);
                    }
                }
                if (z) {
                    return arrayList;
                }
                throw new SSLPeerUnverifiedException("Failed to find a trusted cert that signed " + x509Certificate);
            }
            if (arrayList.size() > 1 || (!C6635.m9825(x509Certificate, x509CertificateMo10374))) {
                arrayList.add(x509CertificateMo10374);
            }
            if (m10393(x509CertificateMo10374, x509CertificateMo10374)) {
                return arrayList;
            }
            z = true;
        }
        throw new SSLPeerUnverifiedException("Certificate chain too long: " + arrayList);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m10393(X509Certificate x509Certificate, X509Certificate x509Certificate2) {
        if (!C6635.m9825(x509Certificate.getIssuerDN(), x509Certificate2.getSubjectDN())) {
            return false;
        }
        try {
            x509Certificate.verify(x509Certificate2.getPublicKey());
            return true;
        } catch (GeneralSecurityException unused) {
            return false;
        }
    }
}
