package com.facetec.sdk; 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.Iterator; import java.util.List; import java.util.Locale; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLException; import javax.net.ssl.SSLSession; /* loaded from: classes.dex */ public final class mn implements HostnameVerifier { public static final mn d = new mn(); private mn() { } @Override // javax.net.ssl.HostnameVerifier public final boolean verify(String str, SSLSession sSLSession) { try { return a(str, (X509Certificate) sSLSession.getPeerCertificates()[0]); } catch (SSLException unused) { return false; } } public static boolean a(String str, X509Certificate x509Certificate) { if (km.b(str)) { return c(str, x509Certificate); } return d(str, x509Certificate); } private static boolean c(String str, X509Certificate x509Certificate) { List c = c(x509Certificate, 7); int size = c.size(); for (int i = 0; i < size; i++) { if (str.equalsIgnoreCase(c.get(i))) { return true; } } return false; } private static boolean d(String str, X509Certificate x509Certificate) { String lowerCase = str.toLowerCase(Locale.US); Iterator it = c(x509Certificate, 2).iterator(); while (it.hasNext()) { if (b(lowerCase, it.next())) { return true; } } return false; } public static List a(X509Certificate x509Certificate) { List c = c(x509Certificate, 7); List c2 = c(x509Certificate, 2); ArrayList arrayList = new ArrayList(c.size() + c2.size()); arrayList.addAll(c); arrayList.addAll(c2); return arrayList; } private static List c(X509Certificate x509Certificate, int i) { Integer num; String str; ArrayList arrayList = new ArrayList(); try { Collection> 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(); } } private static boolean b(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(".")) { StringBuilder sb = new StringBuilder(); sb.append(str); sb.append('.'); str = sb.toString(); } if (!str2.endsWith(".")) { StringBuilder sb2 = new StringBuilder(); sb2.append(str2); sb2.append('.'); str2 = sb2.toString(); } 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)) { return false; } int length = str.length() - substring.length(); return length <= 0 || str.lastIndexOf(46, length - 1) == -1; } return false; } }