package 㿎.ሽ.㳳;

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;

/* renamed from: 㿎.ሽ.㳳.K  reason: contains not printable characters */
/* compiled from: BasicCertificateChainCleaner */
public final class C2574 extends AbstractC2571 {

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC2572 f8678;

    public C2574(AbstractC2572 r1) {
        this.f8678 = r1;
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof C2574) || !((C2574) obj).f8678.equals(this.f8678)) {
            return false;
        }
        return true;
    }

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

    @Override // 㿎.ሽ.㳳.AbstractC2571
    /* renamed from: K  reason: contains not printable characters */
    public List<Certificate> m6769(List<Certificate> list, String str) throws SSLPeerUnverifiedException {
        ArrayDeque arrayDeque = new ArrayDeque(list);
        ArrayList arrayList = new ArrayList();
        arrayList.add(arrayDeque.removeFirst());
        boolean z = false;
        for (int i = 0; i < 9; i++) {
            X509Certificate x509Certificate = (X509Certificate) arrayList.get(arrayList.size() - 1);
            X509Certificate r4 = this.f8678.m6767(x509Certificate);
            if (r4 != null) {
                if (arrayList.size() > 1 || !x509Certificate.equals(r4)) {
                    arrayList.add(r4);
                }
                if (m6770(r4, r4)) {
                    return arrayList;
                }
                z = true;
            } else {
                Iterator it2 = arrayDeque.iterator();
                while (it2.hasNext()) {
                    X509Certificate x509Certificate2 = (X509Certificate) it2.next();
                    if (m6770(x509Certificate, x509Certificate2)) {
                        it2.remove();
                        arrayList.add(x509Certificate2);
                    }
                }
                if (z) {
                    return arrayList;
                }
                throw new SSLPeerUnverifiedException("Failed to find a trusted cert that signed " + x509Certificate);
            }
        }
        throw new SSLPeerUnverifiedException("Certificate chain too long: " + arrayList);
    }

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