what-the-bank/sources/o/AbstractC15238gky.java

186 lines
6.6 KiB
Java

package o;
import com.google.common.net.HttpHeaders;
import java.io.IOException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import org.apache.http.conn.ssl.X509HostnameVerifier;
@Deprecated
/* renamed from: o.gky, reason: case insensitive filesystem */
/* loaded from: classes6.dex */
public abstract class AbstractC15238gky implements X509HostnameVerifier {
private static String[] b;
private final InterfaceC15219gkf c = AbstractC15217gkd.b(getClass());
static {
String[] strArr = {"ac", "co", "com", "ed", "edu", "go", "gouv", "gov", "info", "lg", "ne", "net", "or", "org"};
b = strArr;
Arrays.sort(strArr);
}
@Override // org.apache.http.conn.ssl.X509HostnameVerifier
public final void verify(String str, SSLSocket sSLSocket) throws IOException {
C15267glv.b(str, HttpHeaders.HOST);
SSLSession session = sSLSocket.getSession();
if (session == null) {
sSLSocket.getInputStream().available();
session = sSLSocket.getSession();
if (session == null) {
sSLSocket.startHandshake();
session = sSLSocket.getSession();
}
}
verify(str, (X509Certificate) session.getPeerCertificates()[0]);
}
@Override // javax.net.ssl.HostnameVerifier
public final boolean verify(String str, SSLSession sSLSession) {
try {
verify(str, (X509Certificate) sSLSession.getPeerCertificates()[0]);
return true;
} catch (SSLException e) {
if (this.c.e()) {
this.c.d(e.getMessage(), e);
}
return false;
}
}
@Override // org.apache.http.conn.ssl.X509HostnameVerifier
public final void verify(String str, X509Certificate x509Certificate) throws SSLException {
List<gkI> e = gkF.e(x509Certificate);
ArrayList arrayList = new ArrayList();
if (gkJ.b(str) || gkJ.e(str)) {
for (gkI gki : e) {
if (gki.b == 7) {
arrayList.add(gki.c);
}
}
} else {
for (gkI gki2 : e) {
if (gki2.b == 2) {
arrayList.add(gki2.c);
}
}
}
String b2 = gkF.b(x509Certificate.getSubjectX500Principal().getName("RFC2253"));
verify(str, b2 != null ? new String[]{b2} : null, arrayList.isEmpty() ? null : (String[]) arrayList.toArray(new String[arrayList.size()]));
}
public final void verify(String str, String[] strArr, String[] strArr2, boolean z) throws SSLException {
List<String> list = null;
String str2 = (strArr == null || strArr.length <= 0) ? null : strArr[0];
if (strArr2 != null && strArr2.length > 0) {
list = Arrays.asList(strArr2);
}
String d = gkJ.e(str) ? gkF.d(str.toLowerCase(Locale.ROOT)) : str;
if (list != null) {
for (String str3 : list) {
if (gkJ.e(str3)) {
str3 = gkF.d(str3);
}
if (c(d, str3, z)) {
return;
}
}
StringBuilder sb = new StringBuilder("Certificate for <");
sb.append(str);
sb.append("> doesn't match any of the subject alternative names: ");
sb.append(list);
throw new SSLException(sb.toString());
}
if (str2 != null) {
if (c(d, gkJ.e(str2) ? gkF.d(str2) : str2, z)) {
return;
}
StringBuilder sb2 = new StringBuilder("Certificate for <");
sb2.append(str);
sb2.append("> doesn't match common name of the certificate subject: ");
sb2.append(str2);
throw new SSLException(sb2.toString());
}
StringBuilder sb3 = new StringBuilder("Certificate subject for <");
sb3.append(str);
sb3.append("> doesn't contain a common name and does not have alternative names");
throw new SSLException(sb3.toString());
}
private static boolean c(String str, String str2, boolean z) {
if (str == null) {
return false;
}
String lowerCase = str.toLowerCase(Locale.ROOT);
String lowerCase2 = str2.toLowerCase(Locale.ROOT);
String[] split = lowerCase2.split("\\.");
if (split.length >= 3 && split[0].endsWith("*") && (!z || e(split))) {
String str3 = split[0];
if (str3.length() > 1) {
String substring = str3.substring(0, str3.length() - 1);
String substring2 = lowerCase2.substring(str3.length());
String substring3 = lowerCase.substring(substring.length());
if (!lowerCase.startsWith(substring) || !substring3.endsWith(substring2)) {
return false;
}
} else if (!lowerCase.endsWith(lowerCase2.substring(1))) {
return false;
}
return !z || countDots(lowerCase) == countDots(lowerCase2);
}
return lowerCase.equals(lowerCase2);
}
private static boolean e(String[] strArr) {
return (strArr.length == 3 && strArr[2].length() == 2 && Arrays.binarySearch(b, strArr[1]) >= 0) ? false : true;
}
public static boolean acceptableCountryWildcard(String str) {
return e(str.split("\\."));
}
public static String[] getCNs(X509Certificate x509Certificate) {
try {
String b2 = gkF.b(x509Certificate.getSubjectX500Principal().toString());
if (b2 != null) {
return new String[]{b2};
}
return null;
} catch (SSLException unused) {
return null;
}
}
public static String[] getDNSSubjectAlts(X509Certificate x509Certificate) {
List<gkI> e = gkF.e(x509Certificate);
if (e == null) {
return null;
}
ArrayList arrayList = new ArrayList();
for (gkI gki : e) {
if (gki.b == 2) {
arrayList.add(gki.c);
}
}
if (arrayList.isEmpty()) {
return (String[]) arrayList.toArray(new String[arrayList.size()]);
}
return null;
}
public static int countDots(String str) {
int i = 0;
for (int i2 = 0; i2 < str.length(); i2++) {
if (str.charAt(i2) == '.') {
i++;
}
}
return i;
}
}