package okhttp3;

import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import javax.net.ssl.SSLPeerUnverifiedException;
import kotlin.Metadata;
import kotlin.collections.EmptyList;
import kotlin.collections.j;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.k0;
import kotlin.jvm.internal.markers.KMappedMarker;
import kotlin.jvm.internal.markers.KMutableList;
import kotlin.jvm.internal.o;
import okhttp3.n0.tls.CertificateChainCleaner;
import okio.ByteString;

/* JADX INFO: renamed from: y.h, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000T\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\"\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0011\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0006\u0018\u0000 \"2\u00020\u0001:\u0003!\"#B!\b\u0000\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003\u0012\n\b\u0002\u0010\u0005\u001a\u0004\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007J)\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\u0012\u0010\u0010\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00130\u00120\u0011H\u0000¢\u0006\u0002\b\u0014J)\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\u0012\u0010\u0015\u001a\n\u0012\u0006\b\u0001\u0012\u00020\u00170\u0016\"\u00020\u0017H\u0007¢\u0006\u0002\u0010\u0018J\u001c\u0010\f\u001a\u00020\r2\u0006\u0010\u000e\u001a\u00020\u000f2\f\u0010\u0015\u001a\b\u0012\u0004\u0012\u00020\u00170\u0012J\u0013\u0010\u0019\u001a\u00020\u001a2\b\u0010\u001b\u001a\u0004\u0018\u00010\u0001H\u0096\u0002J\u0014\u0010\u001c\u001a\b\u0012\u0004\u0012\u00020\u00040\u00122\u0006\u0010\u000e\u001a\u00020\u000fJ\b\u0010\u001d\u001a\u00020\u001eH\u0016J\u0015\u0010\u001f\u001a\u00020\u00002\u0006\u0010\u0005\u001a\u00020\u0006H\u0000¢\u0006\u0002\b R\u0016\u0010\u0005\u001a\u0004\u0018\u00010\u0006X\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u0017\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\b\n\u0000\u001a\u0004\b\n\u0010\u000b¨\u0006$"}, d2 = {"Lokhttp3/CertificatePinner;", "", "pins", "", "Lokhttp3/CertificatePinner$Pin;", "certificateChainCleaner", "Lokhttp3/internal/tls/CertificateChainCleaner;", "(Ljava/util/Set;Lokhttp3/internal/tls/CertificateChainCleaner;)V", "getCertificateChainCleaner$okhttp", "()Lokhttp3/internal/tls/CertificateChainCleaner;", "getPins", "()Ljava/util/Set;", "check", "", "hostname", "", "cleanedPeerCertificatesFn", "Lkotlin/Function0;", "", "Ljava/security/cert/X509Certificate;", "check$okhttp", "peerCertificates", "", "Ljava/security/cert/Certificate;", "(Ljava/lang/String;[Ljava/security/cert/Certificate;)V", "equals", "", "other", "findMatchingPins", "hashCode", "", "withCertificateChainCleaner", "withCertificateChainCleaner$okhttp", "Builder", "Companion", "Pin", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class CertificatePinner {
    public static final a a = new a(null);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final CertificatePinner f9632b = new CertificatePinner(j.o0(new ArrayList()), null, 2);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Set<b> f9633c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final CertificateChainCleaner f9634d;

    /* JADX INFO: renamed from: y.h$a */
    @Metadata(d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\bH\u0007J\f\u0010\t\u001a\u00020\n*\u00020\u000bH\u0007J\f\u0010\f\u001a\u00020\n*\u00020\u000bH\u0007R\u0010\u0010\u0003\u001a\u00020\u00048\u0006X\u0087\u0004¢\u0006\u0002\n\u0000¨\u0006\r"}, d2 = {"Lokhttp3/CertificatePinner$Companion;", "", "()V", "DEFAULT", "Lokhttp3/CertificatePinner;", "pin", "", "certificate", "Ljava/security/cert/Certificate;", "sha1Hash", "Lokio/ByteString;", "Ljava/security/cert/X509Certificate;", "sha256Hash", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class a {
        public a(DefaultConstructorMarker defaultConstructorMarker) {
        }

        public final String a(Certificate certificate) {
            o.f(certificate, "certificate");
            if (certificate instanceof X509Certificate) {
                return o.l("sha256/", b((X509Certificate) certificate).b());
            }
            throw new IllegalArgumentException("Certificate pinning requires X509 certificates".toString());
        }

        public final ByteString b(X509Certificate x509Certificate) {
            o.f(x509Certificate, "<this>");
            ByteString.a aVar = ByteString.f10120f;
            byte[] encoded = x509Certificate.getPublicKey().getEncoded();
            o.e(encoded, "publicKey.encoded");
            return ByteString.a.c(aVar, encoded, 0, 0, 3).e("SHA-256");
        }
    }

    /* JADX INFO: renamed from: y.h$b */
    @Metadata(d1 = {"\u00002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0003¢\u0006\u0002\u0010\u0005J\u0013\u0010\u000e\u001a\u00020\u000f2\b\u0010\u0010\u001a\u0004\u0018\u00010\u0001H\u0096\u0002J\b\u0010\u0011\u001a\u00020\u0012H\u0016J\u000e\u0010\u0013\u001a\u00020\u000f2\u0006\u0010\u0014\u001a\u00020\u0015J\u000e\u0010\u0016\u001a\u00020\u000f2\u0006\u0010\u0017\u001a\u00020\u0003J\b\u0010\u0018\u001a\u00020\u0003H\u0016R\u0011\u0010\u0006\u001a\u00020\u0007¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u0011\u0010\n\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u000b\u0010\fR\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\r\u0010\f¨\u0006\u0019"}, d2 = {"Lokhttp3/CertificatePinner$Pin;", "", "pattern", "", "pin", "(Ljava/lang/String;Ljava/lang/String;)V", "hash", "Lokio/ByteString;", "getHash", "()Lokio/ByteString;", "hashAlgorithm", "getHashAlgorithm", "()Ljava/lang/String;", "getPattern", "equals", "", "other", "hashCode", "", "matchesCertificate", "certificate", "Ljava/security/cert/X509Certificate;", "matchesHostname", "hostname", "toString", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class b {
        public boolean equals(Object other) {
            if (this == other) {
                return true;
            }
            if (!(other instanceof b)) {
                return false;
            }
            b bVar = (b) other;
            Objects.requireNonNull(bVar);
            if (!o.a(null, null)) {
                return false;
            }
            Objects.requireNonNull(bVar);
            if (!o.a(null, null)) {
                return false;
            }
            Objects.requireNonNull(bVar);
            return o.a(null, null);
        }

        public int hashCode() {
            throw null;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append((String) null);
            sb.append('/');
            throw null;
        }
    }

    public CertificatePinner(Set<b> set, CertificateChainCleaner certificateChainCleaner) {
        o.f(set, "pins");
        this.f9633c = set;
        this.f9634d = certificateChainCleaner;
    }

    public CertificatePinner(Set set, CertificateChainCleaner certificateChainCleaner, int i2) {
        int i3 = i2 & 2;
        o.f(set, "pins");
        this.f9633c = set;
        this.f9634d = null;
    }

    public final void a(String str, Function0<? extends List<? extends X509Certificate>> function0) {
        o.f(str, "hostname");
        o.f(function0, "cleanedPeerCertificatesFn");
        o.f(str, "hostname");
        Set<b> set = this.f9633c;
        List<b> arrayList = EmptyList.f9307f;
        for (Object obj : set) {
            Objects.requireNonNull((b) obj);
            o.f(str, "hostname");
            if (kotlin.text.j.M(null, "**.", false, 2)) {
                throw null;
            }
            if (kotlin.text.j.M(null, "*.", false, 2)) {
                throw null;
            }
            if (o.a(str, null)) {
                if (arrayList.isEmpty()) {
                    arrayList = new ArrayList();
                }
                if ((arrayList instanceof KMappedMarker) && !(arrayList instanceof KMutableList)) {
                    k0.d(arrayList, "kotlin.collections.MutableList");
                    throw null;
                }
                arrayList.add(obj);
            }
        }
        if (arrayList.isEmpty()) {
            return;
        }
        List<? extends X509Certificate> listInvoke = function0.invoke();
        for (X509Certificate x509Certificate : listInvoke) {
            Iterator it = arrayList.iterator();
            ByteString byteStringE = null;
            ByteString byteStringE2 = null;
            while (it.hasNext()) {
                Objects.requireNonNull((b) it.next());
                if (o.a(null, "sha256")) {
                    if (byteStringE == null) {
                        o.f(x509Certificate, "<this>");
                        ByteString.a aVar = ByteString.f10120f;
                        byte[] encoded = x509Certificate.getPublicKey().getEncoded();
                        o.e(encoded, "publicKey.encoded");
                        byteStringE = ByteString.a.c(aVar, encoded, 0, 0, 3).e("SHA-256");
                    }
                    if (o.a(null, byteStringE)) {
                        return;
                    }
                } else {
                    if (!o.a(null, "sha1")) {
                        throw new AssertionError(o.l("unsupported hashAlgorithm: ", null));
                    }
                    if (byteStringE2 == null) {
                        o.f(x509Certificate, "<this>");
                        ByteString.a aVar2 = ByteString.f10120f;
                        byte[] encoded2 = x509Certificate.getPublicKey().getEncoded();
                        o.e(encoded2, "publicKey.encoded");
                        byteStringE2 = ByteString.a.c(aVar2, encoded2, 0, 0, 3).e("SHA-1");
                    }
                    if (o.a(null, byteStringE2)) {
                        return;
                    }
                }
            }
        }
        StringBuilder sbJ = g.a.a.a.a.J("Certificate pinning failure!", "\n  Peer certificate chain:");
        for (X509Certificate x509Certificate2 : listInvoke) {
            sbJ.append("\n    ");
            o.f(x509Certificate2, "certificate");
            o.f(x509Certificate2, "<this>");
            ByteString.a aVar3 = ByteString.f10120f;
            byte[] encoded3 = x509Certificate2.getPublicKey().getEncoded();
            o.e(encoded3, "publicKey.encoded");
            sbJ.append(o.l("sha256/", ByteString.a.c(aVar3, encoded3, 0, 0, 3).e("SHA-256").b()));
            sbJ.append(": ");
            sbJ.append(x509Certificate2.getSubjectDN().getName());
        }
        sbJ.append("\n  Pinned certificates for ");
        sbJ.append(str);
        sbJ.append(":");
        for (b bVar : arrayList) {
            sbJ.append("\n    ");
            sbJ.append(bVar);
        }
        String string = sbJ.toString();
        o.e(string, "StringBuilder().apply(builderAction).toString()");
        throw new SSLPeerUnverifiedException(string);
    }

    public final CertificatePinner b(CertificateChainCleaner certificateChainCleaner) {
        o.f(certificateChainCleaner, "certificateChainCleaner");
        return o.a(this.f9634d, certificateChainCleaner) ? this : new CertificatePinner(this.f9633c, certificateChainCleaner);
    }

    public boolean equals(Object other) {
        if (other instanceof CertificatePinner) {
            CertificatePinner certificatePinner = (CertificatePinner) other;
            if (o.a(certificatePinner.f9633c, this.f9633c) && o.a(certificatePinner.f9634d, this.f9634d)) {
                return true;
            }
        }
        return false;
    }

    public int hashCode() {
        int iHashCode = (this.f9633c.hashCode() + 1517) * 41;
        CertificateChainCleaner certificateChainCleaner = this.f9634d;
        return iHashCode + (certificateChainCleaner != null ? certificateChainCleaner.hashCode() : 0);
    }
}
