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

222 lines
8.1 KiB
Java

package o;
import java.net.InetAddress;
import java.net.UnknownHostException;
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 java.util.NoSuchElementException;
import javax.naming.InvalidNameException;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
/* loaded from: classes6.dex */
public final class gkF implements HostnameVerifier {
private final gkN b;
private final InterfaceC15219gkf c;
/* loaded from: classes6.dex */
enum HBt {
IPv4(7),
IPv6(7),
DNS(2);
final int subjectType;
HBt(int i) {
this.subjectType = i;
}
}
private gkF(byte b) {
this.c = AbstractC15217gkd.b(getClass());
this.b = null;
}
public gkF() {
this((byte) 0);
}
@Override // javax.net.ssl.HostnameVerifier
public final boolean verify(String str, SSLSession sSLSession) {
HBt hBt;
try {
X509Certificate x509Certificate = (X509Certificate) sSLSession.getPeerCertificates()[0];
if (gkJ.b(str)) {
hBt = HBt.IPv4;
} else if (gkJ.e((str.startsWith("[") && str.endsWith("]")) ? str.substring(1, str.length() - 1) : str)) {
hBt = HBt.IPv6;
} else {
hBt = HBt.DNS;
}
List<gkI> e = e(x509Certificate);
if (e != null && !e.isEmpty()) {
int i = AnonymousClass1.e[hBt.ordinal()];
if (i == 1) {
for (int i2 = 0; i2 < e.size(); i2++) {
gkI gki = e.get(i2);
if (gki.b != 7 || !str.equals(gki.c)) {
}
}
StringBuilder sb = new StringBuilder("Certificate for <");
sb.append(str);
sb.append("> doesn't match any of the subject alternative names: ");
sb.append(e);
throw new SSLPeerUnverifiedException(sb.toString());
}
if (i != 2) {
String lowerCase = str.toLowerCase(Locale.ROOT);
for (int i3 = 0; i3 < e.size(); i3++) {
gkI gki2 = e.get(i3);
if (gki2.b != 2 || !b(lowerCase, gki2.c.toLowerCase(Locale.ROOT), null)) {
}
}
StringBuilder sb2 = new StringBuilder("Certificate for <");
sb2.append(str);
sb2.append("> doesn't match any of the subject alternative names: ");
sb2.append(e);
throw new SSLPeerUnverifiedException(sb2.toString());
}
String d = d(str);
for (int i4 = 0; i4 < e.size(); i4++) {
gkI gki3 = e.get(i4);
if (gki3.b != 7 || !d.equals(d(gki3.c))) {
}
}
StringBuilder sb3 = new StringBuilder("Certificate for <");
sb3.append(str);
sb3.append("> doesn't match any of the subject alternative names: ");
sb3.append(e);
throw new SSLPeerUnverifiedException(sb3.toString());
}
String b = b(x509Certificate.getSubjectX500Principal().getName("RFC2253"));
if (b == null) {
StringBuilder sb4 = new StringBuilder("Certificate subject for <");
sb4.append(str);
sb4.append("> doesn't contain a common name and does not have alternative names");
throw new SSLException(sb4.toString());
}
if (!b(str.toLowerCase(Locale.ROOT), b.toLowerCase(Locale.ROOT), null)) {
StringBuilder sb5 = new StringBuilder("Certificate for <");
sb5.append(str);
sb5.append("> doesn't match common name of the certificate subject: ");
sb5.append(b);
throw new SSLPeerUnverifiedException(sb5.toString());
}
return true;
} catch (SSLException e2) {
if (this.c.e()) {
this.c.d(e2.getMessage(), e2);
}
return false;
}
}
/* renamed from: o.gkF$1, reason: invalid class name */
/* loaded from: classes6.dex */
static /* synthetic */ class AnonymousClass1 {
static final int[] e;
static {
int[] iArr = new int[HBt.values().length];
e = iArr;
try {
iArr[HBt.IPv4.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
e[HBt.IPv6.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
private static boolean b(String str, String str2, gkN gkn) {
int indexOf = str2.indexOf(42);
if (indexOf != -1) {
String substring = str2.substring(0, indexOf);
String substring2 = str2.substring(indexOf + 1);
if (substring.isEmpty() || str.startsWith(substring)) {
return (substring2.isEmpty() || str.endsWith(substring2)) && !str.substring(substring.length(), str.length() - substring2.length()).contains(".");
}
return false;
}
return str.equalsIgnoreCase(str2);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String b(String str) throws SSLException {
if (str == null) {
return null;
}
try {
List rdns = new LdapName(str).getRdns();
for (int size = rdns.size() - 1; size >= 0; size--) {
Attribute attribute = ((Rdn) rdns.get(size)).toAttributes().get("cn");
if (attribute != null) {
try {
Object obj = attribute.get();
if (obj != null) {
return obj.toString();
}
continue;
} catch (NoSuchElementException | NamingException unused) {
continue;
}
}
}
return null;
} catch (InvalidNameException unused2) {
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.append(" is not a valid X500 distinguished name");
throw new SSLException(sb.toString());
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static List<gkI> e(X509Certificate x509Certificate) {
try {
Collection<List<?>> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames();
if (subjectAlternativeNames == null) {
return Collections.emptyList();
}
ArrayList arrayList = new ArrayList();
for (List<?> list : subjectAlternativeNames) {
Integer num = list.size() >= 2 ? (Integer) list.get(0) : null;
if (num != null && (num.intValue() == 2 || num.intValue() == 7)) {
Object obj = list.get(1);
if (obj instanceof String) {
arrayList.add(new gkI((String) obj, num.intValue()));
}
}
}
return arrayList;
} catch (CertificateParsingException unused) {
return Collections.emptyList();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static String d(String str) {
if (str == null) {
return str;
}
try {
return InetAddress.getByName(str).getHostAddress();
} catch (UnknownHostException unused) {
return str;
}
}
}