package XnFJ5_9.Ft6VRog_36.WwEq_13;

import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
/* compiled from: OkHostnameVerifier.java */
/* loaded from: classes.dex */
public final class Mqv2r_3 implements HostnameVerifier {
    public static final Mqv2r_3 KQgRr5e_0 = new Mqv2r_3();

    public boolean KQgRr5e_0(String str, X509Certificate x509Certificate) {
        if (XnFJ5_9.Ft6VRog_36.X6FRs_4.QxJ9d_1(str)) {
            return PGPF6hQ_2(str, x509Certificate);
        }
        return QxJ9d_1(str, x509Certificate);
    }

    public final boolean PGPF6hQ_2(String str, X509Certificate x509Certificate) {
        List<String> KQgRr5e_02 = KQgRr5e_0(x509Certificate, 7);
        int size = KQgRr5e_02.size();
        for (int i = 0; i < size; i++) {
            if (str.equalsIgnoreCase(KQgRr5e_02.get(i))) {
                return true;
            }
        }
        return false;
    }

    public final boolean QxJ9d_1(String str, X509Certificate x509Certificate) {
        String lowerCase = str.toLowerCase(Locale.US);
        for (String str2 : KQgRr5e_0(x509Certificate, 2)) {
            if (KQgRr5e_0(lowerCase, str2)) {
                return true;
            }
        }
        return false;
    }

    @Override // javax.net.ssl.HostnameVerifier
    public boolean verify(String str, SSLSession sSLSession) {
        try {
            return KQgRr5e_0(str, (X509Certificate) sSLSession.getPeerCertificates()[0]);
        } catch (SSLException unused) {
            return false;
        }
    }

    public static List<String> KQgRr5e_0(X509Certificate x509Certificate) {
        List<String> KQgRr5e_02 = KQgRr5e_0(x509Certificate, 7);
        List<String> KQgRr5e_03 = KQgRr5e_0(x509Certificate, 2);
        ArrayList arrayList = new ArrayList(KQgRr5e_02.size() + KQgRr5e_03.size());
        arrayList.addAll(KQgRr5e_02);
        arrayList.addAll(KQgRr5e_03);
        return arrayList;
    }

    public static List<String> KQgRr5e_0(X509Certificate x509Certificate, int i) {
        Integer num;
        String str;
        ArrayList arrayList = new ArrayList();
        try {
            Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
            if (subjectAlternativeNames == null) {
                return Collections.emptyList();
            }
            for (List<?> list : subjectAlternativeNames) {
                if (list != null && list.size() >= 2 && (num = (Integer) list.get(0)) != null && num.intValue() == i && (str = (String) list.get(1)) != null) {
                    arrayList.add(str);
                }
            }
            return arrayList;
        } catch (CertificateParsingException unused) {
            return Collections.emptyList();
        }
    }

    public boolean KQgRr5e_0(String str, String str2) {
        if (str != null && str.length() != 0 && !str.startsWith(".") && !str.endsWith("..") && str2 != null && str2.length() != 0 && !str2.startsWith(".") && !str2.endsWith("..")) {
            if (!str.endsWith(".")) {
                str = str + '.';
            }
            if (!str2.endsWith(".")) {
                str2 = str2 + '.';
            }
            String lowerCase = str2.toLowerCase(Locale.US);
            if (!lowerCase.contains("*")) {
                return str.equals(lowerCase);
            }
            if (!lowerCase.startsWith("*.") || lowerCase.indexOf(42, 1) != -1 || str.length() < lowerCase.length() || "*.".equals(lowerCase)) {
                return false;
            }
            String substring = lowerCase.substring(1);
            if (str.endsWith(substring)) {
                int length = str.length() - substring.length();
                return length <= 0 || str.lastIndexOf(46, length - 1) == -1;
            }
            return false;
        }
        return false;
    }
}
