package p447.p448.p460;

import java.security.cert.Certificate;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import kotlin.TypeCastException;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.p403.C6563;
import p402.p411.p413.C6635;
import p402.p420.C6703;
import p447.p448.C6943;

/* JADX INFO: renamed from: ސ.ޣ.ދ.ށ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C7095 implements HostnameVerifier {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static final C7095 f20616 = new C7095();

    @Override // javax.net.ssl.HostnameVerifier
    public boolean verify(String str, SSLSession sSLSession) {
        if (str == null) {
            C6635.m9824("host");
            throw null;
        }
        if (sSLSession == null) {
            C6635.m9824("session");
            throw null;
        }
        try {
            Certificate certificate = sSLSession.getPeerCertificates()[0];
            if (certificate != null) {
                return m10397(str, (X509Certificate) certificate);
            }
            throw new TypeCastException("null cannot be cast to non-null type java.security.cert.X509Certificate");
        } catch (SSLException unused) {
            return false;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final List<String> m10395(X509Certificate x509Certificate) {
        if (x509Certificate == null) {
            C6635.m9824("certificate");
            throw null;
        }
        List<String> listM10396 = m10396(x509Certificate, 7);
        List<String> listM103962 = m10396(x509Certificate, 2);
        if (listM10396 == null) {
            C6635.m9824("$this$plus");
            throw null;
        }
        if (listM103962 == null) {
            C6635.m9824("elements");
            throw null;
        }
        ArrayList arrayList = new ArrayList(listM103962.size() + listM10396.size());
        arrayList.addAll(listM10396);
        arrayList.addAll(listM103962);
        return arrayList;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final List<String> m10396(X509Certificate x509Certificate, int i) {
        Object obj;
        try {
            Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
            if (subjectAlternativeNames == null) {
                return C6563.f19343;
            }
            ArrayList arrayList = new ArrayList();
            for (List<?> list : subjectAlternativeNames) {
                if (list != null && list.size() >= 2 && !(!C6635.m9825(list.get(0), Integer.valueOf(i))) && (obj = list.get(1)) != null) {
                    arrayList.add((String) obj);
                }
            }
            return arrayList;
        } catch (CertificateParsingException unused) {
            return C6563.f19343;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:82:0x012e  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean m10397(String str, X509Certificate x509Certificate) {
        boolean zM9825;
        int length;
        if (str == null) {
            C6635.m9824("host");
            throw null;
        }
        if (x509Certificate == null) {
            C6635.m9824("certificate");
            throw null;
        }
        if (C6943.m10167(str)) {
            String strM7203 = C4303.m7203(str);
            List<String> listM10396 = m10396(x509Certificate, 7);
            if (!(listM10396 instanceof Collection) || !listM10396.isEmpty()) {
                Iterator<T> it = listM10396.iterator();
                while (it.hasNext()) {
                    if (C6635.m9825((Object) strM7203, (Object) C4303.m7203((String) it.next()))) {
                        return true;
                    }
                }
            }
        } else {
            Locale locale = Locale.US;
            C6635.m9823((Object) locale, "Locale.US");
            String lowerCase = str.toLowerCase(locale);
            C6635.m9823((Object) lowerCase, "(this as java.lang.String).toLowerCase(locale)");
            List<String> listM103962 = m10396(x509Certificate, 2);
            if (!(listM103962 instanceof Collection) || !listM103962.isEmpty()) {
                for (String strM4879 : listM103962) {
                    if ((lowerCase.length() == 0) || C6703.m9899(lowerCase, ".", false, 2) || C6703.m9885(lowerCase, "..", false, 2)) {
                        zM9825 = false;
                    } else if (!(strM4879 == null || strM4879.length() == 0) && !C6703.m9899(strM4879, ".", false, 2) && !C6703.m9885(strM4879, "..", false, 2)) {
                        String strM48792 = !C6703.m9885(lowerCase, ".", false, 2) ? C2803.m4879(lowerCase, ".") : lowerCase;
                        if (!C6703.m9885(strM4879, ".", false, 2)) {
                            strM4879 = C2803.m4879(strM4879, ".");
                        }
                        Locale locale2 = Locale.US;
                        C6635.m9823((Object) locale2, "Locale.US");
                        if (strM4879 == null) {
                            throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
                        }
                        String lowerCase2 = strM4879.toLowerCase(locale2);
                        C6635.m9823((Object) lowerCase2, "(this as java.lang.String).toLowerCase(locale)");
                        if (!C6703.m9881((CharSequence) lowerCase2, (CharSequence) "*", false, 2)) {
                            zM9825 = C6635.m9825((Object) strM48792, (Object) lowerCase2);
                        } else if (C6703.m9899(lowerCase2, "*.", false, 2) && C6703.m9856((CharSequence) lowerCase2, '*', 1, false, 4) == -1 && strM48792.length() >= lowerCase2.length() && !C6635.m9825((Object) "*.", (Object) lowerCase2)) {
                            String strSubstring = lowerCase2.substring(1);
                            C6635.m9823((Object) strSubstring, "(this as java.lang.String).substring(startIndex)");
                            if (C6703.m9885(strM48792, strSubstring, false, 2) && ((length = strM48792.length() - strSubstring.length()) <= 0 || C6703.m9886((CharSequence) strM48792, '.', length - 1, false, 4) == -1)) {
                                zM9825 = true;
                            }
                        }
                    }
                    if (zM9825) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
